akhauriyash/Code-Regression huggingface dataset:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998_244_353

def precompute(S):
    if np.all(S == 1):
        print(1)
        exit()
    while S[0] == 1:
        S = S[1:]
    if np.all(S == 0):
        print(1)
        exit()
    # 各 1 の左側にある 0 の個数を数える
    z = 0
    A = []
    for i, x in enumerate(S):
        if x == 0:
            z += 1
        else:
            A.append(z)
    return np.array(A, dtype=np.int64)

S, K = read().split()
S = np.array(list(S), np.int64) - ord('0')
K = int(K)
A = precompute(S)

A = precompute(S)

def main(A):
    U = 310
    # 数、消費回数、できた禁止地点
    dp = np.zeros((U, U, U), np.int64)
    dp[0, 0, 0] = 1
    for n in range(1, U):
        # 消費回数なし
        dp[n] += dp[n - 1]
        count = np.sum(A == n)
        if not count:
            continue
        tmp = np.zeros_like(dp[n])
        tmp[1:, 1:] += dp[n - 1][:-1, :-1]
        np.cumsum(tmp, axis=1, out=tmp)
        tmp %= MOD
        for k in range(1, count + 1):
            dp[n] += tmp
            tmp2 = np.zeros_like(tmp)
            tmp2[1:] = tmp[:-1]
            np.cumsum(tmp2, axis=1, out=tmp2)
            tmp = tmp2 % MOD
        dp[n, :, n + 1:] = 0
        dp[n] %= MOD
    x = dp[-1][:K + 1, :].sum() % MOD
    return x

print(main(A))

Measured memory_bytes: 261244
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define rev(a,b,c) for(int a=b;a>=c;a--)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define F first
#define S second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define get(a) cin>>a
#define nextl cout<<"\n"
#define deb(x) cout<<#x<<"="<<x<<"\n";
const ll mod = 1000000007;
const ll maxn = 1000005;
const ll mm = 1e+18;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
ll ncr(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1])%mod;
    }
    return C[k];
}
void solve()
{
    int n;
    cin>>n;
    ll mi=mm;
    ll sum=0;
    ll arr[n];
    rep0(i,n) {get(arr[i]);sum+=arr[i];}
    rep1(i,n-1) arr[i]+=arr[i-1];
    rep0(i,n-1){
        mi=min(mi,abs(sum-2*arr[i]));
    }
    pr(mi);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nextl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef  long long ll;
const int MAX_N=1e7+1;
int prime[MAX_N];
void sieveFactors() {
    for (int i = 2; i < MAX_N; ++i) {
        prime[i] = i;
    }
    for (int i = 2; i * i <= MAX_N; i += 1 + (i & 1)) {
        if (prime[i] == i) {
            for (int j = i * i; j < MAX_N; j += i)
                prime[j] = i;
        }
    }}
map<int, int> factorizeBetter(int n) {
    map<int, int> factors;
    while (n > 1) {
        factors[prime[n]]++;
        n /= prime[n];
    }
    return factors;
}

//requires sieveFactors
//O(lg n)
ll countDivisors(int n) {
    map<int, int> factors = factorizeBetter(n);
    ll cnt = 1;
    for (auto v : factors) {
        cnt *= (v.second + 1);
    }
    return cnt;
}
int main(){
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    sieveFactors();
  int n; scanf("%d",&n); ll sum=0;
  for(int i=1;i<=n;i++)
      sum+=i*countDivisors(i)*1LL;
  printf("%lld",sum);
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    ll n,k;
    cin>>n>>k;
    Array a(n);
    Array in(n,0);
    REP(i,n){
        cin>>a[i];
        a[i]--;
    }

    if(n+1<=k){
        ll ans=0;
        if(a[0]) ans++;
        cout<<ans<<en;
        return;
    }

    if(k==1){
        ll ans=0;
        REP(i,n) if(a[i]) ans++;
        cout<<ans<<en;
        return;
    }

    ll ans=0;
    if(a[0]) ans++;
    a[0]=0;

    Graph g(n);

    rep(i,1,n){
        add_edge(g,a[i],i,1,false,1);
    }

    auto dfs =[&](auto &&self, int v)->ll{
        ll d=0;
        for(auto e:g[v]){
            chmax(d,self(self,e.to)+1);
        }
        if(d==k-1){
            if(a[v]){
                a[v]=0;
                ans++;
            }
            return -1;
        }
        return d;
    };

    dfs(dfs,0);
    cout<<ans<<en;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 10752
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int saihinchi(map<int,int> m){
  int max = 0;
  int key;
  for(auto itr = m.begin();itr != m.end();itr++){
    if(itr->second > max){
      max = itr->second;
      key = itr->first;
    }
  }
  return key;
}

int main(int argc,char** argv){
  int n;
  cin >> n;
  map<int,int> v1;
  map<int,int> v2;
  for(int i = 0;i<n;i++){
    int tmp;
    cin >> tmp;
    if(i%2==0){
      if(v1.find(tmp) != v1.end()){
        v1.at(tmp)++;
      }else{
        v1[tmp] = 1;
      }
    }else{
      if(v2.find(tmp) != v2.end()){
	v2.at(tmp)++;
      }else{
	v2[tmp] = 1;
      }
    }
  }
  int i1 = saihinchi(v1);
  int s1 = v1[i1];
  int i2 = saihinchi(v2);
  int s2 = v2[i2];
  if(i1 == i2){
    v1.erase(v1.find(i1));
    v2.erase(v2.find(i2));
    int tmp1 = saihinchi(v1);
    int tmp2 = saihinchi(v2);
    if(v1[tmp1] > v2[tmp2]){
      s1 = v1[tmp1];
    }else{
      s2 = v2[tmp2];
    }
  }
  int sum = n - s1 - s2;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 7296
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
// #include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <sstream>
#include <iomanip>
using namespace std;


#define int int64_t
#define vi vector<int>
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define all(x) (x).begin(), (x).end()
#define vii vector< vector<int> >
#define rip(dp, n, m) vector< vector<int> > dp(n, vector<int>(m,0))
#define ff first
#define ss second
#define pii pair<int64_t, int64_t>
#define miv map<int, vector<int> >
#define mp make_pair
#define pb push_back
#define prr(x) cout << (#x) <<'	' << (x) << endl
#define pr(x) cout  << (x) << endl
#define f(i,n) for(i=0;i<n;i++)
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x)  __builtin_popcountll(x)
#define zrobits(x)  __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define FIO  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vi dp(200005,-1);

int rise(const vi v, int n)
{
    if(dp[n]!=-1)
      return dp[n];

    else 
    {
      dp[n] = min( rise(v,n-1)+abs(v[n]-v[n-1]), rise(v,n-2) + abs(v[n]-v[n-2]) );
      return dp[n];
    }
}


int32_t main()
{
  FIO;
  int i, n, j, m, k, l, t;
  cin >> n;
  vi v(n);
  f(i,n) cin >> v[i];
  if(n==2) cout <<  abs(v[0]-v[1]);

  else
{
    dp[1] = abs(v[0]-v[1]); 
  dp[2] = abs(v[0]-v[2]);

  for(i=3;i<=n;i++)
  {
    dp[i] = min((dp[i-1]+abs(v[i]-v[i-1])),(dp[i-2]+abs(v[i]-v[i-2])));
  }
  // cout << rise(v, n-1) << endl;
  // f(i,n) cout << dp[i] << " ";
  cout << dp[n-1];
}
}

Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
const int N=20;
char str[N],str2[N];
int len;
int main(){
	scanf("%s",str+1);
	scanf("%s",str2+1);
	len=strlen(str+1);
	if (strlen(str2+1)!=len+1) {puts("No"); return 0;}
	for (register int i=1; i<=len; ++i) if (str[i]!=str2[i]) {puts("No"); return 0;}
	puts("Yes");
return 0;
}

Measured memory_bytes: 3596
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
typedef pair<int,int> P;
typedef unsigned long long ll;
ll gcd(ll x,ll y){
    ll ma=max(x,y),mi=min(x,y),ama=ma%mi;
    if(ama==0) return mi;
    else return gcd(mi,ama);
}
ll lcm(ll x,ll y){
    ll g=gcd(x,y);
    if(g==1) return x*y;
    return g*lcm(x/g,y/g);
}
int main(){
    ll a,b;
    while(scanf("%lld %lld", &a, &b)!=EOF){
        cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;
    }
    return 0;
};

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

ll gcd(ll x,ll y){return (y==0?x:gcd(y,x%y));}

ll a[510][510];
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

bitset<10101> isp; vector<int> ps;
void init(){
   rep(i,2,10000)isp[i]=1;
   rep(i,2,10000)if(isp[i]){
      ps.push_back(i);
      for(int j=i*i;j<10000;j+=i)isp[j]=0;
   }
}

int main(){
   int n; cin>>n;
   if(n==2){
      cout<<"4 7"<<endl;
      cout<<"23 10"<<endl;
      return 0;
   }
   int idx=0;
   rep(i,0,n)rep(j,0,n)a[i][j]=1;
   init();
   for(int d=-n+(n&1);d<n;d+=2){
      rep(x,0,n)if(x+d>=0 and x+d<n){
         a[x][x+d]*=ps[idx];
      } idx++;
   }
   for(int d=0;d<=n*2-2;d+=2){
      rep(x,0,n)if(d-x>=0 and d-x<n){
         a[x][d-x]*=ps[idx];
      } idx++;
   }
   rep(i,0,n)rep(j,0,n)if((i+j)&1){
      a[i][j]=1;
      rep(k,0,4){
         int tx=i+dx[k],ty=j+dy[k];
         if(tx<0 or tx>=n or ty<0 or ty>=n)continue;
         a[i][j]=a[i][j]/gcd(a[i][j],a[tx][ty])*a[tx][ty];
      } a[i][j]++;
   }
   rep(i,0,n){
      rep(j,0,n)cout<<a[i][j]<<(j==n-1?'\n':' ');
   }
   return 0;
}

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

#define int long long

int32_t main()
{
  int n;
  cin>>n;
  
  vector <int> dp(1000000+1,0);
  
  for(int i=1;i<=1000000;i++)
  {
    for(int j=i;j<=1000000;j+=i){
    	dp[j]++;
    }
  }
  int ans=0;
  for(int i=1;i<n;i++)
  {
    ans+=dp[n-i];
  }
  
  cout<<ans;
  
  return 0;
}

Measured memory_bytes: 11096
#include<stdio.h>

int main(void){
    int ball,stage,x[100],s=0;
    scanf("%d %d",&ball,&stage);
    for (int i = 0; i < ball; i++)
    {
        scanf("%d",&x[i]);
        if(stage-x[i]>x[i])
            s+=x[i];
        else s+=stage-x[i];
    }
    
    printf("%d",2*s);
    return 0;
}

Measured memory_bytes: 128
//                          VIVEK UPADHYAY
//                         MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                           TAB -TAK CHODEGA NHI :D
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<endl ;
#define ok cout<<"ok\n" ;
typedef long long ll;
const int MAXN = 1e5 + 10 ;
const int MAX = 1e6 ;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e18 ;
ll mod = 1e9 + 7 ;
int main(){
    int  N ;
    cin >> N ;
    ll a[N] ;
    ll mx = 0 ;
    for(int i=0;i<N;i++)
        cin >> a[i] ;
    sort(a,a+N) ;
    vector<ll> p ;
    int i =1 , j = N-1 ;
    ll st = a[0] , ed = a[0] ;
    ll sum =0 ;
    while(i <= j){
        ll diff1 = max(abs(st-a[j]),abs(ed-a[j])) ;
        ll diff2 =  max(abs(st-a[i]),abs(ed-a[i])) ;
        if(diff1 > diff2){
            sum+=diff1 ;
            if(abs(st-a[j]) > abs(ed-a[j])) st = a[j] ;
            else ed = a[j] ;
            j-- ;
        }
        else {
            sum+=diff2 ;
            if(abs(st-a[i]) > abs(ed-a[i])) st = a[i] ;
            else ed = a[i] ;
            i++ ;
        }
    }
    cout<<sum<<endl;
    return 0 ;
}


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

int n;
int flags[101];

int main(){
    for(int i = 0; i < 101; i++) flags[i] = false;
    for(int x = 0; x <=  100 / 4; x++){
        for(int y = 0; y <= 100 / 7; y++){
            flags[4 * x + 7 * y] = true;
        }
    }

    cin >> n;
    if(flags[n]) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans;

    if (n > k) {
        n = n - k * ((n - k) / k);
        n = ans = n - k;
    } else {
        n = ans = k - n;
    }
    ans = min(ans, k - n);

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

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

int main()
{
  cout << fixed << setprecision(10);
  int N,K,R,S,P;
  cin >> N >> K >> R >> S >> P;
  string T;
  cin >> T;
  int sum = 0;
  rep(i,K)
  {
    if(T[i]=='r')
    {
      sum += P;
    }
    else if(T[i]=='s')
    {
      sum += R;
    }
    else
    {
      sum += S;
    }   
  }
  for(int i=K;i<N;i++)
  {
    if(T[i]=='r')
    {
      if(T[i-K]=='r')
      {
        T[i] = '0';
        continue;
      }
      else
      {
        sum += P;
      }
    }
    else if(T[i]=='s')
    {
      if(T[i-K]=='s')
      {
        T[i] = '0';
        continue;
      }
      else
      {
        sum += R;
      }
    }
    else if(T[i]=='p')
    {
      if(T[i-K]=='p')
      {
        T[i] = '0';
        continue;
      }
      else
      {
        sum += S;
      }      
    }
    
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3716
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b, c, d = na()
print(max(min(b, d) - max(a, c), 0))

Measured memory_bytes: 3444
#include<iostream>
#include<math.h>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	
	double xt;
	xt=(double)(a+b)/2;
	//cout<<xt<<endl;
	
	//int x;
	//x=(a+b)/2;
	//cout<<x<<endl;
	
	/*if(x==xt)
		cout<<x<<endl;
	else
		cout<<x+1<<endl;*/
	
	cout<<ceil(xt)<<endl;
	
	return 0;
	
	
	
}

Measured memory_bytes: 256
from collections import Counter

def prime_factrization(n):
    a=[]
    for i in range(2,int(n**0.5)+1):
        while n%i==0:
            n//=i
            a.append(i)
    if a==[]:
        a.append(n)
    else:
        if n!=1:
            a.append(n)
    return a
    
n=int(input())
if n==1:
    print(1%1000000007)
else:
    L=[]
    for i in range(2,n+1):
        L+=prime_factrization(i)
    LC=Counter(L)
    r=1
    for v in LC.values():
        r*=(v+1)
    print(r%1000000007)

Measured memory_bytes: 3316
v=[[3*M=998244353,s=1]]
`sort -nr`.lines{|e|x,d=e.split.map &:to_i
d&&(r=1
r=r%M*v.pop[1]while v[-1][0]<x+d
v<<[x,r+1])}
v.map{|_,y|s=s*y%M}
p s

Measured memory_bytes: 25076
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

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

  vector<long long> a(N);
  for(int i=0; i<N; i++)
    cin >> a[i];

  int count = 1;
  for(int i=0; i<N; i++)
    {
      if(a[i]==count)
	{
	  count++;
	}
    }
  count--;
  if(count==0)
    {
      cout << -1 << endl;
    }
  else
    cout << N-count << endl;
  


  return 0;
}



Measured memory_bytes: 1792
#include<stdio.h>

#define MAX 2000000

int n,A[MAX+1];

void maxHeapify(int);

int main(){
  int i;

  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);

  for(i=n/2;i>=1;i--)
    maxHeapify(i);
  for(i=1;i<=n;i++)
    printf(" %d",A[i]);
  printf("\n");

  return 0;
}

void maxHeapify(int i){
  int l,r,larg,tmp;

  l = 2 * i;
  r = 2 * i + 1;

  if(l <= n && A[l] > A[i])larg = l;
  else larg = i;

  if(r <= n && A[r] > A[larg])larg = r;

  if(larg != i){
    tmp = A[i];
    A[i] = A[larg];
    A[larg] = tmp;
    maxHeapify(larg);
  }

}

Measured memory_bytes: 2552
#include<cstdio>
#include<vector>


using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n, a, b;

	while(scanf("%d%d%d", &n, &a, &b)==3)
	{
		vi p(n);
		int q1=0, q2=0, q3=0;

		for(int i=0;i<n;i++)
		{
			scanf("%d", &p[i]);

			if(p[i]>b) q3++;
			else if(p[i]>a) q2++;
			else q1++;
		}
		int ans=min(q1, min(q2, q3));
		printf("%d\n", ans);
	}

	return 0;
}



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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define MAX_N 500
#define MAX_K 500
#define MAX_V 1002
#define INF 1000000000

struct edge { int to, cap, rev; };
vector<edge> G[MAX_V]; // ??°???????????£??\???????????¨???
int V;
int level[MAX_V]; // s??????????????¢
int iter[MAX_V]; // ???????????§??????????????£??????
// from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}
// s????????????????????¢???BFS??§?¨??????????
void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (int i = 0; i < G[v].size(); i++) {
            edge &e = G[v][i];
            if (e.cap > 0 && level[e.to] < 0) {
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}
// ?¢?????????????DFS??§??¢???
int dfs(int v, int t, int f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[v] < level[e.to]) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }

        }
    }
    return 0;
}
// s??????t???????????§???????±???????
int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        bfs(s);
        if (level[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        int f;
        while ((f = dfs(s, t, INF)) > 0) {
            flow += f;
        }
    }
}
void resetG(int ver){
    V = ver;
    REP(i,V)
        G[i].clear();
}

int N, K;
bool can[MAX_N][MAX_K];
void solve() {
    int s = N + K, t = s + 1;
    for (int i = 0; i < N; i++) {
        add_edge(s, i, 1);
    }
    for (int i = 0; i < K; i++) {
        add_edge(N + i, t, 1);
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < K; j++) {
            if (can[i][j]) {
                add_edge(i, N + j, 1);
            }
        }
    }
    printf("%d\n",max_flow(s,t));
}

int gcd(int a,int b){
    if(a < b){
        int c = a;
        a = b;
        b = c;
    }
    if(a % b == 0)
        return b;
    return gcd(b,a % b);
}

int inb[500],inr[500];

bool input(){
    scanf("%d%d",&N,&K);
    if(N == 0 && K == 0)
        return false;
    REP(i,N)
        scanf("%d",&inb[i]);
    REP(i,K)
        scanf("%d",&inr[i]);

    memset(can,false,sizeof(can));
    REP(i,N){
        REP(j,K){
            if(gcd(inb[i],inr[j]) > 1)
                can[i][j] = true;
        }
    }
    resetG(N + K + 2);
    return true;
}

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

Measured memory_bytes: 9452
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int points[] = new int[w + 1];
		for (int i = 1; i <= w; ++i)
			points[i] = i;
		int n = sc.nextInt();
		sc.useDelimiter(",|\n");
		for (int i = 0; i < n; ++i) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int tmp = points[a];
			points[a] = points[b];
			points[b] = tmp;
		}
		for (int i = 1; i <= w; ++i)
			System.out.println(points[i]);
	}
}


Measured memory_bytes: 26288
//#include    <bits/stdc++.h>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <cassert>
#include <iterator>
#include <complex>
#define N  1001000
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f
template<typename T> inline T max(T a,T b,T c){
    return max(a,max(b,c));
}
template<typename T> inline T min(T a,T b,T c){
    return min(a,min(b,c));
}
template<typename T> inline T max(T a,T b,T c,T d){
    return max(a,max(b,c,d));
}
template<typename T> inline T min(T a,T b,T c,T d){
    return min(a,min(b,c,d));
}
const int  dx[]={0,1,0,-1,0,1,-1,1,-1};
const int  dy[]={0,0,1,0,-1,1,-1,-1,1};
typedef long long ll;
using namespace std;
using namespace std;
/*
ll a[N];
ll C(ll n,ll m){
  if (m<n-m) m=n-m;
  ll ans=1;
  for (int i=m+1;i<=n;i++) ans*=i;
  for (int i=1;i<=n-m;i++) ans/=i;
  return ans;
}
int main(){
   ll n,maxn=0;
   scanf("%lld",&n);
   for (int i=1;i<=n;i++)
   {
       scanf("%lld",&a[i]);
       maxn=max(maxn,a[i]);
   }
   ll mid=maxn/2,x=n-mid;
   sort(a+1,a+1+n);
   for (int i=1;i<=n;i++){
      if (a[i]>=mid){
        pos1=a[i];
      }
   }
  printf("%lld %lld\n",maxn,temp);
}
/**/
ll a[N],b[N], n;
int main(){
  scanf("%lld",&n);
  for (int i=1;i<=n;i++)
  {
       scanf("%lld",&a[i]);
       b[i]=a[i];
  }
  sort(b+1,b+1+n);
  ll w=b[n/2],v=b[n/2+1];
  for (int i=1;i<=n;i++){
    if (a[i]<=w) printf("%lld\n",v);
    else printf("%lld\n",w);
  }

   return 0;
}


Measured memory_bytes: 7808
#! coding:utf-8

import numpy as np

weather = input()
w_temp = 0
w_sum = 0

for i in range(len(weather)):
    if weather[i] == "R":
        w_temp += 1
    else:
        if w_sum < w_temp:
            w_sum = w_temp
        w_temp = 0

if w_sum < w_temp:
    w_sum = w_temp

print(str(w_sum))

Measured memory_bytes: 27136
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

ll ceil(ll a, ll b) {
	return (a + b - 1) / b;
}

void solve() {
	ll x, k, d;
	cin >> x >> k >> d;
	if(x < 0) x = -x;
	
	if(ceil(x, d) > k) {
		cout << x - k * d << endl;
	} else {
		int rem = k - ceil(x, d);
		if(rem % 2) {
			cout << abs(x - ceil(x, d) * d + d) << endl;
		} else {
			cout << abs(x - ceil(x, d) * d) << endl;
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B; cin>>A>>B;
    if (A>=13){
        cout<<B<<endl;
    }else if(A>=6){
        cout<<B/2<<endl;
    }else{
        cout<<"0\n";
    }
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


int main(){
  ll n,k,c;
  string s;
  cin >> n >> k >> c >> s;
  vector<ll> be_ind,be_can;
  vector<ll> en_ind,en_can;

  ll bef = -INF,can=0,bef_ind;
  FOR(i,0,n){
    if(s[i]=='x')continue;
    be_can.push_back(can+(bef+c<i));
    if(bef+c<i){bef=i;can++;bef_ind=i;}
    be_ind.push_back(bef_ind);
  }

  bef = INF,can = 0;
  FORR(i,0,n){
    if(s[i]=='x')continue;
    en_ind.push_back(i);
    en_can.push_back(can+(i+c<bef));
    if(i+c<bef){bef=i;can++;}
  }

  REV(en_can);
  REV(en_ind);

  //for(auto x:be_can)cout<<x<<" ";cout<<endl;
  //for(auto x:en_can)cout<<x<<" ";cout<<endl;

  ll ans=0,cnt=0;
  FOR(i,0,n){
    if(s[i]=='x')continue;
    if(cnt==0){
      ll num=0;
      if(en_can.size()>1)num = en_can[1];
      cnt++;
      if(num<k)cout<<i+1<<"\n";
      continue;
    }
    ll num = 0;
    if(cnt) num += be_can[cnt-1];
    int ind = POSU(be_ind,be_ind[cnt-1]+c);
    if(ind==cnt)ind++;
    if(ind<en_can.size())num += en_can[ind];
    if(num<k)cout << i+1 << "\n";
    cnt++;
  }
  //cout << ans << endl;
}


Measured memory_bytes: 9832
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=10005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
ll a[MAXN],cnt[MAXN];
int main()
{
    int n=read();ll k=read();
    for (int i=1;i<=n;i++) 
	{
	    a[i]=read();
	    cnt[a[i]]++;
	}
	ll ans=0;
	for (int i=1;i<=2000;i++) cnt[i]+=cnt[i-1];
	for (int i=1;i<n;i++)
		for (int j=i+1;j<=n;j++) 
		    if (a[i]>a[j]) ans++;
	ans=ans*k%mods;
	for (int i=1;i<=n;i++) (ans+=(((k-1)*k/2)%mods)*cnt[a[i]-1]%mods)%=mods;
	printf("%lld",ans%mods);
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

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

    REP(i, n+1){
        REP(j, m+1){
            int num = (m - j) * i + j * (n - i);
            if(num == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a[4],ans=0;
	cin>>a[1]>>a[2]>>a[3];
	while(a[1]!=a[2]||a[2]!=a[3]||a[1]!=a[3])
	{
		sort(a+1,a+4);
		if(a[2]!=a[3])
		{
			a[1]++;
			a[2]++;
			ans++;
		}
		else
		{
			a[1]+=2;
			ans++;	
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3620
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

int main(){
  int n;
  cin>>n;
  double x1,y1,x2,y2,x3,y3,x,y,r;
  double a,b,c,d,e,f;
  
  rep(i,n){
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    a=2*(x1-x2);
    b=2*(y1-y2);
    c=x1*x1-x2*x2+y1*y1-y2*y2;
    d=2*(x1-x3);
    e=2*(y1-y3);
    f=x1*x1-x3*x3+y1*y1-y3*y3;
    x=(c*e-b*f)/(a*e-b*d);
    y=(c*d-a*f)/(b*d-a*e);
    r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
    
    printf("%.3f %.3f %.3f\n",x,y,r);
  }
  return 0;
}


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

using namespace std;

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

  vector<int> in(3);
  cin >> in[0] >> in[1] >> in[2];
  sort(in.begin(), in.end());
  int A = in[0], B = in[1], C = in[2];
  int res;
  if (A == C) res = 0;
  else if (A == B) res = C-A;
  else if (A < B && (B-A)%2 == 0) res = (B-A)/2 + C-B;
  else res = 1 + (B+1-A)/2 + (C-B); 

  cout << res << endl;

  return 0;
}



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

#define ll long long
#define ld long double
#define ii pair<int ,int >
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);
const int N = 1e5+107;
int n,a[N],mem[N],k;

int dp(int i){
    if(i==n-1)return 0;
    if(i>=n)return 1e9;
    int &ret = mem[i];
    if(ret!=-1)return ret;
    int p1=1e9;
    for(int j=1;j<=k;j++){
        p1 = min(p1,abs(a[i+j]-a[i])+dp(i+j));
    }
    return ret = p1;
}

int main(){
    SPEED
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    memset(mem,-1,sizeof mem);
    cout<<dp(0);

}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> rec;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			rec.push_back(i);
			if (i * i != n) rec.push_back(n / i);
		}
	}
	ll ans = 0;
	for (ll c : rec) {
		if (c == 1) continue;
		ll tmp = c - 1;
		if (ll(n / tmp) == ll(n % tmp)) ans += tmp;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  char a,b;
  cin>>a>>b;
  if((a=='H'&&b=='H')||(a=='D'&&b=='D'))puts("H");
  else puts("D");
  return 0;
}

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

using namespace std;

int main()
{
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	
	if((x+r <= W) && (y+r <= H) && (x-r >= 0) && (y-r >= 0))
		printf("Yes\n");
	else
		printf("No\n");
	
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

ll nums[55];

int main() {
    ll K;
    cin >> K;
    
    mem(nums,0);
    
    rrep(i,49){
        nums[i] = (ll)(i + (K+i)/50);
    }
    cout1(50);
    rep(i,50){
        if(i)cout<<" ";
        cout<<nums[i];
    }
    cout<<endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc166/tasks/abc166_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N;
  cin >> N;

  VL as(N);
  rep(i, N) cin >> as[i];

  map<ll, ll> m;

  ll res = 0;

  rep1(i, N) {
    ll a = as[i - 1];
    res += m[-(a - i)];
    m[a + i]++;
  }

  cout << res << "\n";
}


Measured memory_bytes: 27460
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define MOD           1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define endl "\n"
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int fc[100001], in[100001];
/*int pwmd(int a, int n)
{
	if (!n)
		return 1;
	int pt = pwmd(a, n / 2);
	pt *= pt, pt %= mod;
	if (n & 1)
		pt *= a, pt %= mod;
	return pt;
}*/

/*void dfs(int i,int par)
{
	for(int x:adj[i])
	{
		if(x!=par)
		{
			dfs(x,i);
		    sub[i]+=sub[x];
		}
	}
}*/
int pow(int a,int b,int m)
{
	int ans=1; 
	while(b>0)
	{ 
		if(b%2==1) 
			ans=(ans*a)%m; 
		 b/=2; 
		 a=(a*a)%m; 
	}
		return ans%m; 
}


int c1,c2,c3;
int dp[3005][3];
int32_t main()
{
	FIO;
	int k;
	string s;
	cin>>k;
	cin>>s;
	int n=s.size();

	if(n<=k)
		cout<<s<<endl;
	else
	{
		for(int i=0;i<k;i++)
			cout<<s[i];
		cout<<"..."<<endl;
	}

}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

string s;

int main() {
	cin >> s;
	if (s == "SUN") cout << 7;
	if (s == "MON") cout << 6;
	if (s == "TUE") cout << 5;
	if (s == "WED") cout << 4;
	if (s == "THU") cout << 3;
	if (s == "FRI") cout << 2;
	if (s == "SAT") cout << 1;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n;
  cin >> n;
  vint A(5);
  rep(i,0,5) cin >> A[i];
  int min = INF;
  int key = -1;
  rep(i,0,5){
    if(A[i]<min){
      min = A[i];
      key = i;
    }
  }
  if(n % min == 0){
    cout << 4 + n/min << endl;
  }
  else cout << 4 + n/min + 1 << endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 998244353;
ll dp[4005][4005];
ll R_sum[4005];
ll B_sum[4005];
ll red[4005];
ll blue[4005];

int main() {
    //cout.precision(10);
    string S;
    cin >> S;
    ll N = S.size();
    S = "#" + S;
    for(int i = 1; i <= N; i++) {
        R_sum[i] = R_sum[i - 1];
        B_sum[i] = B_sum[i - 1];
        if(S[i] == '0') {
            R_sum[i] += 2;
        }
        if(S[i] == '1') {
            R_sum[i]++;
            B_sum[i]++;
        }
        if(S[i] == '2') {
            B_sum[i] += 2;
        }
    }
    for(int i = N + 1; i <= 2 * N + 1; i++) {
        R_sum[i] = R_sum[i - 1];
        B_sum[i] = B_sum[i - 1];
    }
    for(int i = 1; i <= 2 * N; i++) {
        red[i] = red[i - 1];
        if(R_sum[i] > red[i]) red[i]++;
    }
    for(int i = 1; i <= 2 * N; i++) {
        blue[i] = blue[i - 1];
        if(B_sum[i] > blue[i]) blue[i]++;
    }
    for(int i = 1; i <= 2 * N; i++) {
        //cout << i << " " << red[i] << " " << blue[i] << endl;
    }
    dp[0][0] = 1;
    for(int num_r = 0; num_r <= R_sum[N]; num_r++) {
        for(int num_b = 0; num_b <= B_sum[N]; num_b++) {
            int total = num_r + num_b;
            if(red[total] < num_r) continue;
            if(blue[total] < num_b) continue;
            if(num_r > 0) {
                dp[num_r][num_b] = (dp[num_r][num_b] + dp[num_r - 1][num_b]) % mod;
            }
            if(num_b > 0) {
                dp[num_r][num_b] = (dp[num_r][num_b] + dp[num_r][num_b - 1]) % mod;
            }
        }
    }
    cout << dp[R_sum[N]][B_sum[N]] << endl;
    return 0;
}


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

using namespace std;

int a[2005];
pair <int, int> b[2005];
long long dp[2005][2005];

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	
	for (int i = 1; i <= n; i++) b[i] = make_pair(a[i], i);
	sort(b + 1, b + 1 + n, greater<pair<int, int>>());
	
	dp[0][0] = 0;
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			// left
			if (j - 1 >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1LL * b[i].first * (b[i].second - j));
			
			// right
			if (j != i)	dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1LL * b[i].first * (n - (i - j) + 1 - b[i].second)); 
		}
	}
	
	long long res = 0;
	
	for (int i = 0; i <= n; i++) res = max(res, dp[n][i]);
	
	printf("%lld\n", res);
}


Measured memory_bytes: 26496
#include<bits/stdc++.h>
using namespace std;
int a[26];
int main(){
  string s;cin>>s;
  for(int i=0;i<s.size();i++){
    a[s[i]-'a']++;
    a[s[i]-'a']%=2;
  }
  bool f=true;
  for(int i=0;i<26;i++){
    if(a[i]){
      f=false;
      break;
    }
  }
  cout<<(f?"Yes":"No")<<endl;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[][] used;
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int ans = 0;
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        ans = Math.min(a,k);
        k -= (a+b);
        if(k <= 0){
            System.out.println(ans);
        }else{
            System.out.println(ans-k);
        }
        
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 25348
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a == 1) a = 14;
  if(b == 1) b = 14;
  if(a > b) cout << "Alice" << endl;
  else if(a < b) cout << "Bob" << endl;
  else cout << "Draw" << endl;
}

Measured memory_bytes: 384