akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

vector<vector<pair<ll, ll>>> edge;
vector<ll> dist;

void dfs(ll node){
	for(ll i = 0; i < edge[node].size(); i ++){
		if(dist[edge[node][i].first] < 0){
			dist[edge[node][i].first] = dist[node] + edge[node][i].second;
			dfs(edge[node][i].first);
		}
	}
}
int main(){

	ll N;
	cin >> N;
	edge = vector<vector<pair<ll, ll>>>(N);
	ll a, b, c;
	for(ll i = 0; i < N - 1; i ++){
		cin >> a >> b >> c;
		a --;
		b --;
		edge[a].pm(b, c);
		edge[b].pm(a, c);
	}
	ll Q, K;
	cin >> Q >> K;
	K --;
	dist = vector<ll>(N, -1);
	dist[K] = 0;
	dfs(K);
	/*for(int i = 0; i < N; i ++){
		cout << i << SPACE << dist[i] << endl;
	}*/
	ll x, y;
	for(ll i = 0; i < Q; i ++){
		cin >> x >> y;
		x --;
		y --;
		//cout << "dist[x] = " << dist[x] << ", dist[y] = " << dist[y] << endl;
		cout << dist[x] + dist[y] << endl;
	}

	return 0;
}

Measured memory_bytes: 13568
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception{
        Input input = new Input();
        int caseNumCount = 10000;
        for(int caseNumber = 1; caseNumber <= caseNumCount; caseNumber++){
            int inputNum = input.inputNum(); 
            if( inputNum == 0){
                break;
            }else{
                System.out.println( "Case" + " " + caseNumber + ":" + " " + inputNum);
            }
        }
    }
}

class Input{
    Scanner sc;
    public Input(){
        this.sc = new Scanner(System.in);
    }
    public int inputNum() throws Exception{
        return this.sc.nextInt();
    }
}


Measured memory_bytes: 41152
#include <cstdio>
#include <cstring>

typedef unsigned long long int ull;

int N;

const int MAXN=502;

struct info_t{
    ull targets[MAXN];
    int opcat[MAXN];
    int zeroCount[64][MAXN];
}row,col;

ull matrix[MAXN][MAXN];

bool check(){
    //
    for(int r=1;r<=N;r++){
        ull androw=-1,orrow=0ull,andcol=androw,orcol=orrow;
        for(int c=1;c<=N;c++){
            androw&=matrix[r][c];
            orrow|=matrix[r][c];
            andcol&=matrix[c][r];
            orcol|=matrix[c][r];
        }

        if (row.opcat[r]&&orrow!=row.targets[r]) return false;
        if (!row.opcat[r]&&androw!=row.targets[r]) return false;
        if (col.opcat[r]&&orcol!=col.targets[r]) return false;
        if (!col.opcat[r]&&andcol!=col.targets[r]) return false;
    }

    return true;
}

void simpleInference(int pos){
    for(int r=1;r<=N;r++){
        for(int c=1;c<=N;c++){
            //目標値の対応ビットを取り出す
            auto colBit=(col.targets[c]>>pos)&1;
            auto rowBit=(row.targets[r]>>pos)&1;

            if (colBit^col.opcat[c]) matrix[r][c]|=(colBit<<pos);

            if (rowBit^row.opcat[r]) matrix[r][c]|=(rowBit<<pos);

            if (rowBit==colBit) matrix[r][c]|=(rowBit<<pos);
        }
    }
}

void SpecialInference(info_t& one,info_t& another,bool isRow,int pos){
    ull mask=(ull)1<<(ull)pos;
    for(int r=1;r<=N;r++){
        //今の桁を何にするかを表す
        auto bitTarget=(one.targets[r]>>pos)&one.opcat[r];
        if (!bitTarget||one.zeroCount[pos][r]<N) continue;
        
        int c=1;
        while(c<=N){
            if (another.opcat[c]==0&&(another.targets[c]&mask)==0&&another.zeroCount[pos][c]>1) break;
            c++;
        }
        if (c>N) continue;
        if (isRow)
            matrix[r][c]|=mask;
        else 
            matrix[c][r]|=mask;
        another.zeroCount[pos][c]--;
        one.zeroCount[pos][r]--;
    }
}

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

    for(int i=1;i<=N;i++) scanf("%d",row.opcat+i);
    for(int i=1;i<=N;i++) scanf("%d",col.opcat+i);
    for(int i=1;i<=N;i++) scanf("%llu",row.targets+i);
    for(int i=1;i<=N;i++) scanf("%llu",col.targets+i);

    for(int bit=0;bit<64;bit++){
        simpleInference(bit);

        for(int r=1;r<=N;r++)
            for(int w=1;w<=N;w++)
                if (((matrix[r][w]>>bit)&1)==0) row.zeroCount[bit][r]++,col.zeroCount[bit][w]++;

        SpecialInference(row,col,true,bit);
        SpecialInference(col,row,false,bit);
    }

    if (!check()){
        puts("-1");
        return 0;
    }

    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++)
            printf("%llu ",matrix[i][j]);
            putchar('\n');
    }

    return 0;
}

Measured memory_bytes: 7576
#include <stdio.h>
int main()
{
  int a,b,c,d = 0,i;
  for(;;){
    scanf("%d%d",&a,&b);
    if(a==0 && b==0) break;
    if(d) printf("\n");
    c = 0;
    for(i=a;i<=b;i++){
      if(i % 400 == 0 || i % 4 == 0 && i % 100 != 0){
	printf("%d\n",i);
	c = 1;
      }
    }
    if(!c) printf("NA\n");
    d = 1;
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <string>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;


int main() {
    while(1) {
        int e;
        cin >> e;
        if(e == 0) {
            break;
        }
        int min = 1000000;
        for(int z = 0; z*z*z <= e; z++) {
            for(int y = 0; y*y <= e-z*z*z; y++) {
                int tmp  = e-y*y-z*z*z + y + z;
                if(tmp < min){
                    min = tmp;
                }
            }
        }
        cout << min << endl;
    }
	return 0;
}

Measured memory_bytes: 3012
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } }
const LL LLINF = 1LL << 60;

vector<LL> dp(100010, LLINF);

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

	vector<LL> H(100010);
	rep(i, N) cin >> H[i];

	dp[0] = 0;

	for (LL i = 0; i < N; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]));
	}

	cout << dp[N - 1] << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
const ll MOD = 1e9 + 7;
using namespace std;
ll powmod(ll a, ll b, ll MOD = MOD){
    if(!a and !b)	return 1ll;
    if(!a)	return a;
    ll res = 1ll;
    b %= (MOD - 1ll), a %= MOD;
    while(b){
        if(b%2 == 1)	res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
void panda() {
    ll m,n;
    cin>>n>>m;
    ll arr[m];
    ll sum=0;
    for(auto i =0;i<m;++i)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    if(sum<=n)
        cout<<n-sum<<"\n";
    else
        cout<<"-1"<<"\n";


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


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

using namespace std;

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

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

	int n;
	cin >> n;

	vector<int> x(n), l(n);
	rep(i, n) cin >> x[i] >> l[i];

	vector<pli> w(n);
	rep(i, n) w[i] = {x[i] + l[i], i};
	sort(w.begin(), w.end());

	int ans = 1;
	int t = 0;
	rep(i, n-1){
		int j = w[i+1].second;
		if(w[t].first <= x[j] - l[j]){
			ans++;
			t = i+1;
		}
	}

	cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
    a.at(i)--;
  }
  
  vector<int> b(n);
  for(int i = 0; i < n; i++) {
    cin >> b.at(i);
  }

  vector<int> c(n-1);
  for(int i = 0; i < n-1; i++) {
    cin >> c.at(i);
  }
  
  int ans = 0;
  int temp = a.at(0);
  for(int i = 0; i < n; i++){
    ans+= b.at(a.at(i));
    if (a.at(i) == temp+1){
      ans += c.at(a.at(i)-1);
    }
    temp = a.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  char c;
  cin >> c;
  if(c>='A'&&c<='Z') {
    cout << "A" << endl;
  } else {
    cout << "a" << endl;
  }
  return 0;
}

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

int main(){
	int n, c[100][100];
	cin >> n;
	for(int i = 0; i < n; ++i)
	for(int j = 0; j < n; ++j){
		cin >> c[i][j];
	}
	long long s = 0;
	for(int i = 1; i < n; ++i)
	for(int j = 0; j < i; ++j){
		s += min(c[i][j], c[j][i]);
	}
	cout << s << endl;
}

Measured memory_bytes: 1196
/*16D8104007J 1-A　兼弘真帆　*/
#include<stdio.h>

void insertionSort(int A[],int N);

int main(){
  int N;
  // printf("長さN:"); 
  scanf("%d",&N);
  int A[N];
  int i;

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  insertionSort(A,N);
  return 0;

}

void insertionSort(int A[],int N){
  int i,j,v,n;
  for(n=0;n<N;n++){
    printf("%d",A[n]);
    if(n!=N-1){
      putchar(' ');
    }
  }
  
  putchar('\n');

  for(i=1;i<N;i++){
    // printf("test2\n");
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
      // printf("test1\n");
    }
    A[j+1]=v;
    for(n=0;n<N;n++){
      if(n!=N-1){
	printf("%d ",A[n]);
      }else{
	printf("%d\n",A[n]);
      }
    }
  }
}



Measured memory_bytes: 2044
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using ll = long long;

template <typename T>
T min(T a, T b){
  return (a < b) ? a : b;
}

template <typename T>
class SegTree{
  static const int MAXN = 100010;
  T INF;
  int n;
  T A[MAXN*4];
  public:
  SegTree(int size, T INF): INF(INF){
    n = 1;
    while(n < size){
      n *= 2;
    }
    for(int i = 0; i < MAXN*4; i++) A[i] = INF;
  }

  T query(int a, int b){
    return _query(a, b, 0, 0, n);
  }

  T _query(int a, int b, int k, int l, int r){
    if(a >= r || b <= l){
      return INF;
    }
    if(l >= a && r <= b){
      return A[k];
    }
    T v1 = _query(a, b, 2*k + 1, l, (l+r)/2);
    T v2 = _query(a, b, 2*k + 2, (l+r)/2, r);
    return min(v1, v2);
  }

  void update(int _idx, int value){
    int offset = n - 1;
    int idx = _idx + offset;
    A[idx] = value;
    while(idx > 0){
      idx = (idx-1)/2;
      A[idx] = min(A[idx*2+1], A[idx*2+2]);
    }
  }
};

int main(void){
  int n, q; cin >> n >> q;
  SegTree<int> rmq(n, 0x7FFFFFFF);
  for(int loop = 0; loop < q; loop++){
    int com, x, y;
    cin >> com >> x >> y;
    if(com == 0){
      rmq.update(x, y);
    }else{
      cout << rmq.query(x, y+1) << endl;
    }
  }
}



Measured memory_bytes: 4692
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: isize = iterator.next().unwrap().parse().unwrap();
    let b: isize = iterator.next().unwrap().parse().unwrap();
    let c: isize = iterator.next().unwrap().parse().unwrap();

    return if b - a == c - b {
        "YES".to_string()
    } else {
        "NO".to_string()
    };
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int k, x; cin>>k>>x;
  for(int i=x-(k-1);i<x+k;++i){
    cout << i << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
def factorial(n):
    if (n==0) or (n==1):
        return 1
    ret = 1
    for i in range(2, n+1):
        ret *= i
    return ret
def combination(n, k):
    return factorial(n)//factorial(k)//factorial(n-k)
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N = I()
abc = LIR(N)

dp = [[0]*(N+1) for i in range(3)]
A, B, C = 0, 1, 2

for i in range(N):
    a, b, c = abc[i]
    dp[A][i+1] = max(dp[B][i], dp[C][i]) + a
    dp[B][i+1] = max(dp[A][i], dp[C][i]) + b
    dp[C][i+1] = max(dp[A][i], dp[B][i]) + c

print(max(dp[A][N], dp[B][N], dp[C][N]))

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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

int main(){
    int H,W;
    cin>>H>>W;
    bool flag=true;
    vector<vector<char> > s(H+2,vector<char>(W+2,'.'));
    FOR(i,1,H+1){
        FOR(j,1,W+1){
            cin>>s[i][j];
        }
    }
    FOR(i,1,H+1){
        FOR(j,1,W+1){
            if(s[i][j]=='#'){
                if(s[i][j-1]!='#'&&s[i][j+1]!='#'&&s[i+1][j]!='#'&&s[i-1][j]!='#'){
                    flag=false;
                }
            }
        }
    }
    if (flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
#define l first
#define r second
bool comp(pair<int,int> a, pair<int,int> b)
{
	return min(a.l,a.r)<min(b.l,b.r);
}
int32_t main()
{
	int n=in();
	vector<int> a(n);
	trav(i,a)i=in();
	sort(all(a));reverse(all(a));
	priority_queue<pair<int,int>,vector<pair<int,int>>,function<bool(pair<int,int>, pair<int,int>)> > q(comp);
	int ans=0;
	q.push({a[0],a[0]});
	//q.push({a[0],a[0]});
	for(int i=1;i<n;i++)
	{
		
		auto p=q.top();
		//cout<<p.l<<" "<<p.r<<"\n";
		q.pop();
		ans+=min(p.l,p.r);
		q.push({p.l,a[i]});
		q.push({a[i],p.r});
	}
	cout<<ans;
	
}

Measured memory_bytes: 9028
#include<iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
typedef long long LL;
const int MAXN = 100005;
const LL inf = 0x3f3f3f3f3f3f3f3f;
int a[MAXN], b[MAXN], c[MAXN];
int n;
int search(int x)
{
    int ans=-1;
    int l=0,r=n-1;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(a[mid]<x)
        {
            ans=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    return ans;
}
int main()
{
    scanf("%d", &n);
    for(int i=0;i<n;++i)
        scanf("%d", &a[i]);
    sort(a, a+n);
    for(int i=0;i<n;++i)
        scanf("%d", &b[i]);
    sort(b, b+n);
    for(int i=0;i<n;++i)
        scanf("%d", &c[i]);
    sort(c,c+n);
    LL sum=0;
    for(int i=0;i<n;++i)
    {
        int u=lower_bound(a,a+n,b[i])-a;
        //printf("u=%d v=%d\n", u, lower_bound(c,c+n,b[u])-c);
        sum+=(n-(upper_bound(c,c+n,b[i])-c))*(u);
    }
    printf("%lld\n", sum);
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  string s;
  cin >> s;
  int R = 0; int B = 0;
  for(int i=0; i<N; i++){
    if(s.substr(i,1) == "R"){
      R++;
    }else{
      B++;
    }
  }
  if(R > B){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,a[N],P,Q,f[N];
signed main()
{
    n=read();
    for(ri int i=1;i<=n;i++) a[i]=read();
    int now=0;
    for(ri int i=1;i<=n;i++)
    {
        if(i&1ll)
        {
            if(now+a[i]>0) { now+=a[i]; continue; }
            P+=abs(now+a[i])+1, now=1;
        }
        else
        {
            if(now+a[i]<0) { now+=a[i]; continue; }
            P+=abs(now+a[i])+1, now=-1;
        }
    }
    now=0;
    for(ri int i=1;i<=n;i++)
    {
        if(i&1ll)
        {
            if(now+a[i]<0) { now+=a[i]; continue; }
            Q+=abs(now+a[i])+1, now=-1;
        }
        else
        {
            if(now+a[i]>0) { now+=a[i]; continue; }
            Q+=abs(now+a[i])+1, now=1;
        }
    }
    printf("%lld\n",min(P,Q));
    return 0;
}

Measured memory_bytes: 4528
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
            assert!(_it.next().is_none());
        }
    };
}

fn main(){
    from_line!(n: usize);
    let mut vec = Vec::new();
    for _ in 0..n-1 {
        from_line!(c: u64, s: u64, f: u64);
        vec.push((c, s, f));
    }
    for i in 0..n-1 {
        let (c, s, _) = vec[i];
        let mut sum = s + c;
        for j in i+1..n-1 {
            let (c, s, f) = vec[j];
            if sum < s {
                sum = s + c;
            } else {
                sum = (sum + f - 1) / f * f + c;
            }
        }
        println!("{}", sum);
    }
    println!("{}", 0);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
       	int n,m;cin>>n>>m;
       	int ans=0;	int h[n];
       	rep(i,n)cin>>h[i];
       	vector<int> g[n];
       	rep(i,m){
       		int u,v;cin>>u>>v;u--;v--;
       		g[u].pb(v);
       		g[v].pb(u);
       	}
       	rep(i,n){
       		int f=1;
       		for(auto j:g[i]){
       			if(h[i]<=h[j]){
       				f=0;break;
       			}
       		}
       		if(f)ans++;
       	}
       	cout<<ans;
    }   
    timecalculater();
    return 0;   
} 	

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define int long long
using namespace std;

int32_t main(){
	string s;
	cin >> s;
	string t;
	cin >> t;
	if(t.length() > (s.length()+1)){
		cout << "No" << endl;
	}
	else{
		int flag=0;
		for(int i = 0; i < s.length(); i++){
			if(t[i] != s[i]){
				flag = 1;
				break;
			}
		}
		if(flag == 1){
			cout << "No" << endl;
		}
		else{
			cout << "Yes" << endl;
		}
	}
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC111
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] vs = ReadInts();
            int[][] evenCnts = new int[100005][];
            int[][] oddCnts = new int[100005][];
            for (int i = 0; i < 100005; i++)
            {
                evenCnts[i] = new int[2] { 0, i };
                oddCnts[i] = new int[2] { 0, i };
            }
            for (int i = 0; i < n; i += 2)
            {
                evenCnts[vs[i]][0]++;
            }
            for (int i = 1; i < n; i += 2)
            {
                oddCnts[vs[i]][0]++;
            }
            Array.Sort(evenCnts, (a, b) => b[0] - a[0]);
            Array.Sort(oddCnts, (a, b) => b[0] - a[0]);
            if (evenCnts[0][1] == oddCnts[0][1])
            {
                if (evenCnts[0][0] + oddCnts[0][0] == n) WriteLine(n / 2);
                else if (evenCnts[0][0] == n / 2) WriteLine(n / 2 - oddCnts[1][0]);
                else if (oddCnts[0][0] == n / 2) WriteLine(n / 2 - evenCnts[1][0]);
                else WriteLine(Min(n - evenCnts[0][0] - oddCnts[1][0],
                    n - evenCnts[1][0] - oddCnts[0][0]));

            }
            else
            {
                WriteLine(n - evenCnts[0][0] - oddCnts[0][0]);
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 32856
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e9+7;

int main(){
    ll n,p;
    cin >> n;
    if(n % 2 != 0){
        p = n/2 + 1;
        cout << p;
    }else{
        p = n;
        cout << p/2;
    }

}

Measured memory_bytes: 3548
#include<iostream>
#include<string>
#include<math.h>
#include <vector>
#include <algorithm>

using namespace std;


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);    
        
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if((x-r>=0 && x+r<=W) && (y-r>=0 && y+r<=H)){
        cout <<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;}
        
}



Measured memory_bytes: 3196
#pragma once
#pragma once
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include <iomanip>
#define rep(i,n) for(auto i=0;i<(n);i++)
#define all(vs) (vs).begin(),(vs).end()
#define roundup(A,B) (A)/(B)+((A)%(B)==0?0:1)
#define read(type,name) type name;cin>>name
using namespace std;


/*
	3桁の数字からなる、重複を許す数字列はN^3パターンになる。O(1)
*/
void A() {
	read(int, i);
	cout << i * i * i << endl;
}

/*
 次の数字が連番である場合、追加でスコアが入る。そのため、直前の数字を記憶する必要がある。
 あとは情報を読み込んで配列を走査すればよい。空間量は今回削減できないと思われる。
*/
void B() {
	read(int, n);
	auto dishes = vector<int>(n);
	auto scores = vector<int>(n);
	auto bonus = vector<int>(n - 1);
	rep(i, n) cin >> dishes[i];
	rep(i, n) cin >> scores[i];
	rep(i, n - 1) cin >> bonus[i];
	auto prev = -1;
	int current;
	int result = 0;
	rep(i, n) {
		current = dishes[i];
		result += scores[current - 1];
		if (prev + 1 == current) result += bonus[prev - 1];
		prev = current;
	}
	cout << result << endl;
}

/*
*/
void C() {

}
void D() {

}
void E() {

}
void F() {

}



int main() {
	B();
}	
										

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値取得
		int X = scan.nextInt();
		int Y = scan.nextInt();

		//WK変数

		//演算
		String result = "No";

		if (Y % 2 == 0 && 2 * X <= Y && Y <= 4 * X) {
			result = "Yes";
		}

		//結果出力
		System.out.println(result);
	}
}

Measured memory_bytes: 35784
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

vector<int> val;
ll psum[MAXN];
ll dp[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    for(int i=1;i<=n;i++)
        cin>>A[i];

    for(int i=1;i<=n;i++)
        if(A[i]!=A[i-1])val.push_back(A[i]);

    int sz = val.size();

    dp[sz] = 1;

    for(int i=sz-1;i>=0;i--){
        dp[i] = (dp[i+1]+psum[val[i]])%MOD;
        psum[val[i]]+=dp[i+1];
        psum[val[i]]%=MOD;
    }

    cout<<dp[0]<<"\n";

    return 0;
}


Measured memory_bytes: 5364
struct B{int w,s,v;}A[1111];
long dp[22222],ans;
comp(a,b)struct B*a,*b;{ans=a->w+a->s-b->w-b->s;}
n,i,j;
main(){
	scanf("%d",&n);
	for(;~scanf("%ld%ld%ld",&A[i].w,&A[i].s,&A[i].v);i++);
	qsort(A,n,sizeof(struct B),comp);
	for(i=0;i<n;i++)
	{
		for(j=A[i].s;j>=0;j--)ans=fmax(ans,dp[j+A[i].w]=fmax(dp[j+A[i].w],dp[j]+A[i].v));
	}
	printf("%ld",ans);
}


Measured memory_bytes: 380
#include <stdio.h>

int main(){
	int N;
	int p[10];
	int max=0;
	int sum=0;
	int memory=0;
	scanf("%d",&N);
	for(int i = 0; i < N; i++){
		scanf("%d",&p[i]);
		if(i == 0) max = p[0];
		if(i != 0){
			if(max < p[i]) {
				max = p[i];
				memory = i;
			}
		}
	}
	max = max/2;
	for(int i = 0; i < N ; i++){
		if(i != memory) sum += p[i];
		if(i == memory) sum += max;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x1 = scanner.nextInt();
		int y1 = scanner.nextInt();
		int x2 = scanner.nextInt();
		int y2 = scanner.nextInt();
		
		//x1,y1,x2,y2
		//System.out.println(x1 + " " + y1 + " " + x2 + " " + y2);
		
		int x3 = x2 + y1 - y2;
		int y3 = y2 - x1 + x2;
		int x4 = x1 + y1 - y2;
		int y4 = y1 - x1 + x2;
		
		//x3,y3,x4,y4
		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
	}
}

Measured memory_bytes: 22612
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n, h;
  cin >> h >> n;
  vector<int> a(n);
  for (int i = 0; i<n; i++){
    cin >> a[i];
    h -= a[i];
  }
  if(h<=0){
    cout << "Yes" << "\n";
  }else{
    cout << "No" << "\n";
  }
  return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  ll ans = (k % 2 == 0) ? a - b : b - a;

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

Measured memory_bytes: 256
LGE = 20
SML = 19
FUTU = 195
URUU = 200
YEAR3 = 590

def main():
    howmany = int(input())

    for i in range(howmany):
        daycount = 0
        
        dataset = input()
        dataset = dataset.split(" ")
        
        for j in range(len(dataset)):
            dataset[j] = int(dataset[j])
        #print("-------------------------------------")
        #print("data::")
        #print(dataset)
        daycount += totopmonth(dataset)
        #print("to the top of month")
        #print(daycount)
        #print("date::")
        #print(dataset)
        #print("")
        
        if dataset[0] == 1000:
            print(daycount)
        else:
            daycount += totopyear(dataset)
            #print("to the top of year")
            #print(daycount)
            #print("date::")
            #print(dataset)
            #print("")
            
            if dataset[0] == 1000:
                print(daycount)
            else:
                daycount += totheend(dataset)
                print(daycount)
                

def totopmonth(array):
    count = 0
    
    if array[2] == 1:
        return count
    elif array[0] % 3 != 0:
        if array[1] % 2 == 1:
            count = LGE - array[2] + 1
            array[2] = 1
            array[1] += 1
        else:
            count = SML - array[2] + 1
            array[2] = 1
            array[1] += 1

    else:
        count = LGE - array[2] + 1
        array[2] = 1
        array[1] += 1

    if array[1] == 11:
        array[1] = 1
        array[0] += 1
        
    return count 
        
def totopyear(array):
    count = 0
    if array[1] == 1:
        return count
    elif array[0] % 3 != 0:
        if array[1] % 2 == 1:
            count = (10 - array[1] + 1) // 2 * (LGE + SML)
            array[1] = 1
            array[0] += 1
        else:
            count = (11 - array[1] + 1) // 2 * (LGE + SML) - LGE
            array[1] = 1
            array[0] += 1
    else:
        count = (10 - array[1] + 1) * LGE
        array[1] = 1
        array[0] += 1
    return count

def totheend(array):
    count = 0
    if array[0] % 3 == 0:
        count = (999 - array[0]) // 3 * YEAR3 + URUU
        return count
    elif array[0] % 3 == 1:
        count = (999 - array[0]) // 3 * YEAR3 + YEAR3
        return count
    else:
        count = (999 - array[0]) // 3 * YEAR3 + URUU + FUTU
        return count
main()



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

int main()
{
    int a,b,c;
    cin>> a>> b >> c;
    if(a==b){
        if(a!=c)
            cout<< c << endl;
    }
    else if(a==c){
        if(a!=b)
            cout<< b << endl;
    }
    else if(b==c){
        if(b!=a)
            cout<< a << endl;
    }
    else if(b==a){
        if(b!=c)
            cout<< c << endl;
    }
    else if(c==a){
        if(c!=b)
            cout<< b << endl;
    }
    else if(c==b){
        if(c!=a)
            cout<< a << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
const int MOD=1e9+7;
typedef long long ll;
ll a[N];
int n,m;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	int zh=0,fs=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>0) zh++;
		else fs++;
	}
	ll sum=1;
	if((m&1)&&(zh==0))
	{
		sort(a+1,a+1+n,greater<int>());
		
		for(int i=1;i<=m;i++) sum=(sum*a[i])%MOD;
	//	cout<<sum<<endl;
	}
	else
	{
		sort(a+1,a+1+n,greater<int>());
		int l=1,r=n;
		while(m>0)
		{
			if(m&1) sum=(sum*a[l])%MOD,l++,m--;
			if(m>=2)
			{
				if(a[l]*a[l+1]>=a[r]*a[r-1]) 
				{
					sum=(sum*a[l]%MOD*a[l+1])%MOD;
					l+=2;
					m-=2;
				}
				else
				{
					sum=(sum*a[r]%MOD*a[r-1])%MOD;
					r-=2;
					m-=2;
					
				}
			}
			
		}
	}
	cout<<(sum%MOD+MOD)%MOD<<endl;
}

Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}



int main() {
ll N;
  ll K;
    cin >>N>>K;
  vvl vec(K);
  rep(i,K) {
ll a;
    cin >>a;
    rep(j,a) {
      ll b;
      cin >>b;
vec.at(i).push_back(b-1);
    }
  }
  
  
  
  
  vl vect(N);
  rep(i,N) {
vect.at(i)=0;
  }
rep(i,K) {
ll c=vec.at(i).size();
  rep(j,c) {
vect.at(vec.at(i).at(j))=1;
  }
}
  
  ll sum=0;
  rep(i,N) {
if(vect.at(i)==0) {
sum++;
}

  }

  
  cout<<sum<<endl;
  

}
  
  
  
  

Measured memory_bytes: 3624
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<climits>

using namespace std;

int main() {
	int n, k; cin >> n >> k;
	int h[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int dp[n];
	for (int i = 0; i < n; i++) {
		dp[i] = INT_MAX;
	}
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n&&j < i + k + 1; j++) {
			dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
		}
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

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



int main(){
    int N, A; std::cin >> N;
    long long ans(0);
    std::unordered_map<int, int> mp;
    for(int i(0); i < N; ++i){
        std::cin >> A;
        ans += mp[A-i];
        ++mp[-i-A];
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 18552
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define N_MAX 310
#define INF 500000000000

int H[N_MAX];
long long int memo[N_MAX][N_MAX];

long long int func(int last, int cnt)
{
	if (1 == cnt){
		return H[last];
	}
	if (0 == last){
		return INF;
	}
	if (-1 != memo[last][cnt]){
		return memo[last][cnt];
	}

	long long int ret = INF;
	for (int i = 0; i < last; i++){
		ret = min(ret, func(i, cnt - 1) + max(0, H[last] - H[i]));
	}

	return memo[last][cnt] = ret;
}

void solv()
{
	int N, K; scanf("%d%d", &N, &K);

	for (int i = 0; i < N; i++){
		scanf("%d", H + i);
	}

	for (int i = 0; i < N; i++){
		fill(memo[i], memo[i] + N + 1 , -1);
	}

	long long int ret = INF;
	if (N == K){
		ret = 0;
	}
	else{
		for (int i = 0; i < N; i++){
			ret = min(ret, func(i, N - K));
		}
	}


	printf("%lld", ret);

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 896
s = input()

def palindrome(s):
    l = len(s)
    reverse_half_s_left = s[:l//2]
    reverse_half_s_right = s[(l//2)+1:]
    if reverse_half_s_left != reverse_half_s_right[::-1]: return False
    if reverse_half_s_left != reverse_half_s_right: return False
    return True

print ('Yes' if (palindrome(s)) else 'No')

Measured memory_bytes: 3188
loop do
  w, h = gets.chomp.split(' ').map(&:to_i)
  exit(0) if w == 0 && h == 0
  c = []
  count = 0
  h.times do
    c << gets.chomp.split(' ').map(&:to_i)
  end

  while c.any? { |line| line.include?(1) }
    stack = []

    c.each_with_index do |line, i|
      next unless line.include?(1)
      stack = [[i, line.index(1)]]
      count += 1
      break
    end

    until stack.empty?
      i, j = stack.pop
      next if c[i][j] == 0

      c[i][j] = 0

      stack << [i + 1, j] if i + 1 < h && c[i + 1][j] == 1
      stack << [i - 1, j] if i - 1 >= 0 && c[i - 1][j] == 1
      stack << [i, j + 1] if j + 1 < w && c[i][j + 1] == 1
      stack << [i, j - 1] if j - 1 >= 0 && c[i][j - 1] == 1

      stack << [i + 1, j - 1] if i + 1 < h && j - 1 >= 0 && c[i + 1][j - 1] == 1
      stack << [i - 1, j - 1] if i - 1 >= 0 && j - 1 >= 0 && c[i - 1][j - 1] == 1
      stack << [i + 1, j + 1] if i + 1 < h && j + 1 < w && c[i + 1][j + 1] == 1
      stack << [i - 1, j + 1] if i - 1 >= 0 && j + 1 < w && c[i - 1][j + 1] == 1
    end
  end
  puts count
end


Measured memory_bytes: 6976
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    string S; cin >> S;

    int ans = 0;
    FOR(i,1,N-1) {
        string ls = S.substr(0, i);
        string rs = S.substr(i);
        set<char> lst, rst;
        for (char c : ls) lst.insert(c);
        for (char c : rs) rst.insert(c);

        int cnt = 0;
        for(char c ='a'; c<='z'; c++) {
            if (lst.count(c) > 0 && rst.count(c) > 0) cnt++;
        }
        ans = max(ans, cnt);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    int cnt = 1;
    foreach (a; A) {
        if (cnt == a) {
            cnt += 1;
        }
    }

    int ans = N - cnt + 1;


    writeln(cnt == 1 ? -1 : ans);
}

Measured memory_bytes: 11408
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef pair<LL,LL> PLL;
typedef double LD;
#define FI first
#define SE second
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define ZERO(m) memset(m,0,sizeof(m))
#define ALL(x) (x).begin(), (x).end()
#define MINUS(m) memset(m,-1,sizeof(m))
#define RALL(x) (x).rbegin(), (x).rend()
#define FOR(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define FORE(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((LD)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif

	string s;
	cin >> s;
	int k;
	cin >> k;
	LL v = 0;
	int ls = -1;
	string t = s;
	int n = s.length();
	if(n==1){
		cout << k/2 << endl;
		return 0;
	}
	LL org = 0;
	FOR1(i,n-1){
		if(s[i]==s[i-1] && t[i-1]!='1'){
			t[i] = '1';
			org++;
		}
	}
	LL o = 0;
	t = s;
	FORD(i,n-1){
		if(s[i]==s[i+1] && t[i+1]!='1'){
			o++;
			t[i] = '1';
		}
	}
	t = s;
	umin(org,o);
	cerr << org << endl;
	if(s[0]==s[n-1]){
		LL f = n*k;
		t[0] = '1';
		LL c = 1;
		FOR1(i,n-1){
			if(s[i]==s[i-1] && t[i-1]!='1'){
				c++;
				t[i] = '1';
			}
		}
		f = (k-1)*c + org;
		t = s;
		t[n-1] = '1';
		c = 1;
		FORD(i,n-1){
			if(s[i]==s[i+1] && t[i+1]!='1'){
				c++;
				t[i] = '1';
			}
		}	
		umin(f,org+(k-1)*c);
		c = 2;
		t = s;
		t[0] = t[n-1] = '1';
		FOR1(i,n-2){
			if(s[i]==s[i-1] && t[i-1]!='1' && t[i]!='1'){
				c++;
				t[i] = '1';
			}
		}
		cerr << c << endl;
		umin(f,(k+1)/2*org+k/2*c);
		cout << f << endl;
	}else cout << org*k << endl;

  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

Measured memory_bytes: 256
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

string s,t;
int n,m;

int solve(){
	int ans = inf;
	fo(i,n-m+1){
		int cnt = 0;
		fo(j,m){
			if(s[i+j]!=t[j]) cnt++;
		}
		cerr << "cnt:" << cnt << endl;
		ans=min(cnt,ans);
	}
	return ans;
}

int32_t main(){
    NINJA;

	cin >> s >> t;
	n = sz(s);
	m = sz(t);

	cout << solve() << endl;
    
    return 0;
}



Measured memory_bytes: 3684