akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
	int n,a,b;
	cin >> n >> a >> b;
	int ans=0;
	rep(i,n+1){
		int j=i,num=0;
		while(j>0){
			num+=j%10;
			j/=10;
		}
		if(num>=a&&num<=b) ans+=i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    string s; cin>>s;
    int K; cin>> K;
    vector<string> A;
    int N = s.size();
    for(int k=1; k<=K; k++){
        for(int i=0; i<N; i++){
            if(i+k<=N) A.emplace_back(s.substr(i, k));
        }
    }
    sort(ALL(A));
    A.erase(unique(ALL(A)), A.end());
    cout << A[K-1] << endl;
    return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

int main(){

int a,b;
cin>>a>>b;

int dif = b-a;

int bt=0;

for(int i=1;i<=dif;i++){
  bt +=i;
}

cout<<bt-b<<endl;

  return 0;
}
  


Measured memory_bytes: 256
from sys import stdin,setrecursionlimit
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = [0]*(n+1)
for i in li:
    lin[i] += 1
liv = [0]*(n+1)
point = 0
for j,k in enumerate(lin):
    point += k*(k-1)//2
    liv[j] += k*(k-1)//2
for i in li:
    print(point-liv[i]+(lin[i]-1)*(lin[i]-2)//2)

Measured memory_bytes: 26140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int d, g; cin >> d >> g;
    vector<int> p(d), c(d);
    rep(i, d) cin >> p[i] >> c[i];

    int ans = 1001;
    for (ll i=0; i<1LL<<d; i++) { //ビットが立ってる問題を全解き
        int n = 0; //上位から見て最初にビットが立ってない問題
        int score = 0;
        int tmp = 0;
        rep(j, d) {
            if (i>>j & 1) {
                score += 100*(j+1)*p[j] + c[j];
                tmp += p[j];
            }
            else {
                n = j;
            }
        }

        if (score >= g) {
            ans = min(ans, tmp);
            continue;
        }

        rep(j, p[n]) {
            score += 100*(n+1);
            if (j == p[n]-1) score += c[n];
            tmp++;
            if (score >= g) {
                ans = min(ans, tmp);
                break;
            }
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>

using namespace std;
typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

vector<int> E[110000];
long long int val[110000];
P lim[110000];

P check1(int pos, int pre){
	long long int n1 = -INF, n2 = INF;
	long long int rem = -1;
	for(int to : E[pos]){
		if(to == pre){
			continue;
		}
		P ret = check1(to, pos);
		if(ret.second == INF){
			continue;
		}
		ret.first -= 1;
		ret.second += 1;

		if(rem == -1){
			rem = ret.second % 2;
		}else if(rem != ret.second % 2){
			return P(INF, -INF);
		}
		n1 = max(n1, ret.first);
		n2 = min(n2, ret.second);
	}
	if(val[pos] != INF){
		if(n2 != INF && val[pos] % 2 != n2 % 2){
			return P(INF, -INF);
		}
		n1 = max(n1, val[pos]);
		n2 = min(n2, val[pos]);
	}
	if(n1 > n2){
		return P(INF, -INF);
	}
	lim[pos] = P(n1, n2);
	return P(n1, n2);
}

void check2(int pos, int pre, long long int num){
	lim[pos].second = min(lim[pos].second, num);
	for(int to : E[pos]){
		if(to == pre){
			continue;
		}
		check2(to, pos, lim[pos].second + 1);
	}
}

int main(){
	int N;
	cin >> N;
	for(int i = 0; i < N - 1; i++){
		int A, B;
		cin >> A >> B;
		E[A].push_back(B);
		E[B].push_back(A);
	}
	for(int i = 0; i <= N; i++){
		val[i] = INF;
		lim[i] = P(INF, -INF);
	}
	int K;
	cin >> K;
	for(int i = 0; i < K; i++){
		int v, p;
		cin >> v >> p;
		val[v] = p;
	}
	P ret = check1(1, -1);
	if(ret.second == -INF){
		cout << "No" << endl;
		return 0;
	}
	check2(1, -1, lim[1].second);
	cout << "Yes" << endl;
	for(int i = 1; i <= N; i++){
		cout << lim[i].second << endl;
	}
  return 0;
}


Measured memory_bytes: 16896
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
#define mx 100001
using namespace std;
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define d double
void fun(vvi&adj,int v,int par,vvl&dp){
	for(int nbs:adj[v]){
		if(nbs!=par){
			fun(adj,nbs,v,dp);
			dp[v][0]=dp[v][0]*dp[nbs][1]%mod;
			dp[v][1]=dp[v][1]*(dp[nbs][0]+dp[nbs][1])%mod;
		}
	}
}
void solve(){
	ll n;
	cin>>n;
	vvi adj(n);
	rep(i,0,n-1){
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	int root;
	int val=-1;
	vvl dp(n,vl(2,1));
	for(int i=0;i<n;i++){
		if(adj[i].size()>val) val=adj[i].size(),root=i;
	}
	fun(adj,root,-1,dp);
	cout<<(dp[root][0]+dp[root][1])%mod;
 
}
int32_t main(){
int t=1;
//cin>>t;
while(t--){
	solve();
}
}

Measured memory_bytes: 19584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k;
    double x;
    double ans=0,now,prev;
    cin>>n>>k;
    vector<double> p(n);
    for(int i=0;i<n;i++){
        cin>>x;
        p[i]=(x+1.0)/2.0;
    }
    for(int i=0;i<k;i++){
        now+=p[i];
    }
    ans = now;
    for(int i=1;i+k-1<n;i++){
        prev = now;
        now-=p[i-1];
        now+=p[i+k-1];
        ans=max(ans,now);
    }
    cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, n,m , M, K,a;

vector<ll> v,w;
int main(){
    string str;
  	cin >> N;
    cin >> str;
    int ans =0;
    for(int i = 0; i < N -2; ++i){
        if(str[i] == 'A' && str[i+1] == 'B' && str[i +2] == 'C') {
            ans +=1;        }
    }
    cout << ans ;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <fstream>
#define ni(n) scanf("%d", &n)
#define nl(n) scanf("%lld", &n)
#define nai(a,n) for (int i = 0; i < (n); i++) ni((a)[i])
#define nal(a,n) for (int i = 0; i < (n); i++) nl((a)[i])
#define case(t) printf("Case #%d: ", (t))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e2 + 5;
const double eps = 1e-9;
using namespace std;
char arr[MAXN][MAXN];

int main()
{
    int a, b;
    ni(a), ni(b);
    int x = 0, y = 0;
    for (int i = 1; i < b; i++)
    {
        arr[x][y] = '#';
        arr[x + 1][y] = '.';
        arr[x][y + 1] = '.';
        arr[x + 1][y + 1] = '.';
        x += 2;
        if (x >= 100)
            x = 0, y += 2;
    }
    for (int i = x; i < 100; i++)
        arr[i][y] = arr[i][y + 1] = '.';
    x = 0, y += 2;
    for (int i = x; i < 100; i++)
        arr[i][y] = '#';
    y++;
    for (int i = 1; i < a; i++)
    {
        arr[x][y] = '.';
        arr[x + 1][y] = '#';
        arr[x][y + 1] = '#';
        arr[x + 1][y + 1] = '#';
        x += 2;
        if (x >= 100)
            x = 0, y += 2;
    }
    for (int i = x; i < 100; i++)
        arr[i][y] = arr[i][y + 1] = '#';
    cout << 100 << " " << y + 2 << "\n";
    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j <= y + 1; j++)
            cout << arr[i][j];
            cout << "\n";
    }
    return 0;
}


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

int main()
{
  int a,b,c,d;
  cin>>a;
  cin>>b;
  cin>>c;
  
  d=a-b;
  if(c<=d)
    cout<<0;
  else
  {
   cout<<c-d;
  }
  
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

void solve(){
  ll N, M, V, P;
  cin >> N >> M >> V >> P;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());
  ll ok = N - P;
  ll ng = -1;
  while(ok - ng > 1){
    ll mid = (ok + ng) / 2;
    if(A[mid] + M < A[N-P]){
      ng = mid;
      continue;
    }
    if(mid + P - 1 >= V-1){
      ok = mid;
      continue;
    }



    ll rest = V - mid - P;
    ll X = A[mid] + M;
    vector<ll> B;
    for(ll i = mid + 1; i <= N-P; i++){
      B.pb(X-A[i]);
    }
    sort(B.begin(), B.end());//足せる回数


    ll point = rest * M;
    revrep(i, B.size()){
      point -= min(point, min(M, B[i]));
    }
    if(point == 0){
      ok = mid;
    }else{
      ng = mid;
    }
  }
  cout << N - ok << endl;
}

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


Measured memory_bytes: 2844
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(),greater<int>());
#define ALL(X) (X).begin(),(X).end()
#define INF 999999999
#define M_PI 3.14159265358979323846
#define MOD 1000000007

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int main()
{
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif

    fast_io();
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A,F;
    A = fetch_vec<ll>(N);
    F = fetch_vec<ll>(N);
    VSORT(A);
    VRSORT(F);
    ll ans=0;

    ll l=0,r=1e12;
    while(l<r){
        ll x = (l+r)/2;
        ll need=0;
        FOR(i,0,N) need+=max(0LL,A[i]-x/F[i]);
        if(need<=K) r=x;
        else l=x+1;
    }

    cout << l << endl;

}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define ll long long 
#define P pair<int,int>
#define PP pair<P,int>
using namespace std;
int inf = 1ll << 30;

int main(){
    int x, y;
    cin >> x >> y;
    if(y%2 == 1){
        cout << "No" << endl;
        return 0;
    }

    if(x*2 <= y && y <= x*4){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=100010;

ll n,W;
ll val[110],w[110];

ll dp[101][100001];

ll func(ll idx,ll left)
{
    if(left<0){return INT_MIN;}
    if(idx<0){return 0;}
    if(dp[idx][left]==-1)
    {dp[idx][left]=max(func(idx-1,left-w[idx])+val[idx],func(idx-1,left));}
    return dp[idx][left];
}

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

    cin>>n>>W;
    for(ll i=0;i<n;++i){
        cin>>w[i]>>val[i];
    }
    memset(dp,-1,sizeof(dp));
    ll ans=func(n-1,W);
    cout<<ans<<endl;

    return (0);
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;

int main(){
  string s,t;
  cin >> s;
  t=s;
  int n=s.size();
  reverse(s.begin(),s.end());
  int cnt=0;
  rep(i,n){
    if(t[i]!=s[i]) cnt++;
  }
  cout<<cnt/2<<endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, C;
  cin >> n >> C;
  int d[C][C];
  vector<map<int, int>> vm(3);
  rep(i, 0, C) rep(j, 0, C) cin >> d[i][j];
  rep(i, 1, n + 1) rep(j, 1, n + 1) {
    int c;
    cin >> c;
    c--;
    vm[(i + j) % 3][c]++;
  }

  map<int, int> zero = vm[0], one = vm[1], two = vm[2];
  ll ans = 1e18;
  rep(i, 0, C) {
    ll sumzero = 0;
    for (auto m : zero)
      sumzero += d[m.first][i] * m.second;
    rep(j, 0, C) {
      ll sumone = 0;
      if (i == j)
        continue;
      for (auto m : one)
        sumone += d[m.first][j] * m.second;
      rep(k, 0, C) {
        ll sumtwo = 0;
        if (i == k || j == k)
          continue;
        for (auto m : two)
          sumtwo += d[m.first][k] * m.second;
        chmin(ans, sumzero + sumone + sumtwo);
      }
    }
  }
  cout << ans << endl;
}


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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

string latte="^>v<";

int H,W;
string fld[55];

int dist[55][55][4][4];


const int INF=1001001001;
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};

int dy_h[4][4]={
{-1,-1,0,1},
{0,1,1,1},
{1,1,0,-1},
{0,-1,-1,-1}
};

int dx_h[4][4]={
{0,1,1,1},
{1,1,0,-1},
{0,-1,-1,-1},
{-1,-1,0,1}
};
int gy,gx;
bool vis[55][55][4][4];
int calc(int y,int x,int d,int h){
    memset(vis,0,sizeof(vis));

    while(true){
        if(vis[y][x][d][h]){
            return INF;
        }
        vis[y][x][d][h]=true;
        if(fld[y][x]=='G')break;

        if(h==3){
            if(fld[y+dy[(d+1)%4]][x+dx[(d+1)%4]]=='#'){
                h=2;
            }
            else{
                d=(d+1)%4;
                h=1;
            }
        }
        else if(h==2){
            if(fld[y+dy[d]][x+dx[d]]=='#'){
                d=(d+3)%4;
            }
            else{
                y+=dy[d];x+=dx[d];
                h=3;
            }
        }
        else if(h==1){
            if(fld[y+dy[d]][x+dx[d]]=='#'){
                d=(d+3)%4;
                h=2;
            }
            else{
                y+=dy[d];x+=dx[d];
                h=2;
            }
        }
        else{
            d=(d+1)%4;
            h=2;
        }
    }

    int cnt=0;
    rep(i,H)rep(j,W){
        int f=false;
        rep(k,4)rep(l,4)f|=vis[i][j][k][l];
        cnt+=f;
    }
    return cnt;
}

signed main(){
    scanf("%lld%lld",&H,&W);
    int sy,sx,sd;

    rep(i,H){
        cin>>fld[i+1];
        fld[i+1]="#"+fld[i+1]+"#";
    }
    fld[0]=fld[H+1]=string(W+2,'#');
    H+=2;W+=2;

    rep(i,H)rep(j,W){
        if(fld[i][j]=='G'){
            gy=i;gx=j;
        }
        else if(fld[i][j]!='.'&&fld[i][j]!='#'){
            sy=i;sx=j;
            sd=find(all(latte),fld[i][j])-latte.begin();
        }
    }

    int ans=INF;
    rep(i,4){
        int hy=sy+dy_h[sd][i],hx=sx+dx_h[sd][i];
        if(fld[hy][hx]=='#')chmin(ans,calc(sy,sx,sd,i));
    }
    if(ans==INF)cout<<-1<<endl;
    else cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 3336
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
       n: u32,
       m: u32,
    }
    println!("{}", (n-1) * (m-1));
}


Measured memory_bytes: 4352
import java.util.*;

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

        System.out.println(String.valueOf(calculation(a, b, h)));

    }

    public static int calculation(int a, int b, int h) {
        return (a + b) * h / 2;
    }


}

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

namespace ABC177B
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int SL = S.Length;
            int TL = T.Length;
            int ans = 1000;
            for(int i = 0; i < SL - TL + 1; i++)
            {
                int temp = 0;
                for(int j = i; j < i+TL; j++)
                {
                    if (T[j-i] != S[j])
                    {
                        temp += 1;
                    }
                }
                if (temp < ans)
                {
                    ans = temp;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 25952
#include<algorithm>
#include<iostream>
#include<string.h>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
using namespace std;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
const double PI=acos(-1.0);
typedef long long ll;
const int maxn=100010;
int tree[maxn];
int Find(int x)
{
    if(tree[x]==x)
        return x;
    return Find(tree[x]);
}
int main()
{
    int n,m,id,i;
    char com[10];
    ll ans;

    while(scanf("%d%d",&n,&m),n||m)
    {
        tree[1]=1;
        ans=0;
        for(i=2;i<=n;i++)
            scanf("%d",&tree[i]);
        for(i=0;i<m;i++)
        {
            scanf("%s%d",com,&id);
            if(com[0]=='M')
                tree[id]=id;
            else
                ans+=Find(id);
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1580
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int N;
	cin >> N;
	
	int digit = log10(N) + 1;
	int x[10][10] = {};
	for(int i=1; i<=N; i++){
		string s = to_string(i);
		x[(int)(s[0]-'0')][(int)(s[s.size()-1]-'0')]++;
	}
	
	ll ans=0;
	REP(i,10){
		REP(j,10){
			if(i*j==0) continue;
			ans += x[i][j]*x[j][i];
		}
	}

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

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int a, b, c, d;
    scan(a, b, c, d);
    int l = a + b;
    int r = c + d;
    if (l > r)
        print("Left");
    else if (l == r)
        print("Balanced");
    else
        print("Right");

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      (int)1e9+7
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;

int main(){
	int m,d;
	cin>>m>>d;
	
	llong ans=0;
	for(int i=4;i<=m;++i){
		for(int j=22;j<=d;++j){
			if(j%10!=1){
				int d=j%10;
				int dd=j/10;
				if(d*dd==i) ans++;
			}
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

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

int N;
int M;
int t[200001];
int b[200001];
int main(){
	cin >> N >> M;
	for(int i = 0; i < N; i++){
		t[i] = 0;
		b[i] = 0;
	}

	vector<pair<int, int> > arms(M);
	for(int i = 0; i < M; i++){
		int a,b;
		cin >> a >> b;
		arms[i] = {a, b};
	}

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

	for(auto arm : arms){
		t[arm.second] = t[arm.second - 1] + 1;
		b[arm.second - 1] = b[arm.second] + 1;
	}

	for(int i = 0; i < N; i++){
		if(i) cout << " ";
		cout << (t[i] + b[i] + 1);
	}
	cout << endl;
}

Measured memory_bytes: 5212
import sys
from itertools import accumulate
q = int(input())
ls = []

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime

pr = primes(10 ** 5)
pr = [j and pr[i*2-1] for i, j in enumerate(pr[:5*10**4+1])]
new_pr = [i for i in accumulate(pr)]

for i in range(q):
    l, r = [int(i) for i in sys.stdin.readline().split()]
    print(new_pr[(r+1)//2] - new_pr[(l-1)//2])

Measured memory_bytes: 54232
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int inf = 1<<30;
const ll mod = 1000000007;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

int main () {
  int n, m; cin >> n >> m;
  vvi jobs(m);

  rep(i,n) {
    int a, b; cin >> a >> b;
    if (a > m) continue;
    jobs[m-a].push_back(b);
  }

  priority_queue<int> q;
  int ans = 0;
  for (int i = m-1; i >= 0; --i) {
    for (int b : jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }

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

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

int main(){
	char a, b;
	cin >> a >> b;

	if(a=='H' && b=='H'){ cout << 'H' << endl; }
	else if(a=='D' && b=='D'){ cout << 'H' << endl; }
	else { cout << 'D' << endl; }

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        int[] t = new int[N];
        int[] x = new int[N];
        int[] y = new int[N];
        for (int i = 0; i < N; ++i) {
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        System.out.println(solve(t, x, y) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(int[] t, int[] x, int[] y) {
        return IntStream.range(0, t.length).allMatch(i -> {
            int distance = Math.abs(x[i] - (i == 0 ? 0 : x[i - 1])) + Math.abs(y[i] - (i == 0 ? 0 : y[i - 1]));
            int time = t[i] - (i == 0 ? 0 : t[i - 1]);

            return distance <= time && (time - distance) % 2 == 0;
        });
    }
}

Measured memory_bytes: 93408
N=int(input())
l=map(int,input().split())
h=dict()
m1=0
m2=0
for i in l:
        if(i not in h):
                h.update({i:1})
        else:
                del h[i]
                if(i>m1):
                        m2=m1
                        m1=i
                else:
                        m2=max(m2,i)
print(m1*m2)

Measured memory_bytes: 23848
#include <stdio.h>
#include <stdlib.h>
int compara(void const *a, void const *b){
	char *x = (char *)a, *y = (char *)b;
	int i = 0, sdxvd;
	while(x[i] != '\0' && y[i] != '\0'){
		sdxvd = x[i] - y[i];
		if(sdxvd) return sdxvd;
		i++;
	}
	sdxvd = x[i] - y[i];
	if(sdxvd) return sdxvd;
	return 0;
}

int main(){
	char stringe[100][111];
	int n, l;
	scanf("%d%d", &n, &l);
	for(int i = 0; i < n; ++i) scanf(" %s", stringe[i]);
	qsort(stringe, n, sizeof(stringe[0]), compara);
	for(int i = 0; i < n; ++i){
		int z = 0;
		while(stringe[i][z] != '\0') printf("%c", stringe[i][z++]);
	}
	printf("\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vector<string> S(N);
        rep(i, 0, N) cin >> S[i];
        unordered_map<char, ll> cnt;
        cnt['M'] = 0;
        cnt['A'] = 0;
        cnt['R'] = 0;
        cnt['C'] = 0;
        cnt['H'] = 0;
        rep(i, 0, N) {
                if (S[i][0] == 'M') ++cnt['M'];
                if (S[i][0] == 'A') ++cnt['A'];
                if (S[i][0] == 'R') ++cnt['R'];
                if (S[i][0] == 'C') ++cnt['C'];
                if (S[i][0] == 'H') ++cnt['H'];                
        }       
        vll freq{cnt['M'], cnt['A'], cnt['R'], cnt['C'], cnt['H']};

        ll ans = 0;
        rep(i, 0, 5) {
                rep(j, i+1, 5) {
                        rep(k, j+1, 5) {
                                ans += freq[i] * freq[j] * freq[k];
                        }
                }
        }
        cout << ans << endl;
}

Measured memory_bytes: 6268
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let a = i.read_vec::<usize>(n);

    writeln!(o, "{}", solve(a)).unwrap();
}
fn counts(a: &[usize]) -> Vec<usize> {
    let mut ss = vec![[None; 16]; a.len()];
    let mut rs = Vec::with_capacity(a.len() + 1);
    let mut cs = Vec::with_capacity(a.len());

    rs.push(0);
    rs.push(0);

    for i in 1..a.len() {
        cs.clear();
        let mut c = 0;
        let mut j = i;
        while j > 0 {
            let mut c_ext = 0;
            if c >= 16 {
                c_ext = c - 16 + 1;
                c -= c_ext;
            }

            if let Some(c_j) = ss[j][c] {
                c = c_j + c_ext * (j + 1);
                break;
            }
            cs.push((c, c_ext));

            let log = (a[j - 1] as f64 / a[j] as f64).log(4.0);
            if log >= 1.0 {
                c -= std::cmp::min(c, log as usize);
            }
            if log < 0.0 {
                c += (-log.floor()) as usize;
            }
            j -= 1;
        }
        while let Some((c_j, c_j_ext)) = cs.pop() {
            j += 1;
            ss[j][c_j] = Some(c + c_j);
            c += c_j + c_j_ext * (j + 1);
        }
        rs.push(c);
    }
    rs
}
fn solve(mut a: Vec<usize>) -> usize {
    let cs0 = counts(&a);
    a.reverse();
    let cs1 = counts(&a);

    (0..a.len())
        .map(|x| cs0[x] * 2 + x + cs1[a.len() - x] * 2)
        .min()
        .unwrap()
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


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

if N == 3:
    print("2 5 63")
    exit()

MAX = 30000
v2, v3, v6 = [], [], []

for x in range(2, MAX+1):
    if x%6 == 0:
        v6.append(x)
    elif x%3 == 0:
        v3.append(x)
    elif x%2 == 0:
        v2.append(x)

ans = []
j = 0

while j < len(v2)//2 and N > 3:
    ans.append(v2[j*2])
    ans.append(v2[j*2+1])
    j += 1
    N -= 2

j = 0
while j < len(v3)//2 and N > 1:
    ans.append(v3[j*2])
    ans.append(v3[j*2+1])
    j += 1
    N -= 2

for j in range(N):
    ans.append(v6[j])


print(" ".join(map(str, ans)))

Measured memory_bytes: 5468
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];

  map<ll,ll> l;

  rep(i,n)
  {
    ll buf = i + a[i];
    l[buf]++;
  }

  ll ans = 0;

  rep(i,n)
  {
    ll buf = i - a[i];
    if(l[buf] > 0)
      ans += l[buf];
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 27448
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    private final int A, B, C;

    AtCoder(FastScanner sc) {
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();

    }

    void solve(PrintWriter out) {
        int ans = C - (A - B);
        out.println(ans <= 0 ? 0 : ans);
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;

int main(){
	string s, t;
	cin >> s >> t;
	vector<int> cor(26,-1);
	vector<int> used(26, 0);

	bool flag = true;
	for (int i = 0; i < s.length(); ++i) {
		int cs = s[i] - 'a';
		int ct = t[i] - 'a';

		if (cor[cs] == -1) {
			if (used[ct] == 0) {
				cor[cs] = ct;
				used[ct] = 1;
			}
			else {
				flag = false;
			}
		}
		else if (cor[cs] != ct) {
			flag = false;
		}
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    int cx, cy, x3, y3, x4, y4;
    cx = x2 - x1;
    cy = y2 - y1;
    x4 = x1 - cy;
    y4 = y1 + cx;
    x3 = x4 + cx;
    y3 = y4 + cy;
    cout << x3 << ' ' << y3 << ' ' << x4 << ' ' <<  y4 << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String ans[] = { "Yes", "No" };
		String s = sc.next();
		int an = 0;
		sc.close();
		an = ((s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) ? 0 : 1);
		System.out.println(ans[an]);
	}
}


Measured memory_bytes: 21844
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n
    

    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]
    

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return False
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x

        return True
    

    def size(self, x):
        return -self.parents[self.root(x)]


def main():
    N, M = map(int, input().split())

    UF = UnionFind(N)
    for _ in range(M):
        A, B = map(int, input().split())
        A, B = A - 1, B - 1
        UF.unite(A, B)

    ans = 0
    for i in range(N):
        ans = max(ans, UF.size(i))

    print(ans)

main()

Measured memory_bytes: 14548
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
for i in range(N):
    if A[i]>=B[i]:
        ans+=B[i]
    else:
        a=A[i+1]
        A[i+1]=max(0,A[i+1]+A[i]-B[i])
        ans+=A[i]+(a-A[i+1])
print(ans)

Measured memory_bytes: 19116