akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#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
//const ll INFL = 1LL << 60;//10^18 = 2^60
const ll INFL = 1LL << 60;
const int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
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){
  x %= MOD; x += MOD; x %= MOD;
  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;
}

ll kai_mod(ll x){
  if(x == 1) return 1;
  return x * kai_mod(x-1) % MOD;
}


int main(void){
  ll N;
  cin >> N;
  vector<double> A(N);
  rep(i, N) cin >> A[i];
  double x = 0;
  rep(i, N){
    x += 1.0 / A[i];
  }
  double ans = 1.0 / x;
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A[3][3];
  bool B[3][3]={};
  for(int i=0;i<3;i++)for(int j=0;j<3;j++)cin>>A[i][j];
  int N;cin>>N;
  for(int i=0;i<N;i++){
    int b;cin>>b;
    for(int i=0;i<3;i++)for(int j=0;j<3;j++)B[i][j]|=(b==A[i][j]);
  }
  long ans=0;
  for(int i=0;i<3;i++)ans|=(B[i][0]&B[i][1]&B[i][2]);
  for(int i=0;i<3;i++)ans|=(B[0][i]&B[1][i]&B[2][i]);
  ans|=B[0][0]&B[1][1]&B[2][2];
  ans|=B[2][0]&B[1][1]&B[0][2];
  cout<<(ans?"Yes":"No");
  
}

Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

//とりあえず1-indexedでつくったBIT
template <class T>
class BinaryIndexedTree {
 private:
  T n;
  std::vector<T> bit;

 public:
  BinaryIndexedTree(T i) : n(i), bit(i + 1, 0){};

  // a番目にwを加算
  void add(T a, T w) {
    for (T x = a; x <= n; x += (x & -x)) {
      bit[x] += w;
    }
  }

  //[1,a]の和
  T sum(T a) {
    T ret = 0;
    for (T x = a; x > 0; x -= (x & -x)) {
      ret += bit[x];
    }
    return ret;
  }

  //各項がすべて非負のものに対して、sum[1,a]>=keyを満たす最小のaを返す
  //存在しないなら-1返す
  T lower_bound(T key) {
    T len = 1, temp = n, now = 0, value = 0, flag;
    while (temp / 2 != 0) {
      len *= 2;
      temp /= 2;
    }

    while (len > 0) {
      while (now + len > n) len /= 2;

      if (value + bit[now + len] >= key) {
        len /= 2;
      } else {
        now += len;
        value += bit[now];
        len /= 2;
        if (now == n) {
          return -1;
        }
      }
    }

    now++;
    return now;
  }
};

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n;
  std::cin>>n;

  std::vector<P> a(n);

  rep(i,0,n){
    ll temp;
    std::cin>>temp;
    a[i]=P(temp,i+1);
  }

  std::sort(all(a),std::greater<P>());

  BinaryIndexedTree<ll> count(n+10);

  ll ans=0;

  count.add(a[0].second,1);

  rep(i,1,n){
    ll value=a[i].first,itr=a[i].second;
    ll cnt=count.sum(itr);
    ll left1,left2,right1,right2;
    if(cnt==0){
      left1=itr;left2=0;
    }else if(cnt==1){
      left1=itr-count.lower_bound(1);
      left2=count.lower_bound(1);
    }else{
      left1=itr-count.lower_bound(cnt);
      left2=count.lower_bound(cnt)-count.lower_bound(cnt-1);
    }

    if(i-cnt==0){
      right1=n-itr+1;right2=0;
    }else if(i-cnt==1){
      right1=count.lower_bound(cnt+1)-itr;
      right2=n-count.lower_bound(cnt+1)+1;
    }else{
      right1=count.lower_bound(cnt+1)-itr;
      right2=count.lower_bound(cnt+2)-count.lower_bound(cnt+1);
    }

    ans+=(left1*right2+left2*right1)*value;
    count.add(itr,1);
  }

  std::cout<<ans;

  return 0;
}


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


int data[2000001] = {0};

struct Heap{
    int last;
    Heap(): last(1) {};

    void insert(int key){
        data[last++] = key;
        int idx = last - 1;
        while (idx > 1 && key > data[idx>>1]){
            data[idx] = data[idx>>1];
            idx >>= 1;
        }
        data[idx] = key;
    }
    
    void maxHeapify(int i){
        int L = i << 1;
        int R = L | 1;
        int largest = (L < last && data[L] > data[i]) ? L : i;
        if (R < last && data[R] > data[largest]) largest = R;
        if (largest != i){
            int tmp = data[i];
            data[i] = data[largest];
            data[largest] = tmp;
            maxHeapify(largest);
        }
    }
    
    void extractMax(){
        cout << data[1] << endl;
        data[1] = data[--last];
        maxHeapify(1);
    }
};


int main()
{
    ios::sync_with_stdio(false);
    Heap hp;
    string command;
    int key;
    while (cin >> command){
        if (command[0] == 'i'){
            cin >> key;
            hp.insert(key);
        }else if (command[1] == 'x'){
            hp.extractMax();
        }else{
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 7144
s_orig = gets.chomp
t_orig = gets.chomp

s = s_orig.codepoints
t = t_orig.codepoints

dp = Array.new(s.size+1) { Array.new(t.size+1,0) }

0.upto(s.size-1).each do |i|
  dpi = dp[i]
  dpi1 = dp[i+1]
  0.upto(t.size-1).each do |j|
    if s[i] == t[j]
      dpi1[j+1] = dpi[j] + 1
    else
      dpi1[j+1] = dpi1[j] > dpi[j+1] ? dpi1[j] : dpi[j+1]
    end
  end
end

ans = ''
y = s.size
x = t.size

while y>0
  if dp[y-1][x] == dp[y][x]
    y-=1
  elsif dp[y][x-1] == dp[y][x]
    x-=1
  else
    y-=1
    x-=1
    ans += s_orig[y]
  end
end

# dp.each{|l| p l}

puts ans.reverse


Measured memory_bytes: 76924
n = int(input())
a_list = []
for i in range(2):
  a_list.append(list(map(int,input().split())))
max_list = [[0 for i in range(n)] for i in range(2)]
max_list[0][0] = a_list[0][0]
max_list[1][0] = a_list[0][0] + a_list[1][0]
for i in range(1,n):
  max_list[0][i] = max_list[0][i-1] + a_list[0][i]
for j in range(1,n):
  max_list[1][j] = max(max_list[0][j],max_list[1][j-1]) + a_list[1][j]
  
print(max_list[1][n-1])

  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int l=0;
	for (int i=0;i<s.size();i++){
		if (s[i]=='C') l=1;
		if (s[i]=='F' && l==1){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import heapq
ans=0
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=a[i]*(-1)
heapq.heapify(a)
for i in range(m):
  b=int(heapq.heappop(a)*(-1))
  b=(b//2)*(-1)
  heapq.heappush(a,b)
for i in range(n):
  ans+=a[i]
print(ans*(-1))


Measured memory_bytes: 14180
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

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

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

int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=0;i<n;i++){
        int l,r;
        cin>>l>>r;
        ans += (r-l)+1;
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define S second
#define F first
#define ll long long
#define ld double

using namespace std;

const ll N = 2e5 + 5, M = N * 2;

int arr[N];

int main()
{
    int n, m, xx, sum = 0;
    scanf("%d", &n);
    for(int i = 1 ; i < n ; i++)
    {
        scanf("%d", &xx);
        arr[--xx]++;
    }
    for(int i = 0 ; i < n ; i++) printf("%d%c", arr[i], " \n"[i == m - 1]);

    return 0;
}


Measured memory_bytes: 4504
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string o,e;
  cin>>o>>e;
  size_t sizeO=o.length();
  size_t sizeE=e.length();
  if(sizeO>sizeE){
    for(int i(0);i<sizeE;i++){
      cout<<o[i]<<e[i];
    }
    cout<<o[sizeO-1]<<endl;
  }else{
    for(int i(0);i<sizeE;i++){
      cout<<o[i]<<e[i];
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String S = s.nextLine();
		if(S.matches(".*AC.*")){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 23636
N,X = map(int,input().split())
A = list(map(int,input().split()))

ans = 0

sumA = sum(A)
A.sort()

if sumA == X:
    ans = N
elif sumA < X:
    ans = N-1
else:
    for i in range(N):
        if A[i] <= X:
            X -= A[i]
            ans += 1
        else:
            break

print(ans)


Measured memory_bytes: 3060
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
#define DEBUG

const int maxn=100005;
int n,m,ans=-1;
vector<pii>edge[maxn];
int cons[maxn],coef[maxn];
bool vis[maxn];

inline void End(){printf("0");exit(0);}

void dfs(int x){
	vis[x]=true;
//	cout<<x<<" "<<cons[x]<<" "<<coef[x]<<endl;
	rep(i,edge[x].size()){
		pii y=edge[x][i];
		if(vis[y.fst]){
			int a=cons[x],b=coef[x],c=cons[y.fst],d=coef[y.fst];
			if(b+d==0){
				if(y.snd-a-c==0)continue;
				else End();
			}
			else{
				if(abs(y.snd-a-c)%abs(b+d)!=0||(y.snd-a-c)/(b+d)<=0)End();
				int now=(y.snd-a-c)/(b+d);
				if(ans<0||ans==now)ans=now;
				else End();
			}
		}
		else{
			cons[y.fst]=y.snd-cons[x];coef[y.fst]=-coef[x];
			dfs(y.fst);
		}
	}
}

int main(){
#ifndef DEBUG
	freopen("my.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	rep(i,m){
		int u,v,s;
		scanf("%d%d%d",&u,&v,&s);
		edge[u].pb(mp(v,s));
		edge[v].pb(mp(u,s));
	}
	cons[1]=0;coef[1]=1;
	dfs(1);
	if(ans>0){
		REP(i,n)if(cons[i]+coef[i]*ans<=0)End();
		printf("1");
		return 0;
	}
	int l=0,r=INF+2;
	REP(i,n){
		if(coef[i]<0)r=min(r,cons[i]);
		else l=max(l,-cons[i]);
	}
	if(l>=r)End();
	printf("%d",r-l-1);
	return 0;
}

/*
Input:
-----------------
Output:
*/

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

int main(){
    int l, r, m;
    cin >> l >> r;
    m = 2019;
    if (r - l >= 2019){
        cout << 0 << endl;
        return 0;
    }
    int ans = 1000000000;
    for (int i = l; i <= r; i++){
        for (int j = i + 1; j <= r; j++){
            long long t = (long long)i * j;
            t %= m;
            ans = min(ans, (int)t);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FASTIO cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define ll long long int
#define F first
#define S second
#define pll pair<ll,ll>
#define vl vector<ll>
#define pb push_back

struct compare {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		if ((a.S - a.F) != (b.S - b.F)) return ((a.S - a.F) > (b.S - b.F));
		else return (a.F < b.F);
	}
};

int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	FASTIO;
	ll n, i, k, j; cin >> n;
	vector<vector<int>> v(n, vector<int>(3)), dp(n, vector<int>(3));
	for (i = 0; i < n; i++) cin >> v[i][0] >> v[i][1] >> v[i][2];
	dp[n - 1][0] = v[n - 1][0]; dp[n - 1][1] = v[n - 1][1]; dp[n - 1][2] = v[n - 1][2];
	for (i = n - 2; i >= 0; i--) {
		dp[i][0] = v[i][0] + max(dp[i + 1][1], dp[i + 1][2]);
		dp[i][1] = v[i][1] + max(dp[i + 1][0], dp[i + 1][2]);
		dp[i][2] = v[i][2] + max(dp[i + 1][1], dp[i + 1][0]);
	}
	cout << max(dp[0][0], max(dp[0][1], dp[0][2])) << endl;

}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  string s;
  cin>>s;
  int a=0,b=0;
  rep(i,s.size()) {
    if(s[i]=='A')a++;
    if(s[i]=='B')b++;
  }
  if(a==0||b==0)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int 
int main()
{
    lli x,k,d,a,f;
    cin>>x>>k>>d;
    x=abs(x);
    f=x/d;
    if(f>=k)
    {
        cout<<x-k*d;
    }
    else
    {
       k=k-f;
       x=x-f*d;
       if(k%2==0)
       cout<<x;
       else
       cout<<d-x;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int a,b,h,m;
  cin >> a >> b >> h >> m;
  double A = 30.0*(double)h + (double)m/2.0;
  double B = 6.0*(double)m;
  double PI = acos(-1);
  double S = 2*PI*abs(A-B)/360.0;
  double C2 = a*a + b*b - 2*a*b*cos(S);
  fix20;
  //cout << cos(S) << endl;
  cout << sqrt(C2) << endl;
}

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

int main(void) {
    int n, l;
    cin >> n >> l;
    int max = n + l - 1;
    long long sum = (l + max) * n / 2;
    if(l >= 0){
        sum = sum - l;
    }else if(max < 0){
        sum = sum - max;
    }else{

    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <complex>
using namespace std;
static const double EPS = 1e-12;
#define rep(i,n) for(int i=0;i<n;i++)

const double INF = 1e12;
typedef complex<double> P,point;
namespace std {bool operator < (const P& a, const P& b) {return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);}}
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
struct L : public vector<P> {L(const P &a, const P &b) {push_back(a); push_back(b);}};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectSS(const L &s, const L &t) {
	return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 && ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  return m[0] + B / A * (m[1] - m[0]);
}
double getArea(P a, P b , P c){
		b-=a, c-=a;
		return fabs( b.real() * c.imag() - c.real() * b.imag() ) / 2.0; 
}
int main(){
	double a,b,c,d;
	while(cin >> a >> b >> c >> d , a || b || c || d){
		L one = L(P(a,b),P(c,d));
		cin >> a >> b >> c >> d;
		L two = L(P(a,b),P(c,d));
		cin >> a >> b >> c >> d;
		L three = L(P(a,b),P(c,d));
		double ret = 0;
		
		if(intersectSS(one,two) && intersectSS(two,three) && intersectSS(one,three)){
			ret = getArea( crosspoint(one,two) , crosspoint(two,three) , crosspoint(one,three) );
		}
		if(ret >= 1900000){
			cout << "dai-kichi" << endl;
		}else if(ret >= 1000000){
			cout << "chu-kichi" << endl;
		}else if(ret >= 100000){
			cout << "kichi" << endl;
		}else if(ret > 0){
			cout << "syo-kichi" << endl;
		}else{
			cout << "kyo" << endl;
		}
	}
}

Measured memory_bytes: 0
h,w = gets.split.map(&:to_i)
arr = []
h.times do |i|
  arr << gets.chomp.split('')
end
dx = [1,0,-1,0]
dy = [0,1,0,-1]
prop = 0
h.times do |i|
  w.times do |j|
    if arr[i][j] == '#'
      check = 0
      4.times do |k|
        ny = i + dy[k]
        nx = j + dx[k]
        if nx >= 0 && ny >= 0 && nx < w && ny < h
          check += 1 if arr[ny][nx] == '#'
        end
      end
   	  prop = 1 if check == 0
    end
  end
end
if prop == 1
  puts :No
else
  puts :Yes
end

Measured memory_bytes: 2172
n, k = map(int, input().split())
p = list(map(int, input().split()))
tmp = sum(p[:k])
ans = [tmp]
if n == k:
    ans_mae = ans[0]
    print((ans_mae+k)/2)
else:
    for i in range(1,n-k+1):
        tmp = tmp - p[i-1] + p[i+k-1]
        ans.append(tmp)
    print((max(ans)+k)/2)

Measured memory_bytes: 24808
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;

bool check(const vector<ll>& A, ll K, ll D){
    vector<ll> B;
    for (auto &&a : A) {
        B.push_back(a%D);
    } // end a
    sort(ALL(B));
    vector<ll> fsb(B.size()+1), bsb(B.size()+1);
    for (int i = 0; i < B.size(); ++i) {
        fsb[i+1] = fsb[i] + B[i];
    } // end i
    for (int i = B.size(); i > 0; --i) {
        bsb[i-1] = bsb[i] + (D-B[i-1])%D;
    } // end i

    for (int k = 0; k < B.size()+1; ++k) {
        ll fc = fsb[k];
        ll bc = bsb[k];
        if(K >= max(fc, bc) ){
            return true;
        }
    } // end k

    return false;
}


void sub_main(istream &is) {
    ll N, K;
    is >> N >> K;
    if(!is) return;
    vector<ll> A(N);
    ll sum = 0;
    for (auto &&a : A) {
        is >> a;
        sum += a;
    } // end a
    vector<ll> ff;
    ff.push_back(sum);
    for (int i = 2; i < sqrt(sum) + 1; ++i) {
        if(sum % i == 0){
            ff.push_back(i);
            ff.push_back(sum/i);
        }
    } // end i

    ll ans = 1;

    for (auto &&t : ff) {
        if(check(A, K, t)) ans = max(ans, t);
    } // end t

    cout << ans << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_E.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


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

int N,A,B;

int main(){

    cin>>N>>A>>B ;
    if(N*A < B ){
        cout << N*A << endl;
    }
    else if (N*A > B)
    {
        cout << B << endl;
    }
    else
    {
        cout << B << endl;
    }
    
}

Measured memory_bytes: 256
import scala.io.StdIn.{readInt,readLine}

object Main {
  def main(args:Array[String]) = {
    val n = readInt
    val players = new Array[Int](n)
    val a = for(i <- 1 to n) yield readLine.split(" ").map(_.toInt)
    for(i<-0 until 3) {
      { for(j<-0 until n) yield (a(j)(i),j) }.toList.groupBy(_._1).filter(_._2.length==1).foreach { p=>
        players(p._2(0)._2) += p._1
      }
    }
    players.foreach(println)
  }
}

Measured memory_bytes: 44532
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    println!("{}", (n + k - 3) / (k - 1));
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int y,m,d;
  while(s!="#"){
    cin >>y >>m>>d;
    if(y>=32||(y==31&&m>=5)){
      cout <<"? "<<y-30<<" "<<m<< " "<<d<<endl;
    }else{
      cout << s << " "<<y<<" "<<m<<" "<<d<<endl;
    }
    cin >> s;
  }
}



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

#define int long long

using namespace std;



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

    int N;
    cin >> N;

    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;

    for(int i = 0 ; i < N ; i++)
    {
    	string cad;
    	cin >> cad;
    	if(cad == "AC")ac++;
    	if(cad == "WA")wa++;
    	if(cad == "TLE")tle++;
    	if(cad == "RE")re++;
    }

    cout << "AC x " << ac << '\n';
    cout << "WA x " << wa << '\n';
    cout << "TLE x " << tle << '\n';
    cout << "RE x " << re << '\n';

    return 0;
}

Measured memory_bytes: 3620
import sys
input = sys.stdin.readline

n = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
C = [0]*(3*n)
for i in range(n):
  C[i] = B[i]^B[(i+1)%n]
  C[i+n] = A[i]^A[(i+1)%n]
  C[i+n+n] = C[i+n]

def z_algo(S):
    N = len(S)
    A = [0]*N
    A[0] = N
    i, j = 1, 0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        A[i] = j
        if not j:
            i += 1
            continue
        k = 1
        while i+k < N and k+A[k] < j:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A  

P = z_algo(C)
for i, p in enumerate(P[n:n+n]):
  if p >= n:
    x = A[i]^B[0]
    print(i, x)

Measured memory_bytes: 124808
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e6 + 5;

ll n, bl[nax];
vector<ll> v;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	
	for(ll i = 2; i < nax; i++){
		if(!bl[i]){
			v.pb(i);
			for(ll j = i * i; j < nax; j += i){
				bl[j] = 1;
			}
		}
	}
	
	cin >> n;
	ll ans = 0;
	for(ll x : v){
		ll cnt = 0;
		while(n % x == 0){
			cnt++;
			n /= x;
		}
		ll tot = 0;
		for(ll i = 1; i <= 30; i++){
			tot += i;
			if(tot > cnt){
				ans += i - 1;
				break;
			}
		}
	}
	if(n > 1){
		ans += 1;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 12068
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
ll X, Y;

int main() {
	scanf("%lld%lld", &X, &Y);
	puts(abs(X - Y) > 1 ? "Alice" : "Brown");
	return 0;
}

Measured memory_bytes: 128
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input! {
        N: usize, 
        A: usize,
        B: usize,
        h: [usize; N],
    }

    let mut max = 1_000_000_000;
    let mut min = 0;
    loop {
        if max - min <= 1 {
            println!("{}", max);
            return
        }
        let t = min + (max - min) / 2;
        let times = h.iter()
        .fold(0, |acc, hi| acc + (hi.saturating_sub(t*B)+A-B-1)/(A-B));
        if times <= t {
            max = t;
        } else {
            min = t;
        }
    }
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        //int a = stdIn.nextInt();
        //int b = stdIn.nextInt();
        //int c = stdIn.nextInt();
        //int w = stdIn.nextInt();
        //int n = stdIn.nextInt();
        //int k = stdIn.nextInt();
        String s = stdIn.next();
        char c[] = s.toCharArray();
        boolean heisei = true;
        
        if(c[5] == '1'){
            heisei = false;
        }else if(c[6] == '5' ||c[6] == '6' ||c[6] == '7' ||c[6] == '8' ||c[6] == '9'){
            heisei = false;
        }
        
        if(heisei){
            System.out.println("Heisei");
        }else{
            System.out.println("TBD");
        }
        
        //System.out.println();
        //System.out.print();
    }
}


Measured memory_bytes: 21972
arr = [list(map(int,input().split())) for _ in range(3)]
a = []
b = []
for i in range(3):
  b.append(arr[0][i]-0)
  a.append(arr[i][0]-b[0])
for i in range(3):
  for j in range(3):
    if a[i] + b[j] != arr[i][j]:
      print("No")
      exit()
print("Yes")


Measured memory_bytes: 3060
//#include<bits_stdc++.h>
#include <iostream>
#include <math.h>
#include <queue>
#include <vector>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define ll long long
using namespace std;
int main() {
    int n, q;
    queue<pair<string, int> > que;
    cin >> n >> q;
    rep(i, n) {
        string st;
        int t;
        cin >> st >> t;
        que.push(make_pair(st, t));
    }
    int now = 0;
    while(!que.empty()) {
        pair<string, int> process = que.front();
        que.pop();
        if(process.second > q) {
            now += q;
            process.second -= q;
            que.push(process);
        } else {
            now += process.second;
            cout << process.first << " " << now << endl;
        }
    }
}



Measured memory_bytes: 6224
#include<iostream>
using namespace std;
int main()
{
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	if(b>0&&d>0)
	cout<<max(b*d,a*c);
	else if(a<0&&c<0)
	cout<<a*c;
	else if(b<0) {
		cout<<b*c;
	}
	else cout<<d*a;
	return 0;
}

Measured memory_bytes: 3620
include Math

  a,b,h,m = gets.strip.split.map(&:to_i)
  ta = PI*(h*60+m) / 360
  tb = PI*m/30
  t = (ta-tb).abs
  t = 2*PI - t if t > PI
  c = sqrt(a*a + b*b - 2*a*b*cos(t))
  p c


Measured memory_bytes: 14676
#include<iostream>
#include<string>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;

int main(){
  string S;
  cin >> S;

  int len=S.length();
  long long ans=0;
  long long ANS=0;

  REP(bit, 1<<len-1){
    int lpi=-1;
    REP(pi, len-1){
      if(bit & (1<<pi)){
        ans += stol(S.substr(lpi+1, pi-lpi));
        lpi = pi;
      }
    }
    ans += stol(S.substr(lpi+1, len-lpi-1));
  }
  cout << ans << endl;

  return 0;
}



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

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; }
const ll INF = 1LL << 60;

//---main---------------------------------------------
int main(){
    //main
    int N,K;
    cin >> N >> K;
    int p[N];
    rep(i,N) cin >> p[i];

    sort(p,p+N);

    int ans=0;
    rep(i,K) ans += p[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d",&x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for(int i = 0 ; i < n ;i ++)
#define repc(i, n) for(int i = 0 ; i < n ; i ++)
#define FOR(i, x, y) for(int i = x ; i < y ; i ++)
#define DEC(i, x, y) for(int i = x ; i >= y ; i --)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a+n
using namespace std;
#define ll long long
 vector<pair<ll,ll>>v;
 ll n,k,p;
 ll go(ll i,ll p)
 {
     if(p==0)
     {
         return 0;
     }
     if(p<0)
     {
         return INT_MIN;
     }
     ll res=INT_MIN;
     res=max(go(i+1,p-v[i].second)+v[i].first,go(i+1,p));
     return res;
 }
 bool check(string s)
 {
     string s1=s;
     reverse(s1.begin(),s1.end());
     if(s1==s)
     return true;
     else
     return false;
 }
int main() {
    
    ll n;
    cin>>n;
    ll a[n];
    map<ll,ll>mp;
    FOR(i,0,n)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    ll s=0;
    for(auto it:mp)
    {
        s+=(it.second*(it.second-1))/2;
    }
    ll res=0;
    FOR(i,0,n)
    {
        res=s-((mp[a[i]]*(mp[a[i]]-1))/2)+((mp[a[i]]-1)*(mp[a[i]]-2)/2);
        cout<<res<<endl;
    }
}


Measured memory_bytes: 12800
mountains_high=[]
for i in range(10):
    mountains_high.append(int(input()))

mountains_high_copy=mountains_high.copy()
for i in range(9):
    for j in range(9):
        if mountains_high_copy[j]>mountains_high_copy[j+1]:
            num=mountains_high_copy[j]
            mountains_high_copy[j]=mountains_high_copy[j+1]
            mountains_high_copy[j+1]=num

for i in range(3):
    print(mountains_high_copy[9-i])

Measured memory_bytes: 7724
n = gets.to_i
a = gets.split.map(&:to_i)


c = Array.new(2*10**5+1,0)
a.each do |k|
    c[k] += 1
end

s = c.map{|k| res = k * (k-1)/2}.inject(:+)

a.each do |k|
    puts s - (c[k]-1)
end

Measured memory_bytes: 25116
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(x,b) (0<=(x)&&(x)<(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

vi p(8);
int dx[] = {0,-1,0,1}, dy[] = {-1,0,1,0};

vi goal(8);
map<vi, int>m;

/*bool ck(vi ca){
  rep(i, 8) if(ca[i] != i) return false;
  return true;
  }*/

void bfs(){
  int res = 0;
  rep(i, 8) goal[i] = i;
  queue<vi>q;
  q.push(goal);
  m[goal] = res;
  while(!q.empty()){
    //    fprintf(stderr, "%d\n", res);
    int qsize = (int)q.size();
    rep(i, qsize){
      vi now  = q.front(); q.pop();
      rep(j, 8){
	if(now[j] != 0) continue;
	int ny = j/4, nx = j%4;
	rep(d, 4){
	  int nexty = ny + dy[d], nextx = nx + dx[d];
	  if(nexty < 0 || nexty >= 2 || nextx < 0 || nextx >= 4) continue;
	  vi next = now;
	  int t = next[nexty*4+nextx];
	  next[nexty*4+nextx] = next[j];
	  next[j] = t;

	  if(m.count(next) == 0){
	    q.push(next);
	    m[next] = res+1;
	    //	    printf("%d\n", m[next]);
	  }
	}
      }
    }
    res++;
  }
  return;
}


int main(){
  bfs();
  while(~scanf("%d", &p[0])){
    REP(i, 1, 8) scanf("%d", &p[i]);

    printf("%d\n", m[p]);
  
    /*    if(ck(p)){
      puts("0");
      continue;
    }
    queue<vi>q;
    map<vi, bool>m;
    q.push(p);
    m[p] = 1;
    int res = 1;
    while(true){
    //    while(res < 29){
      int qsize = (int)q.size();
      //      printf("%d\n", qsize);
      rep(i, qsize){
	vi now = q.front(); q.pop();
	//	if(res == 13){ rep(i, 8) printf("%d ", now[i]); puts("");}
	rep(j, 8){
	  if(now[j] != 0) continue;
	  int ny = j/4, nx = j%4;
	  //	  puts("");
	  //	  printf("%d %d\n", ny, nx);
	  rep(d, 4){
	    int nexty = ny + dy[d], nextx = nx + dx[d];
	    //	    printf("%d %d\n", nexty, nextx);
	    if(nexty < 0 || nexty >= 2 || nextx < 0 || nextx >= 4) continue;
	    vi next = now;
	    int t = next[nexty*4+nextx];
	    next[nexty*4+nextx] = next[j];
	    next[j] = t;
	    
	    //    rep(i, 8) printf("%d ", next[i]); puts("");
	    if(ck(next)){
	      //	      rep(i, 8) printf("%d ", next[i]); puts("");
	      printf("%d\n", res);
	      goto end;
	    }	    

	    if(m.count(next) == 0){
	      q.push(next);
	      m[next] = 1;
	    }
	  }
	}
      }
      res++;
    }
    end:;*/
  }
  return 0;
}

Measured memory_bytes: 3748
#include <stdio.h>
#include <string.h>

char s[100000];
int len;

int main() {
	while (fgets(s, 100000, stdin)) {
		s[strlen(s) - 1] = '\0';
		if (strcmp(s, "END OF INPUT") == 0) { break; }
		len = strlen(s);
		
		int word_len = 0;
		for (int i = 0; i < len; i++) {
			if (s[i] == ' ') { printf("%d", word_len); word_len = -1; }
			word_len++;
		}
		printf("%d\n", word_len);
	}
	return 0;
}

Measured memory_bytes: 2576
#include <stdio.h>
#include <math.h>

main() {
	int n, m, o;
	double x;
	int z;
	scanf("%d%d", &n, &m);
	x = 1900 * m + 100*(n - m);
	z = (int) x*pow(2, m);
	printf("%d", z);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

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

  int maxDiffR = R[1] - R[0];
  int minR = R[0];

  for (int i = 1; i < n; i++) {
    int currentDiffR = R[i] - minR;

    maxDiffR = max(maxDiffR, currentDiffR);
    minR = min(minR, R[i]);
  }

  cout << maxDiffR << endl;

  return 0;
}



Measured memory_bytes: 3868
import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))
#for deque append(),pop(),appendleft(),popleft(),count()
I=lambda:int(input())
S=lambda:input().strip()
mod = 1000000007

a=[]
n=I()
for i in range(1,10):
    k=[]
    for j in range(1,10):
        k.append(0)
    a.append(k)
        

for i in range(1,n+1):
    if(i%10==0):
        continue
    k=str(i)
    p=int(k[0])-1
    q=int(k[-1])-1
    a[p][q]+=1
ans=0

for i in range(0,9):
    for j in range(0,9):
        ans+=a[i][j]*a[j][i]
print(ans)


Measured memory_bytes: 3316
N, W = map( int, input().split())
VS, WS = [], []
for _ in range(N):
    a, b = map( int, input().split())
    VS.append(a)
    WS.append(b)
dp = [ [ 0 for _ in range(10**5+1)] for _ in range(N+1) ]
for i in range(N):
    w = WS[i]
    v = VS[i]
    for j in range(W+1):
        if w <= j:
            dp[i+1][j] = max( dp[i][j-w] + v, dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[N][W])


Measured memory_bytes: 113284
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    vint A(N);
    map<ll, int> cnt;
    for (size_t i = 0; i < N; i++)
    {
        cin >> A[i];
        cnt[i + A[i]]++;
    }
    ll ans = 0;
    for (size_t i = 0; i < N; i++)
    {
        ans += cnt[i - A[i]];
    }
    //    ans *= 2;
    cout << ans;
    return 0;
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int a,b;
    cin >> a >> b;
    int ans = 0;
    for (int i = a; i <= b; i++) {
        string s = to_string(i);
        if (s[0] == s[4] and s[1] == s[3]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define repprev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) repprev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
    vector<ll> par;

    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }

    ll root(ll x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    bool merge(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    ll size(ll x) {
        return -par[root(x)];
    }
};
 
 
 
int main(){
    ll N,M;
  	cin >> N >> M;
  	vector<ll> A(M), B(M);
  	rep(i,M){
      cin >> A[i] >> B[i];
      A[i]--;
      B[i]--;
    }
  
  	vector<ll> ans(M);
  	ans[M-1] = N * (N - 1) / 2;
  
  	UnionFind Uni(N);
  
  	repprev(i, 1, M){
      //繋がってなかったのが繋がった時
      	if(Uni.root(A[i]) != Uni.root(B[i])){
          ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]);
          Uni.merge(A[i],B[i]);
        }
      else ans[i - 1] = ans[i]; 
    }
  
  rep(i,M){
    cout << ans[i] << endl;
  }
  	
}

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

#define rep(i,n) for(long long i = 0; i < n; i++)

typedef long long ll;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;

const ll INF = ll(1e18) + 1;
const int intINF = 1e9 * 2 + 3;
//--------------------------------------------------

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

bool isPrime(int n)
{
	if (n <= 3)return n > 1;
	if (n % 2 == 0)return false;
	if (n % 3 == 0)return false;
	for (int i = 5; i * i < n; i += 6) {
		if (n % i == 0 || n % (i + 2) == 0) { return false; }
	}
	return true;
}
//---------------------------------------------------



void Main()
{
	int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int n; cin >> n;
	cout << a[n-1] << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	Main();
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N; cin >> N;
    int H[N]; rep(i,N) cin >> H[i];
    int ans=0,pos=0;
    rep(i,N-1){
        if(H[i]>=H[i+1]){
            pos++;
        }
        else{
            ans=max(pos,ans);
            pos=0;
        }
    } 
    ans=max(pos,ans); 
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < K; i++)
            {
                Console.Write("ACL");
            }
        }

    }
}


Measured memory_bytes: 27320
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll


int n;
int v[110000];
int ans=0;

void f(){
  int a[110000];

  int m = n/2;
  int i = 0;
  while(0<=m&&m<n){
    a[m]=v[i];
    i++;
    if(i%2)
      m-=2*i;
    else
      m+=2*i;
  }
  m = n/2-1;
  i = 0;
  while(0<=m&&m<n){
    a[m] = v[n-1-i];
    i++;
    if(i%2)
      m+=2*i;
    else
      m-=2*i;
  }

  int sum=0;
  FOR(i,1,n){
    sum+=abs(a[i]-a[i-1]);
  }

  ans = max(ans,sum);
}


signed main(){
  cin>>n;
  rep(i,n){
    cin>>v[i];
  }

  sort(v,v+n);

  f();

  reverse(v,v+n);

  f();

  cout<<ans<<endl;
}


Measured memory_bytes: 1920
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

int main()
{
    int s;
    cin >> s;
    bool yymm = false, mmyy = false;
    if(s % 100 < 13 && s % 100 > 0) yymm = true;
    if(s / 100 < 13 && s / 100 > 0) mmyy = true;
    if(yymm && mmyy) cout << "AMBIGUOUS" << endl;
    else if(yymm) cout << "YYMM" << endl;
    else if(mmyy) cout << "MMYY" << endl;
    else cout << "NA" << endl;
}

Measured memory_bytes: 256