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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


void solve(int N,int Q,vi& s,vi& t,vi& x,vi& d) {
    map<int, vector<ii>> events;
    rep(i,N){
        events[s[i] - x[i]].emplace_back(1, x[i]);
        events[t[i] - x[i]].emplace_back(-1, x[i]);
    }

    rep(i,Q) {
        events[d[i]].emplace_back(INT_MAX, i);
    }

    map<int,int> st;
    vi ans(Q, -1);

    for (auto& ev: events){
        sort(ALL(ev.second));
        for (auto& p: ev.second){
            switch (p.first) {
                case -1:
                    if (--st[p.second] == 0) st.erase(p.second);
                    break;
                case 1:
                    ++st[p.second];
                    break;
                default:
                    if (!st.empty()) {
                        ans[p.second] = st.begin()->first;
                    }
                    break;
            }
        }
    }
    rep(i,Q){
        printf("%d\n", ans[i]);
    }
}

int main() {
    int N, Q; scanf("%d %d%*c", &N, &Q);
    vi s(N),t(N),x(N);
    rep(i,N) {
        scanf("%d %d %d%*c", &s[i], &t[i], &x[i]);
    }
    vi d(Q);
    rep(i,Q) {
        scanf("%d%*c", &d[i]);
    }
    solve(N,Q,s,t,x,d);
    return 0;
}


Measured memory_bytes: 80128
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}
// 立っている ビットの数
int bitcount(unsigned int uc);
int bitcount(unsigned int uc)
{
	int bit;

	for (bit = 0; 0 != uc; uc = (unsigned int)(uc >> 1))
		if (0 != (uc & 1))++bit;

	return bit;
}//bitco

#define _rnd(a,b)    ((a+b-1)/b) //　A/Bの余りを繰り上げる

#pragma endregion

// ABC088 A-Round Up the Mean
int main(void) {
	int a,b;
	
	scanf("%d %d", &a,&b);
	printf("%d\n", _rnd((a + b),2));

	return 0;
}

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

int main(){
  string s;
  cin >> s;
  
  sort(s.begin(), s.end());
  if(s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3))
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
	long long x,d,k;
	cin >> x >> d >> k;
	long long mins=abs(x);
	long long a;
	if(d%2){
		if(mins>=k){
			mins-=k;
			d--;
			if(2*(mins/(2*k))<=d){
				a=2*(mins/(2*k));
				mins-=a*k;
				d-=a;
				if(d>=2){
					mins=min(abs(mins-2*k),mins);
				}
			}else{
				mins-=k*d;
			}
		}else{
			mins=abs(mins-k);
		}
	}else{
		if(2*(mins/(2*k))<=d){
			a=2*(mins/(2*k));
			mins-=a*k;
			d-=a;
			if(d>=2){
				mins=min(abs(mins-2*k),mins);
			}
		}else{
			mins-=k*d;
		}
	}
	cout << mins << endl;
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
template<typename T> bool chmax(T &a, T b) {if(a <= b){a = b; return true;}return false;}
template<typename T> bool chmin(T &a, T b) {if(a >= b){a = b; return true;}return false;}

int main(void){
    int n; ll k;
    cin >> n >> k;
    int a[60][n];
    rep(i, n){
        cin >> a[0][i];
        a[0][i]--;
    }
    for(int i = 1; i < 60; i++){
        for(int j = 0; j < n; j++){
            a[i][j] = a[i-1][a[i-1][j]];
        }
    }
    int now = 0;
    for(int i = 59; 0 <= i; i--){
        ll l = (1ll << i);
        if(l <= k){
            now = a[i][now];
            k -= l;
        }
    }
    cout << now + 1 << endl;
}

Measured memory_bytes: 50552
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
print(((n - m) * 100 + 1900 * m) * 2 ** m)

Measured memory_bytes: 39408
#include <iostream>

#define endl '\n'
#define pb push_back
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

void solve()
{
    int a, b;

    cin >> a >> b;

    int pal = 0;

    for(int i = a; i <= b; i++)
    {
        string s;
        int temp = i, sz = 0;
        while(temp != 0)
        {
            s.pb(temp%10 + 48);
            temp /= 10;
            ++sz;
        }
        int half = sz/2;
        bool palindrome = true;
        for(int j = 0; j < half; j++)
        {
            if(s[j] != s[sz-j-1])
            {
                palindrome = false;
                break;
            }
        }
        if(palindrome)
            pal++;
    }

    cout << pal;


}

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

//    int t; cin >> t; while(t--){
        solve();
//    }
    return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  string s;
  REP(i,h) {
    cin >> s;
    cout << s << endl << s << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int x = sc.nextInt();
		int y = sc.nextInt();
		String ans = "";

		if ( (x == 4 ||x == 6 ||x == 9 ||x == 11) && (y == 4 ||y == 6 ||y == 9 ||y == 11 )) {
			ans = "Yes";
		} else if ((x == 1 ||x == 3 ||x == 5 ||x == 7||x == 8||x == 10||x == 12) && (y == 1 ||y == 3 ||y == 5 ||y == 7||y == 8||y == 10||y == 12)) {
			ans = "Yes";
		} else {
			ans = "No";
		}

		System.out.println( ans );
	}
}

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

int main(void){
    int N; cin >> N;
    vector<int> A;
    A.push_back(0);
    for(int i=0; i<N; i++){
        int a; cin >> a;
        A.push_back(a);
    }
    A.push_back(0);

    int totalCost=0;
    for(int i=0; i<N+2; i++) totalCost+=abs(A[i+1]-A[i]);

    for(int i=1; i<=N; i++){ //i番目は通らない
        printf("%d\n", totalCost-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]));
    }
} 

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

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

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

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

  int ans = inf;
  rep(i, 1, n/i+1){
    if(n%i) continue;
    int j = n/i;
    chmin(ans, (i-1)+(j-1));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, typename T, T M>
struct ModFact {
    T inv[N+1];
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i = 0; i < N; i++)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i = N-1; i >= 0; i--)
            ifact[i] = (ifact[i+1]*(i+1))%M;
        inv[0] = 0;
        for (int i = 0; i < N; i++)
            inv[i+1] = (fact[i]*ifact[i+1])%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};
 
ModFact<100000, ll, MOD> fact;

ll N;
ll X[100001];

int main() {
    fastio();
    ll N, ans = 0;
    cin >> N;
    REP(i, N) cin >> X[i];
    ll a = 0;
    REP(i, N-1) {
        a = (a + fact.inv[i+1]) % MOD;
        ans = (ans + a * (X[i+1] - X[i])) % MOD;
    }
    cout << (ans * fact.fact[N-1])%MOD << "\n";
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std ;
using ll = long long ;
int main ()
{
ll n, a, b;
cin >> n >> a >> b;
    ll x = n / (a + b);
    ll y = n % (a + b);
    if(a<=y) {cout << x * a + a << endl;}
   else  cout << x * a + y << endl;

    return 0 ;
}



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

using namespace std;

#define ll long long
#define mp make_pair
#define f first
#define s second
#define pb push_back

int main()
{
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);

    int n,i;

    cin>>n;
    int ans = 0;
    for(i=1; i<=n; ++i)
    {
        int x = i;
        int cnt = 0;
        while(x)
        {
            x/=10;
            cnt++;
        }
        if(cnt&1)
            ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 256
N = int(input())

n = N // 2
S = N + (N % 2 == 0)

groups = [[i, S - i] for i in range(1, n + 1)]

if N % 2 == 1:
    groups.append([S])

ans = []

from itertools import *

for g1, g2 in combinations(groups, 2):
    for s, t in product(g1, g2):
        ans.append((s, t))

print(len(ans))
for s, t in ans:
    print(s, t)


Measured memory_bytes: 4004
N = int(input())
S = input()
west = S.count('W')
east = N - west 
Q = [0,0,west,east] #[自分より西で西向き、東向き、自分より東で西向き、東向き]
ans = N-1
for i in range(N):
    if S[i]=='W':
        Q[2]-=1
        cnt = Q[0]+Q[3]
        Q[0]+=1
    else:
        Q[3]-=1
        cnt = Q[0]+Q[3]
        Q[1]+=1
    ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 9688
#include <stdio.h>
#include <memory.h>
int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}
int max(int a,int b){
  return a>b?a:b;
}
int main(void){
  int n,m,t[20001],i,ans;
  while(1){
    memset(t,0,sizeof(t));
    scanf("%d %d,",&n,&m);
    if(n+m==0)
      break;
    for(i=1;i<=n+m;i++)
      scanf("%d",&t[i]);
    qsort(t,n+m,sizeof(int),cmp);
    ans=0;
    for(i=1;i<=n+m;i++){
      if(t[i]-t[i-1]>ans)
	ans=t[i]-t[i-1];
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 804
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

const int tam = 100000 + 10;

int BIT[2010][2010];

void update(int y, int x, int val) {
	y++; x++;
	int orX = x;
	for (; y < 2010; y += (y & -y)) {
		for (x = orX; x < 2010; x += (x & -x)) {
			BIT[y][x] += val;
		}
	}
}

int query(int y, int x) {
	y++; x++;
	int res = 0;
	for (int i = y; i > 0; i -= (i & -i)) {
		for (int j = x; j > 0; j -= (j & -j)) {
			res += BIT[i][j];
		}
	}
	return res;
}


int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int n, k;
    cin >> n >> k;
    int X[n], Y[n];
    char C[n];
    int ans = 0;
    int res = 0;
    fore(i,0,n) {
    	cin >> X[i] >> Y[i] >> C[i];
		int dy = k - Y[i]%k;
		int dx = k - X[i]%k;
    	if ( (X[i]/k + Y[i]/k) % 2 == 0 ) {
    		if (C[i] == 'B') {
    			res++;
    			update( dy, 0, -1 );
    			update( 0, dx, -1 );
    			update( dy, dx, 2 );

    			update( 0, dx + k, 1 );
    			update( dy, dx + k, -2 );

    			update( dy+k, 0, 1 );
    			update( dy+k, dx, -2 );

    			update( dy+k, dx+k, 2 );
    		}
    		else {
    			update( dy, 0, 1 );
    			update( 0, dx, 1 );
    			update( dy, dx, -2 );

    			update( 0, dx + k, -1 );
    			update( dy, dx + k, 2 );

    			update( dy+k, 0, -1 );
    			update( dy+k, dx, 2 );

    			update( dy+k, dx+k, -2 );
    		}
    	}
    	if ( (X[i]/k + Y[i]/k) % 2 == 1 ) {
    		if (C[i] == 'W') {
    			res++;
    			update( dy, 0, -1 );
    			update( 0, dx, -1 );
    			update( dy, dx, 2 );

    			update( 0, dx + k, 1 );
    			update( dy, dx + k, -2 );

    			update( dy+k, 0, 1 );
    			update( dy+k, dx, -2 );

    			update( dy+k, dx+k, 2 );
    		}
    		else {
    			update( dy, 0, 1 );
    			update( 0, dx, 1 );
    			update( dy, dx, -2 );

    			update( 0, dx + k, -1 );
    			update( dy, dx + k, 2 );

    			update( dy+k, 0, -1 );
    			update( dy+k, dx, 2 );

    			update( dy+k, dx+k, -2 );
    		}
    	}
    }
    ans = res;
    fore(i, 0, 2*k+1) {
    	fore(j, 0, 2*k+1) {
    		ans = max(ans, res + query(i, j));
    	}
    }
    cout << ans << '\n';
    return 0;
}
// PLUS ULTRA!

Measured memory_bytes: 20176
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;
int main() {
  int K,N;
  cin >>N>>K;
  long long h[110000];
  for(int i=0; i<N;i++){
    cin >>h[i];
  }
  sort(h,h+N);
  long long min=1000000000;
  for(int i=0; i+K-1<N;i++){
    if(h[i+K-1]-h[i]<min) min=h[i+K-1]-h[i];
  }
  cout <<min <<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

int main(){
    int a,b;
    double ans;
    int temp;
    
    cin >> a >> b;
    temp = b;
    while(temp > 0){
        a *= 10;
        temp /= 10;
    }
    a += b;
    ans = sqrt(a);
   // cout << ans << endl;
    if( ans == int(ans)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    ans = 0;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
 
const int N = 1e5;
int dp[N];
 
int main(){
	int a;
	vector<int> v;
	v.push_back(1);
	for(int i = 0;i < N;++i){
		dp[i] = i + 1;
	}
	for(int i = 6;i < N;i *= 6){
		dp[i - 1] = 1;
		v.push_back(i);
	}
	for(int i = 9;i < N;i *= 9){
		dp[i - 1] = 1;
		v.push_back(i);
	}
	sort(v.begin(), v.end(), greater<int>());
	cin >> a;
	for(int i = 0;i < a;++i){
		for(int j = 0;j < v.size();++j){
			int k = i + v[j];
			if(k < a){
				dp[k] = min(dp[k], dp[i] + 1);
			}
		}
	}
	cout << dp[--a] << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
	int num,top;
	int car[11];
	int i;
	
	top=0;
	while(scanf("%d",&num)!=EOF){
		if(num==0){
			printf("%d\n",car[top-1]);
			car[top-1]=0;
			top--;
		}
		else{
			car[top]=num;
			top++;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

#include <complex>
typedef complex<double> P;

double dot(P a, P b) {
	return (a.real()*b.real() + a.imag()*b.imag());
}

double cross(P a, P b) {
	return (a.real()*b.imag() - a.imag()*b.real());
}

double area(P a, P b, P c) {
	return abs(cross(c-a, b-a)*0.5);
}

double to_radian(double degree) {
	return degree*PI/180.0;
}

#define LT(x,y) ((x)-(y)<=-EPS)

int main() {
	int m, n;
	while(cin >> m, m) {
		P o(0.0, 0.0);
		vector<P> pm;
		double v, tmp = 0;
		REP(i, m-1) {
			cin >> v;
			tmp += v;
			pm.push_back(P(cos(to_radian(tmp)), sin(to_radian(tmp))));
		}
		pm.push_back(P(cos(to_radian(0.0)), sin(to_radian(0.0))));
		double Sm = 0.0;
		REP(i, m) {
			Sm += area(pm[i], pm[(i+1)%m], o);
		}

		cin >> n;
		vector<P> pn;
		tmp = 0;
		REP(i, n-1) {
			cin >> v;
			tmp += v;
			pn.push_back(P(cos(to_radian(tmp)), sin(to_radian(tmp))));
		}
		pn.push_back(P(cos(to_radian(0.0)), sin(to_radian(0.0))));
		double Sn = 0.0;
		REP(i, n) {
			Sn += area(pn[i], pn[(i+1)%n], o);
		}

		if(LT(Sm, Sn)) {
			cout << 2 << endl;
		} else if(LT(Sn, Sm)) {
			cout << 1 << endl;
		} else {
			cout << 0 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
const int mod = 1000000007;
const int modx = 998244353;
#define ll long long
#define readi(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define readl(x) scanf("%I64d", &x)
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)
#define rep2(i, a, b) for (i = b; i >= a; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bpc(x) __builtin_popcount(x)
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pdd pair<double, double>
#define pic pair<int, char>
#define ddouble long double
#define PI 3.1415926535
#define endl "\n"
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define prod(x, y) ((x % mod) * (y % mod)) % mod
#define add(x, y) ((x % mod) + (y % mod)) % mod
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define pqs priority_queue<int, vector<int>, greater<int>>
#define pqb priority_queue<int>
#define mii map<int, int>
#define mll map<ll, ll>
using namespace std;
//using namespace __gnu_pbds;
/*ll power(ll x, ll y)
{
    ll r = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            r = (r*x) % mod;

        y = y>>1;
        x = (x*x) % mod;
    }
    return r;
}*/

void thunder()
{
    int n, k;
    cin >> n >> k;
    vi h(n), dp(n, INT_MAX);
    dp[0] = 0;
    for (auto &it : h)
        cin >> it;
    int i, j;
    rep(i, n)
    {
        rep1(j, i + 1, i + k + 1)
        {
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
            else
                break;
        }
    }
    /*for (auto it : h)
        cout << it << " ";
    cout << endl;
    rep(i, n) cout << dp[i] << " ";
    cout << endl;
    return;*/
    cout << dp[n - 1] << endl;
}
int main()
{
    /*#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif*/
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while (t--)
        thunder();
}


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

int main() {
  int n, k, i, l, r, ans = 1000000000;
  cin >> n >> k;
  
  vector<int> x(n);
  for(i = 0; i < n; i++){
    cin >> x.at(i);
  }
  
  for(i = 0; i < n - k + 1; i++){
    l = x.at(i);
    r = x.at(i + k - 1);
    ans = min(ans, min(abs(r - l) + abs(l), abs(r - l) + abs(r)));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n;
cin>>n;
ll a[n]={};
ll counter=0;
for(ll i=0; i<n; i++){
cin>>a[i];}
ll a1=a[0];
ll r=0;
ll b1,b2;
ll f=1;
for(ll i=1; i<n; i++){
b1=a1;
b2=a[i];
while(b1>0||b2>0){
if(b1%2!=b2%2){
r+=f;}
f*=2;
b1/=2;
b2/=2;}
a1=r;
r=0;
f=1;}
counter=a1;
for(ll i=0; i<n; i++){
a1=counter;
while(a1>0||a[i]>0){
if(a1%2!=a[i]%2){
r+=f;}
f*=2;
a1/=2;
a[i]/=2;}
cout<<r<<" ";
r=0;
f=1;}}

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

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define repr(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define repf(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define inf 1e9

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

using namespace std;
using ll = long long;

int main(int argc, char const *argv[])
{
    int n, c;
    cin >> n >> c;

    vector<int> p(c);
    for (auto &&i : p)
    {
        cin >> i;
    }

    int sum = accumulate(all(p), 0);
    int ans = 0;

    if (sum % (n + 1) == 0)
    {
        cout << sum / (n + 1) << endl;
    }
    else
    {
        cout << sum / (n + 1) + 1 << endl;
    }

    return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    vector<mp> b(n);
    for(ll i=0;i<n;i++) b[i] = mp( a[i] , i+1 );
    sort( b.begin() ,b.end() );
    cout<<b[0].second;
    for(ll i=1;i<n;i++)cout<<' '<<b[i].second;
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

vector<string> split(string str, const char ch) {
	vector<string> res;
	string s = "";
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == ch) {
			res.push_back(s);
			s = "";
		}else{
			s += str[i];
		}
	}
	res.push_back(s);
	return res;
}

int main() {
	string source;
	getline(cin, source);
	
	string maxl = "", mode = "";
	int max = 0;
	vector<string> str = split(source, ' ');
	map<string, int> m;
	
	for (int i = 0; i < str.size(); i++) {
		if (m[str[i]] == 0) {
			m[str[i]] = 1;

			if (str[i].length() > maxl.length()) {
				maxl = str[i];
			}
		}else{
			m[str[i]]++;

			if (m[str[i]] > max) {
				max = m[str[i]];
				mode = str[i];
			}
		}
	}
	cout << mode << " " << maxl << endl;
	return 0;
}

Measured memory_bytes: 3036
n = int(input())
nums = [int(i) for i in input().split()]

each_abs = [abs(nums[0])]
for i in range(1, n):
    each_abs.append(abs(nums[i] - nums[i-1]))
# 0に帰る道
each_abs.append(abs(nums[-1]))
s = sum(each_abs)

add_list = []
for i in range(n):
    if i == 0:
        add_list.append(abs(nums[i+1]))
    elif i == n-1:
        add_list.append(abs(nums[-2]))
    else:
        add_list.append(abs(nums[i+1] - nums[i-1]))

del_list = []
for i in range(n):
    del_list.append(each_abs[i] + each_abs[i+1])

for i in range(n):
    print(s + add_list[i] - del_list[i])


Measured memory_bytes: 20136
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int n, k;
    cin >> n >> k;

    vector<int> kirai;
    for (int i = 0; i < k; i++) {
        int d;
        cin >> d;
        kirai.push_back(d);
    }

    for (int i = 0; i < 100000; i++) {
        int t = i;
        bool valid = true;

        while (t > 0) {
            bool possible = true;
            for (int j = 0; j < kirai.size(); j++) {
                if (t % 10 == kirai[j]) {
                    possible = false;
                }
            }
            if (!possible) valid = false;
            t /= 10;
        }

        if (valid && i >= n) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
import math
N, K = map(int, input().split())
# print(N, K)

ans = 0
for i in range(1, N + 1):
    # print(i)
    need_omote = max(math.ceil(math.log2(K / i)), 0)
    ans += math.pow(0.5, need_omote)
print(ans / N)


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

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

ll mod = 1e9 + 7;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a.at(i);
    ll m(0);
    rep(i, 60)
    {
        ll x1(0);
        rep(j, n) if ((a.at(j) >> i) & 1) x1++;
        ll x0(n - x1);
        ll p = 1;
        rep(j, i)
        {
            p *= 2;
            p %= mod;
        }
        ll c = (x0 * x1) % mod;
        m += p * c;
        m %= mod;
    }
    cout << m << endl;

    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define pint pair<int, int>
#define mp make_pair

using namespace std;

typedef long long ll;


int main() {
	int N;
	int p[100], s[100];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		s[i] = i + 1;
	}

	int dif = 0;
	for (int i = 0; i < N; i++) {
		if (p[i] != s[i]) dif++;
	}

	if (dif == 2 || dif == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
   if (a < b){
        if (c < a)
            printf("%d %d %d\n", c, a, b);
        else if(b < c)
            printf("%d %d %d\n", a, b, c);
        else
            printf("%d %d %d\n", a, c, b);
    }

   if (b < a){
        if (c < b)
            printf("%d %d %d\n", c, b, a);
        else if(a < c)
            printf("%d %d %d\n", b, a, c);
        else
            printf("%d %d %d\n", b, c, a);
    }


return 0;
}


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

using namespace std;
#define eps 1e-10

void solve()
{
	int N;
	cin >> N;
	while(N--)
	{
		double x[4], y[4];
		for(int i = 0; i < 4; ++i)
		{
			cin >> x[i] >> y[i];
		}
		if(x[1] == x[0] && x[3] == x[2])
		{
			if(y[1] == y[0] || y[3] == y[2])
			{
				cout << "NO" << endl;
			}
			else
			{
				cout << "YES" << endl;
			}
		}
		else if(x[1] == x[0] || x[3] == x[2])
		{
			cout << "NO" << endl;
		}
		else if((y[1] - y[0]) / (x[1] - x[0]) == (y[3] - y[2]) / (x[3] - x[2]))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);


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

    int n,k;
    cin >> n >> k;
    cout << n-k+1 << endl; 

    return 0; 
}


Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct Node{
	int f,e,w;
};
inline bool cmp(Node a,Node b){
	return a.w<b.w;
}
int bc[100+30];
int bcj(int x){
    if(bc[x]==x) return bc[x];
    return bc[x]=bcj(bc[x]);
}
int ans,n;
vector<Node> edl;
int main(){
	cin>>n;
	for(int i=0;i<n;++i) bc[i]=i;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			Node x;
			x.f=i;x.e=j;
			cin>>x.w;
			if(x.w!=-1) edl.push_back(x);
		}
	}
	sort(edl.begin(),edl.end(),cmp);
	int tot=0,xi=0;
	while(tot<n-1){
		int a=edl[xi].f,b=edl[xi].e;
		if(bc[bcj(a)]!=bcj(b)){
			bc[bcj(a)]=bcj(b);
			++tot;
			ans+=edl[xi].w;
		}
		++xi;
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(void){

    long long N;
    cin >> N;
    
    long long ans = 0;
    while(N>=500){
        N-=500;
        ans += 1000;
    }
    //cout << N <<endl;
    while(N>=5){
        N-=5;
        ans += 5;
    }
    
    cout << ans <<endl;
}


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

using namespace std;

const int maxN = 1e5+5;
const int INF = 1e9;

int A[maxN][3], DP[maxN][3];

void solve() {
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        cin >> A[i][0] >> A[i][1] >> A[i][2];
    }
    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] + A[i][0], DP[i-1][2] + A[i][0]);
        DP[i][1] = max(DP[i-1][0] + A[i][1], DP[i-1][2] + A[i][1]);
        DP[i][2] = max(DP[i-1][0] + A[i][2], DP[i-1][1] + A[i][2]);
    }
    cout << max({DP[n-1][0], DP[n-1][1], DP[n-1][2]}) << "\n";

}

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

    bool multitest = false;
    //multitest = true;
    if (multitest) {
        int t; cin >> t;
        while (t--)
            solve();
    }
    else
        solve();
}


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

const int INF = 1e9;

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

  int ans = -INF;
  int mi = INF;
  for( int i = 0; i < N; i++ ){
    int a; cin >> a;
    if( i != 0 && ans < a - mi ) ans = a - mi;
    if( mi > a ) mi = a;
  }

  cout << ans << endl;
}



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

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

void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 1);

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

  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 1 && a[i] % 2 == 1) {
      ++cnt;
    }
  }

  cout << cnt << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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 / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    vector<ll> b(n-1);
    for(ll i=0;i<n-1;++i){
        cin>>b[i];
    }

    ll ans = b[0];
    for(ll i=1;i<n-1;++i){
        ans += min(b[i], b[i-1]);
    }
    ans += b[n-2];
    cout<<ans<<endl;
        
    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Node
{
    ll x;
    ll y;
    int i;
};
struct Cost
{
    int a;
    int b;
    ll c;
};
struct UnionFind
{
    void init(int n)
    {
        mN = n;
        mNodeTbl.resize(mN);
        mRankTbl.resize(mN);
        REP(i, mN)
        {
            mNodeTbl[i] = i;
            mRankTbl[i] = 0;
        }
    }
    int find(int x)
    {
        if (x == mNodeTbl[x])
            return x;
        return mNodeTbl[x] = find(mNodeTbl[x]);
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    void unit(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (mRankTbl[x] < mRankTbl[y])
        {
            mNodeTbl[x] = y;
        }
        else
        {
            mNodeTbl[y] = x;
            if (mRankTbl[x] == mRankTbl[y])
                mRankTbl[x]++;
        }
    }

    int mN;
    vector<int> mNodeTbl;
    vector<int> mRankTbl;
};

int N;
Node n[100005];
vector<Cost> C;
void push()
{
    REP(i, N)
    {
        if (i + 1 < N)
        {
            Cost t;
            t.a = n[i + 1].i;
            t.b = n[i].i;
            t.c = min(abs(n[i + 1].x - n[i].x), abs(n[i + 1].y - n[i].y));
            C.push_back(t);
        }
    }
}

int main()
{

    cin >> N;
    REP(i, N)
    {
        cin >> n[i].x >> n[i].y;
        n[i].i = i;
    }
    sort(n, n + N, [](Node a, Node b) { return a.x < b.x; });
    push();
    sort(n, n + N, [](Node a, Node b) { return a.y < b.y; });
    push();
    sort(C.begin(), C.end(), [](Cost a, Cost b) { return a.c < b.c; });
    UnionFind uf;
    uf.init(N);
    ll cost = 0;
    REP(i, C.size())
    {
        if (uf.same(C[i].a, C[i].b))
            continue;
        uf.unit(C[i].a, C[i].b);
        cost += C[i].c;
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 8688
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> mp;
  for (int i = 0; i < N; i++) cin >> A[i];

  /*
  条件より
  A[j] + A[i] = j - i
  j - A[j] = i + A[i]
  となればいい(j > i)
  */

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += mp[i - A[i]];
    mp[i + A[i]]++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 20976
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    int k;
    
    cin >> k;
    
    if(k % 2 == 0) {
        cout << int(pow(k/2, 2)) << endl;
    } else {
        cout << int(((k+1)/2) * ((k+1)/2 - 1)) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,T,S,E;
vector<pair<int,int> >G[1<<17];
bool ans=true;
pair<int,bool>dfs(int u,int p)
{
	int eid=-1;
	vector<int>X;
	for(int i=0;i<G[u].size();i++)
	{
		if(G[u][i].first==p)continue;
		int v=G[u][i].first;
		pair<int,bool>q=dfs(v,u);
		if(q.second)
		{
			eid=i;
		}
		else
		{
			X.push_back(G[u][i].second-q.first-(int)(p>=0));
		}
	}
	sort(X.begin(),X.end());
	for(int i=0;i<X.size();i++)
	{
		if(i>X[i])
		{
			ans=false;
		}
	}
	if(eid>=0)
	{
		if(G[u][eid].second-(int)X.size()-(p>=0)<0)
		{
			ans=false;
		}
	}
	return make_pair(G[u].size(),eid>=0||E==u);
}
main()
{
	cin>>N>>T>>S>>E;
	S--,E--;
	if(T==0)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	for(int i=1;i<N;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		a--,b--;
		c=(c-1)/T;
		G[a].push_back(make_pair(b,c));
		G[b].push_back(make_pair(a,c));
	}
	dfs(S,-1);
	cout<<(ans?"Yes":"No")<<endl;
}



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

void swap(int &a,int &b)
{
    int c = a;
    a = b;
    b = c;
}

int main()
{
    int a[3],tmp;
    cin>>a[0]>>a[1]>>a[2];
    for(int i = 0;i<3;i++){
        for(int j = i;j<3;j++){
            if(a[i]>a[j]) swap(a[i],a[j]);
        }
    }
    cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
    return 0;
}


Measured memory_bytes: 3100
sx,sy,tx,ty=map(int, input().split())
tx2,ty2=tx-sx,ty-sy
a1='U'*ty2+'R'*tx2+'D'*ty2+'L'*tx2
a2='L'+'U'*(ty2+1)+'R'*(tx2+1)+'DR'+'D'*(ty2+1)+'L'*(tx2+1)+'U'
print(a1+a2)

Measured memory_bytes: 3060
x,k,d=map(int,input().split())
a=abs(x)//d
if a>=k:
	print(abs(x)-k*d)
else:
	over=abs(abs(x)-(a+1)*d)
	not_over=abs(x)-a*d
	if (k-a)%2==0:
		print(not_over)
	else:
		print(over)

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

int main(){
  int N;
  string A;
  string B;
  string ans = "";
  cin >> N;
  cin >> A;
  cin >> B;
  for(int i=0;i<N;i++){
    ans += A[i];
    ans += B[i];
  }
  cout << ans;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    int sum = 0;
    int mx = 0;
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        sum += p;
        mx = max(mx, p);
    }
    cout << sum - mx / 2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
vector< pair<ll,ll> > vc; ll n; ll dp[2001][2001];
ll maxval(ll s,ll cur_i){
    if(cur_i>n) return 0;
    if(dp[s][cur_i]!=-1){
        return dp[s][cur_i];
    }
    ll e,dn=(cur_i-1);
    e=n-(dn-(s-1));
    // cout<<cur_i<<" "<<s<<" "<<e<<endl;
    ll a,b;
    a=abs(vc[cur_i-1].sc-s)*vc[cur_i-1].fs+maxval(s+1,cur_i+1);
    b=abs(vc[cur_i-1].sc-e)*vc[cur_i-1].fs+maxval(s,cur_i+1);
    return dp[s][cur_i]=max(a,b);
}
int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    ll i,j,k,l;
    cin>>n;
    ll ar[n+1]; 
    for(i=1;i<=n;i++){
        cin>>ar[i];
        vc.ps({ar[i],i});
    }
    sort(all(vc));
    reverse(all(vc));
    memset(dp,-1,sizeof(dp));
    ll an=maxval(1,1);
    cout<<an;
    return 0;
}

Measured memory_bytes: 35120
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main(){
	while(1){
		int n;
		int a[4]={1000,100,10,1};
		int l[4]={0},s[4]={0};
		int ans[4];
		cin>>n;
		if(n==0000)break;
		int cnt=0;
		int i,j;
		for(i=0;i<4;i++){
			l[i]=n/a[i];
			s[i]=l[i];
			n%=a[i];
		}
		if(l[0]==l[1]&&l[1]==l[2]&&l[2]==l[3])cout<<"NA"<<endl;
		else if(l[0]==6&&l[1]==1&&l[2]==7&&l[3]==4)cout<<0<<endl;
		else{
			while(1){
			for(i=0;i<4;i++){
				for(j=3;j>i;j--){
					if(l[i]<l[j]){
						swap(l[i],l[j]);
					}
					if(s[i]>s[j]){
						swap(s[i],s[j]);
					}
				}
			}
			cnt++;
				n=(l[0]*a[0]+l[1]*a[1]+l[2]*a[2]+l[3]*a[3])-(s[0]*a[0]+s[1]*a[1]+s[2]*a[2]+s[3]*a[3]);
						for(i=0;i<4;i++){
			l[i]=n/a[i];
			s[i]=l[i];
			ans[i]=l[i];
			n%=a[i];
		}
			if(ans[0]==6&&ans[1]==1&&ans[2]==7&&ans[3]==4){
				cout<<cnt<<endl;
				break;
			}
		}
		}
	}
	return 0;
}

Measured memory_bytes: 3084
def r(a): #ランレングス圧縮
    ll,l=[],1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            l+=1
        else:
            ll.append(l)
            l=1
    ll.append(l)
    return ll

def cum(a): #累積和
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b

n=int(input())
print(sum([i*(i-1)//2 for i in r(sorted(cum(list(map(int,input().split())))))]))

Measured memory_bytes: 26136
N = int(input())
sl = [input() for i in range(N)]
M = int(input())
tl = [input() for i in range(M)]
ans = 0
for s in sl:
    tmp = sl.count(s)
    if s in tl:
        tmp -= tl.count(s)
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, double> pdd;
const double eps = 1e-10;
const double pi = acos(-1);
inline int sgn(double d){if(fabs(d) < eps) return 0;if(d > 0) return 1;return -1;}
inline double rad(double _deg){return _deg / 180.0 * pi;}
inline double deg(double _rad){return _rad / pi * 180.0;}
struct Point{
	double x, y;
	void read(){scanf("%lf%lf", &x, &y);}
	Point():x(0.0), y(0.0){}
	Point(double a, double b = 0.0): x(a), y(b){}
	Point(const Point& p): x(p.x), y(p.y){}
	Point operator + (const Point& a){return {x + a.x, y + a.y};}
	Point operator - (const Point& a){return {x - a.x, y - a.y};}
	double operator * (const Point& a){return x * a.x + y * a.y;}
	double operator ^ (const Point& a){return x * a.y - y * a.x;}
	bool operator == (const Point& p){return sgn(x - p.x) == 0 && sgn(y - p.y) == 0;}
	bool operator < (const Point &p) const{
		if(sgn(x - p.x) == 0) 
			return sgn(y - p.y) == -1;
		return sgn(x - p.x) == -1;
	}
	double length(){return sqrt(x * x + y * y);}
}typedef Vector;
struct Line{
	Point a, b;
	void read(){a.read(); b.read();}
	Line() : a(0.0, 0.0) , b(0.0, 0.0){}
};
struct Segment{
	Point a, b;
	void read(){a.read(); b.read();}
	Segment() : a(0.0, 0.0) , b(0.0, 0.0){}
};
double distance(const Point &a, const Point &b) 
{
	double x = a.x - b.x;
	double y = a.y - b.y;
	return sqrt(x * x + y * y);
}
Point Projection(Point p, Line l)
{ 
	// 点在直线上的投影点
	Vector v1 = l.b - l.a;
	Vector v2 = p - l.a;
	double k1 = v1 * v2;
	double k2 = v1.length();
	k1 /= k2 * k2;
	return {l.a.x + v1.x * k1, l.a.y+ v1.y * k1};
}
Point Reflection(Point p, Line l)
{
	// 点关于直线对称
	Point p0 = Projection(p, l);
	Vector v0 = p0 - p;
	return p0 + v0;
}
int ccw(Point p, Segment sg)
{	// Counter_Clockwise
	// p 关于(sg.a -> sg.b)的位置关系
	Vector v0 = sg.b - sg.a;
	Vector v1 = p - sg.a;
	
	int fcross = sgn(v0 ^ v1);
	
	if(fcross == 1) return 1; // 顺时针方向
	if(fcross == -1) return 2; // 逆时针方向
	
	int fdot = sgn(v0 * v1);
	
	if(fdot == -1) return 3; // 反向线段外共线
	if(v0.length() < v1.length()) return 4; //正向线段外共线
	return 5; //点在线段上
}
bool isParallel(Line l1, Line l2)
{
	return sgn((l1.b - l1.a) ^ (l2.b - l2.a)) == 0;
}
bool isOrthogonal(Line l1, Line l2)
{
	return sgn((l1.b - l1.a) * (l2.b - l2.a)) == 0;
}
int main()
{
	int n;
	scanf("%d", &n);
	while(n --)
	{
		Line l1, l2;
		l1.read(); l2.read();
		if(isParallel(l1, l2)) puts("2");
		else if(isOrthogonal(l1,l2)) puts("1");
		else puts("0");
	}
	return 0;
}


Measured memory_bytes: 3256