akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include<functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stack>
#include <deque>

#define LL long long
#define pii pair<int,int>
#define pLL pair<LL,LL>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<LL>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<LL>
#define vecpii vector<pii>
#define vecpLL vector<pLL>
#define vecbL vector<bool>
#define endl "\n"
#define REP(e,v) for(auto e:v)
#define rep(i, a, n) for(LL i = a; i < n;i++)

using namespace std;

struct edge {
    LL to;
    LL cost;
};

/*
 LL V;

 cin >> V;

 vector<edge> G[V];

 rep(i,0,V){
 	 LL e;

 	 cin >> e;

 	 rep(j,0,e){
 	 	 LL to,cost;
 	 	 cin >> to >> cost;

 	 	 G[j].insert(new edge(to,cost));
 	 }
 }

 */

void dijkstra(LL s,LL V,vector<edge> G[],LL d[]) {
    priority_queue<pLL, vector<pLL>, greater<pLL> > que;
    fill(d, d+V, INT_MAX);
    d[s] = 0;
    que.push(pLL(0, s));

    while (!que.empty()) {
        pLL p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(pLL(d[e.to], e.to));
            }
        }
    }
}


int inp(){
	int x;
	scanf("%d",&x);
	return x;
}
LL linp(){
	LL x;
	scanf("%lld",&x);
	return x;
}

void outp(int i){
	printf("%d",i);
}

void loutp(LL i){
	printf("%lld",i);
}

LL mod(LL i){
	return i % 1000000007;
}


LL gcd(LL i,LL j){
	if(j != 0)
		return gcd(j, i % j);
	else
		return i;

}

LL A(){
	LL K,A,B;

	cin >> K >> A >> B;

	rep(i,A,B+1){
		if(i % K == 0) {
			printf("OK");
			return 0;
		}
	}

	printf("NG");

	return 0;
}

LL B(){

	LL X;

	cin >> X;

	LL count = 0;
	LL money = 100;

	while(money < X){
		money *= 1.01;
		count++;

	}

	outp(count);

	return 0;
}

LL C(){
	LL N,M,Q;

	cin >> N >> M >> Q;

	LL four[Q][4];

	rep(i,0,Q){
		rep(j,0,4){
			cin >> four[i][j];
		}
	}

	rep(i,0,N){
		rep(j, 0 , M ){

		}
	}
	return 0;
}

LL D(){
	LL A,B,N;

	cin >> A >> B >>N;

	LL ma = 0;
	/*rep(x,0,N+1){
		ma = max(ma,(A*x)/B - A*(x/B));
	}
	*/

	if(B - 1 <= N){
		ma = (A*(B-1))/B - A*((B-1)/B);
	}else{
		ma = (A*N)/B - A*(N/B);
	}


	loutp(ma);

	return 0;
}


signed main() {
	//A();
	//B();
	//C();
	D();
	return 0;
}

Measured memory_bytes: 3728
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    std::string S;
    std::cin >> S;
    if (S == "Sunny") { std::cout << "Cloudy" << std::endl; }
    else if (S == "Cloudy")
    {
        std::cout << "Rainy" << std::endl;
    }
    else
    {
        std::cout << "Sunny" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>
#include <sstream>

#define all_range(C) std::begin(C), std::end(C)

int n;
int A[55];
bool is_uruu(int x) {
	for (int i = 0; i < n; i++)
	{
		if (x % A[i] == 0) {
			return i % 2 == 0;
		}
	}
	return n%2 == 0;
}

int main()
{
	using std::endl;
	using std::cout;
	using std::cin;

	while (true)
	{
		int l, r;
		cin >> n>>l>>r;
		if (n==0 && l==0 && r == 0) { break; }

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

		int count = 0;
		for (int i = l; i <= r; i++)
		{
			if (is_uruu(i)) {
				++count;
			}
		}
		//cout << "OUT!!!";
		cout << count << endl;
	}

	return 0;
}
#endif



Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
   ll N;
   cin>>N;
   vector<ll> A(N);
   bool C=false;
   rep(i, N){
       cin>>A[i];
       if(A[i]%2==1)C=true;
   }
   cout<<(C?"first":"second")<<endl;

}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define MP make_pair
#define lson root<<1,l,midd
#define rson root<<1|1,midd+1,r
typedef long long ll;
const ll mod=1e9+7;
const int M=4e5+6;
const int inf=0x3f3f3f3f;
const ll INF=1e18;
struct SegTree{
    ll tr[M<<2];
    void up(int root){
        tr[root]=max(tr[root<<1],tr[root<<1|1]);
    }
    void build(int root,int l,int r){
        tr[root]=-INF;
        if(l==r)
            return ;
        int midd=(l+r)>>1;
        build(lson);
        build(rson);
    }
    void update(int pos,ll val,int root,int l,int r){
        if(l==r){
            tr[root]=max(tr[root],val);
            return ;
        }
        int midd=(l+r)>>1;
        if(pos<=midd)
            update(pos,val,lson);
        else
            update(pos,val,rson);
        up(root);
    }
    ll query(int L,int R,int root,int l,int r){
        if(L<=l&&r<=R)
            return tr[root];
        int midd=(l+r)>>1;
        ll res=-INF;
        if(L<=midd)
            res=max(res,query(L,R,lson));
        if(R>midd)
            res=max(res,query(L,R,rson));
        return res;
    }
}t1,t2;
struct node{
    int x,y;
}a[M];
int num[M];
int main(){
    int n;
    scanf("%d",&n);
    int tot=0;
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i].x,&a[i].y),num[++tot]=a[i].y;
    sort(a+1,a+1+n,[&](node A,node B){
        return A.x<B.x;
    });
    sort(num+1,num+1+tot);
    t1.build(1,1,n);
    t2.build(1,1,n);
    int m=unique(num+1,num+1+tot)-num-1;
    int posy=lower_bound(num+1,num+1+m,a[1].y)-num;
    t1.update(posy,-(a[1].x+a[1].y),1,1,m);
    t2.update(posy,a[1].y-a[1].x,1,1,m);
    ll ans=0;
    for(int i=2;i<=n;i++){
        posy=lower_bound(num+1,num+1+m,a[i].y)-num;
        ans=max(ans,a[i].x+a[i].y+t1.query(1,posy,1,1,m));
        ans=max(ans,a[i].x-a[i].y+t2.query(posy,n,1,1,m));
        t1.update(posy,-(a[i].x+a[i].y),1,1,m);
        t2.update(posy,a[i].y-a[i].x,1,1,m);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 14320
#include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define pb push_back
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);


void solve() {
    int n;
    cin >> n;
    cout << (n >= 30 ? "Yes\n" : "No\n");
}

int main() {_
    int t = 1;
    //cin >> t;
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>

using namespace std;

int main(){
  int N = 0,n = 0;
  cin >> N;
  n = N % 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
  {
    cout << "hon";
  }

  else if (n == 0 || n == 1 || n == 6 || n == 8 )
  {
    cout << "pon";
  }

  else{
    cout << "bon";
  }
  
}

Measured memory_bytes: 3568
n = int(input())
h = list(map(int, input().split()))
cnt = 0
ans = []
for i in range(n - 1):
    if(h[i] >= h[i + 1]):
        cnt += 1
    else:
        ans.append(cnt)
        cnt = 0
ans.append(cnt)
print(max(ans))


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vl vector<ll>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define inf 1000000000000000
#define md 998244353
#define endl "\n"

void solve()
{
    int n,x;
    cin>>n>>x;
    ll sum=0;
    int a[n];
    for(int i=0;i<n;i++)
    {
       cin>>a[i];
       sum+=a[i];
    }
    int ans1=n;

    sort(a,a+n);
    
    int ans2=(x-sum)/a[0];

    cout<<ans1+ans2;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
using namespace std;
using ll = long long;
 
const ll M = 1e9+7;// 10^9+7

ll mpow(ll x,ll y){// x^y(mod M)を計算
    ll ans = 1;
    while(y != 0){
        if(y&1){
            ans = ans * x % M;
        }
        x = x * x % M;
        y = y >> 1;
    }
    return ans % M;
}

ll comb(ll n,ll k){// nCk(mod 10^9+7)を計算 : nCk = n! * (k!)^(M-2) * ((n-k)!)^(M-2) (mod M)を使っている
    ll a=1,b=1,c=1;
    if(n == 0 && k == 0) return 1;
    if(n < k|| n < 0) return 0;
    for(ll i = 1;i <= n;++i){// n!を計算
        a = a * i % M;
    }
    for(ll i = 1;i <= k;++i){// k!を計算
        b = b * i % M;
    }
    for(ll i = 1;i <= (n-k);++i){// (n-k)!を計算
        c = c * i % M;
    }
    b = mpow(b,M-2);// (k!)^(M-2)を計算
    c = mpow(c,M-2);// ((n-k)!)^(M-2)を計算
    return (a * b) % M * c % M;
}


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

    ll x, y;
    cin >> x >> y;
    ll n = (x+y) / 3;
    if((x+y)%3 != 0){ //合計が3の倍数ではなかったら0
        cout << 0 << endl;
        return 0;
    }
    x -= n;
    y -= n;
    if(x < 0 || y < 0) { 
        cout << 0 << endl;
        return 0;
    }
    ll ans = comb(x+y,y)%M;
    cout << ans << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cctype>
#include<cstring>
#include<utility>
#include<cmath>
using namespace std;

const double pi = 3.141592653589793;

int main() {
    double a, b, C, sinc, cosc;
    scanf("%lf%lf%lf", &a, &b, &C);
    sinc = sin(pi / (180 / C));
    cosc = cos(pi / (180 / C));

    printf("%f\n", a*b*sinc / 2);
    printf("%f\n", sqrt(a*a + b*b - 2 * a*b*cosc) + a + b);
    printf("%f\n", b*sinc);

    return 0;
}

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

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

    ALL = [0] * (N+1)
    PATE = [0] * (N+1)
    ALL[0] = 1
    PATE[0] = 1
    for i in range(1, N+1):
        ALL[i] = ALL[i-1] * 2 + 3
        PATE[i] = PATE[i-1] * 2 + 1
    
    def dfs(level, remain):
        if level == 0:
            return 1
        ans = 0
        # バン
        if remain > 0:
            remain -= 1
        # レベルL-1バーガー
        if remain > 0:
            if remain >= ALL[level - 1]:
                remain -= ALL[level - 1]
                ans += PATE[level - 1]
            else:
                ans += dfs(level - 1, remain)
                remain = 0
        # パティ
        if remain > 0:
            remain -= 1
            ans += 1
        # レベルL-1バーガー
        if remain > 0:
            if remain >= ALL[level - 1]:
                remain -= ALL[level - 1]
                ans += PATE[level - 1]
            else:
                ans += dfs(level - 1, remain)
                remain = 0
        # バン
        if remain > 0:
            remain -= 1
        return ans
    
    print(dfs(N, X))

if __name__ == "__main__":
    main()

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

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int a, b;
    cin>>a>>b;
    if(a < b) cout<<"a < b\n";
    else if(a > b) cout<<"a > b\n";
    else cout<<"a == b\n";
    return 0;
}

Measured memory_bytes: 1176
#[allow(unused_macros)]
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 ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
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" ) } ; }

fn main() {
    input! {
        n: u64, a: u64, b: u64
    }

    let mut ret = 0u64;
    for i in 1..n+1 {
        let d = dsum(i);
        if a <= d && d <= b {
            ret += i;
        }
    }
    println!("{}", ret);
}

fn dsum(mut n: u64) -> u64 {
    let mut ret = 0;
    while n > 0 {
        ret += n % 10;
        n /= 10;
    }
    ret
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef __int128_t i128;
typedef long long i64;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define FPEN2 freopen("out.txt", "w", stdout);
#else
#define FPEN
#define FPEN2
#endif
#define Sz(a) ((int)(a).size())
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main(){
  FPEN;
  ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
  string s;cin>>s;
  for(int i=0;i<Sz(s);++i)if(s[i]=='?')s[i]='D';
  cout<<s<<endl;
  //int tot=0;
  //for(int i=0;i<Sz(s);++i){
    //if(s[i]=='?')s[i]='D';
    //if(s[i]=='D'){
      //tot++;
      //if(i-1>=0&&s[i-1]=='P')tot++;
    //}
  //}
  //cout<<tot<<endl;
  
  return 0;
}
//2020.05.30 20:09:32


Measured memory_bytes: 3744
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, _ := strconv.Atoi(nextLine())

	row := nextLine()
	as := make([]int, n)
	array := strings.Split(row, " ")
	for i := 0; i < n; i++ {
		as[i], _ = strconv.Atoi(array[i])
	}

	minCost := 1000000
	for i := -100; i <= 100; i++ {
		cost := 0
		for _, a := range as {
			cost += (a - i) * (a - i)
		}
		if cost < minCost {
			minCost = cost
		}
	}

	fmt.Println(minCost)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define FF first
#define SS second

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	string ss; cin>>ss;
	int n = ss.size();
	for(int i=0;i<n-8;i++) cout<<ss[i];
	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;
int main(){
    int n;
    cin>>n;
    map<int,int>ans;
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                int x=i*i+j*j+k*k+i*j+j*k+k*i;
                if(x<=10000) ans[x]++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(ans.count(i)) cout<<ans.at(i)<<endl;
        else cout<<"0"<<endl;
    }
}

Measured memory_bytes: 3932
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int n, m;
string s;
vector<int> ans;

int main(void) {
  cin >> n >> m >> s;
  
  int pos = n;
  while (pos>0) {
    bool ok = false;
    for (int i=m; i>=1; i--) {
      if (s[pos-i]=='0' || pos-i<=0) {
        if (pos-i<=0) ans.pb(pos);
        else ans.pb(i);
        
        pos = max(pos-i, 0);
        ok = true;
        break;
      }
      
      
    
    }
    if (!ok) {
        puts("-1");
        return 0;
      }
  
  }
  reverse(ans.bg, ans.en);
  for (int i=0; i<sz(ans); i++) {
    if (i>0) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  
  
   return 0;
}



Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  bool ans = false;
  
  for (int i = 1;i <= 9;i++){
    for (int j = 1;j <= 9;j++){
      if (i*j == n){
        ans = true;
      }
    }
  }
  
  if (ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3636
# 解説の要点は2つ
# 1,各桁のbitは独立に決定できる(一番大事)(解説後半)
# 2,K以下で探すように成約を入れる（解説前半）


N, K = list(map(int, input().split()))
A = list(map(int, input().split()))


ans = 0

for i in range(40, -1, -1):
    # print(ans)
    # 桁の大きい方から探索していく.
    power = 1 << i  # i個桁をシフトさせることでi桁目について考えることができる。
    # まずは1の処理からしていこう
    # i番目のビットに1はいくつあるか
    bit_count_of_1 = sum(1 for a in A if a & power != 0)  # この書き方は頭いい

    # 寄与の分岐
    # 注意すべきはpower>Kのときで、ビットは必ず0なので寄与はその時点で決まる。
    if power > K:
        # print(i)
        ans += power * bit_count_of_1
        # print(ans)
    elif bit_count_of_1 > N - bit_count_of_1:
        # その桁で1のほうが多い場合は最適なXは0を与えたほうがいい。0を与えるのはつまり その桁の大きさ×1の個数
        ans += power * bit_count_of_1
    else:
        ans += power * (N - bit_count_of_1)
        K -= power

print(ans)


Measured memory_bytes: 14248
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int dp[3002][3002];
const int mod=998244353;
int32_t main()
{
	int n=in();int S=in();
	vector<int> a(n+1);
	for(int i=1;i<=n;i++)a[i]=in();
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=3000;j++)dp[i][j]=dp[i-1][j];
		
		dp[i][a[i]]=(dp[i][a[i]]+i)%mod;
		for(int j=0;j+a[i]<=S;j++)
		{dp[i][j+a[i]]+=dp[i-1][j];dp[i][j+a[i]]%=mod;}
		
		ans+=dp[i][S];ans%=mod;
		
	}
	
	cout<<ans;
	

}

Measured memory_bytes: 74064
//In The Name Of GOD

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll mod = 998244353;
const ll inf = 2000000000;
const ll infll = (ll)2*1000*1000*1000*1000*1000*1000;
const ll maxn = 8*1001+1;
#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);

int main(){
  IO;
  int ans=0;
  string s,ss;
  cin>>s>>ss;
  for(int i=0;i<3;i++)
    if(s[i]==ss[i])
      ans+=1;
  cout<<ans;
}


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

int main(){
	int n;
	cin >> n;
	int c1 = 0;
	int c2 = 0;
	int c4 = 0;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(a % 4 == 0){
			c4++;
		} else if(a % 2 == 0){
			c2++;
		} else {
			c1++;
		}
	}
	int ok = 1;
	if(c1 > c4 + 1) ok = 0;
	if(c1 == c4 + 1 && c2 > 0) ok = 0;
	cout << (ok ? "Yes" : "No") << endl;
}


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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);


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

    map<char,int> A;
    rep(i,N) {
        char tmp = S[i];
        A[tmp]++;
    }

    ll ans = 1;

    for (auto a: A){
        auto n = a.second;

        ans *= n+1;
        ans %= MOD;
    }

    ans = (ans-1)%MOD;
    cout << ans << endl;    
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
const int LIM = 50;
int n, m, a[LIM], b[LIM], ans;

bool g[LIM][LIM], v[LIM];

void dfs(int d) {
    v[d] = true;
    rep(i, n) {
        if (!g[d][i]) continue;
        if (v[i]) continue;
        dfs(i);
    }
}

int main() {
    cin >> n >> m;
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }

    rep(i, m) {
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;
        rep(i, n) v[i] = false;
        dfs(0);
        rep(i, n) {
            if (v[i] == false) {
                ans++;
                break;
            }
        }
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[200010],n,ans=1e18,s[200010];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",a+i),s[i]=s[i-1]+a[i];
	for(int i=1;i<=n-1;i++)
	  ans=min(ans,abs(s[i]-(s[n]-s[i])));
	printf("%lld\n",ans);



	return 0;
}


Measured memory_bytes: 3328
/* Author : Pranav Deshmukh
            PICT,Pune
   Stay Focused!
*/

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

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define int             long long
#define float           double
#define ms(s, n) 		memset(s, n, sizeof(s))
#define dip(type,var)   type var; cin>>var;
#define dipi(x)         int x; cin>>x;
#define dipi2(x,y)      int x,y; cin>>x>>y;
#define w(x)            int x; cin>>x; while(x--)
#define mka(type,arr,n) type *arr=new type[n];
#define fo(i,n)         for(int i=0;i<n;i++)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mod             1000000007
#define inf             1e18
#define pi              3.141592653589793238
#define endl            "\n"
#define f               first
#define s               second
#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> >

void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	c_p_c();
	int count = 0;
	dipi(n);
	mka(int, arr, n);
	fo(i, n) {
		cin >> arr[i];
	}
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; k++) {
				if (arr[i] + arr[j] > arr[k] && arr[j] + arr[k] > arr[i] && arr[i] + arr[k] > arr[j] && arr[i] != arr[j] && arr[j] != arr[k] && arr[i] != arr[k]) {
					count++;
				}
			}
		}
	}
	cout << count << endl;
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}


Measured memory_bytes: 3808
# input
N, M = map(int, input().split())
connect_nums = []
data = []
for i in range(M):
  tmp = list(map(int, input().split()))
  connect_nums.append(tmp.pop(0))
  data.append(tmp)
switch_conditions = list(map(int, input().split()))

# main
ans = 0
for i in range(2**N):
  on_switches = []
  for j in range(N):
    if ((i >> j) & 1):
      on_switches.insert(0, 1)
    else:
      on_switches.insert(0, 0)
      
  ansflag = True
  
  for l in range(M):
    oncnt = 0
    for ss in data[l]:
      if on_switches[ss-1] == 1:
        oncnt += 1
    if oncnt % 2 != switch_conditions[l]:
      ansflag = False
      break
  
  if ansflag:
    ans += 1
    
# output
print(ans)

# debug
"""
print(N, M)
print(connect_nums, switch_conditions)
print(data)
"""

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *
from copy import *

N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0
for i in range(N-1):
    for j in range(i+1, min(N, i+K+1)):
        dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]))
print(dp[N-1])


Measured memory_bytes: 56432
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int mod=1000000007;

int main() {
  int64_t X,K,D;
  cin>>X>>K>>D;
  X=abs(X);
  int64_t cnt=X/D;//cout<<cnt<<endl;
  if(cnt>=K){cout<<X-K*D<<endl;}
  else {
    if(cnt%2==K%2){cout<<X%D<<endl;}
    else{cout<<abs(X%D-D)<<endl;}
  }
    //cout<<min(X%D,abs(X%D-D))<<endl;}
  return 0;
}


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

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

  if ((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

using namespace std;

// typedef long long ll;

const int lg = 21;

int n, q;
int d[100100];
int up[100100][22];
int col[100100];
int cost[100100];
int ans[100100];
int cnt[100100];
int col_dist[100100];
vector<int> adj[100100];
vector<int> weight[100100];
vector<int> color[100100];
vector<int> query[100100];

int lca(int u, int v) {
    if (d[u] > d[v]) swap(u, v);

    int delta = d[v] - d[u];
    for (int i = 0; i <= lg; i++) {
        if (delta & (1 << i)){
            v = up[v][i];
        }
    }

    if (u == v) return u;

    for (int i = lg; i >= 0; i--) {
        if (up[u][i] != up[v][i]) {
            u = up[u][i];
            v = up[v][i];
        }
    }

    return up[u][0];
}

void dfs(int v, int p, int depth) {
    d[v] = depth;
    up[v][0] = p;
    for (int i = 1; i <= lg; i++) {
        up[v][i] = up[up[v][i - 1]][i - 1];
    }
    for (int i = 0; i < (int)adj[v].size(); i++) {
        if (adj[v][i] == p) continue;
        dfs(adj[v][i], v, depth + 1);
    }
}

void solve(int v, int p, int dist) {
    for (int idx: query[v]) {
        int mul = 1;
        if (idx < 0)  {
            mul = -2;
            idx = -idx;
        }
        ans[idx] += mul * (cnt[col[idx]] * cost[idx] - col_dist[col[idx]] + dist);
    }

    for (int i = 0; i < (int)adj[v].size(); i++) {
        if (adj[v][i] == p) continue;
        cnt[color[v][i]]++;
        col_dist[color[v][i]] += weight[v][i];
        solve(adj[v][i], v, dist + weight[v][i]);
        cnt[color[v][i]]--;
        col_dist[color[v][i]] -= weight[v][i];
    }
}



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

    for (int i = 0; i < n - 1; i++) {
        int u, v, c;
        int w;
        scanf("%d %d %d %d", &u, &v, &c, &w);
        adj[u].push_back(v);
        adj[v].push_back(u);
        color[u].push_back(c);
        color[v].push_back(c);
        weight[u].push_back(w);
        weight[v].push_back(w);
    }

    dfs(1, 0, 0);
    // for (int j = 1; j <= lg; j++) {
    //     for (int i = 1; i <= n; i++) {
    //         up[i][j] = up[up[i - 1][j - 1]][j - 1];
    //     }
    // }

    for (int i = 1; i <= q; i++) {
        int u, v;
        scanf("%d %d %d %d", &col[i], &cost[i], &u, &v);
        query[u].push_back(i);
        query[v].push_back(i);
        query[lca(u, v)].push_back(-i);
        // printf("LCA %d\n", lca(u, v));
    }

    solve(1, 0, 0);

    for (int i = 1; i <= q; i++) {
        printf("%d\n", ans[i]);
    }
}

Measured memory_bytes: 39420
#include <stdio.h>

int main(){
	
	int n,i,j;
	int a[100];
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		}
		for(i=n-1;i>=0;i--){
				printf("%d",a[i]);
				if(i!=0)
				printf(" ");
			}
	    printf("\n");
	    return 0;
}


Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int r0, w0, c, r;

int main()
{
    while (cin >> r0 >> w0 >> c >> r)
    {
        if (r0 == w0 && w0 == c && c == r && r == 0)
            return 0;
        if (r0 >= c * w0)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << (w0 * c - r0 + r - 1) / r << endl;
        }
    }
}


Measured memory_bytes: 3096
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define MSB(bm) ((bm==0)?-1:(63-__builtin_clzll((bm))))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
// #define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
// #define degug(...) 663
#define cerr if(0)cout
#endif
#warning "// FOR has been inclusive now!!!!"
ll A,B;
int main()
{
	ll n; cin >> n; ll ans=0;
	FOR(i,1,n-1) ans+=i;
	cout<<ans<<'\n';
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int a = sc.intarr[0];
            int b = sc.intarr[0];
            int c = sc.intarr[0];
            int x = sc.intarr[0];

            int count = 0;

            for(int i=0; i<=a; i++)
            {
                for(int j=0; j<=b; j++)
                {
                    for(int m=0; m<=c; m++)
                    {
                        int sum = i * 500 + j * 100 + m * 50;
                        if(sum == x)
                        {
                            count++;
                        }
                    }
                }
            }

            wr.wri(count);
        }


    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 11476
import numpy as np
N, D = map(int, input().split(' '))
def parse_list(hoge):
  result = list(map(int, input().split(' ')))
  return np.array(result)
points = list(map(parse_list, range(N)))


def calc_dist(points, i , j ):
    result = np.linalg.norm(points[i] - points[j], ord=2)
    return result

res_cnt = 0
for i in range(N):
    for _j in range(N-i-1):
        j = _j + i + 1
        res = calc_dist(points, i, j )
        if float.is_integer(res):
            res_cnt += 1
print(res_cnt)

Measured memory_bytes: 12444
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    a=[int(input()) for i in range(n)]
    b=[int(input()) for i in range(m)]
    ans=[-1]
    va=100000
    for i in range(n):
        for j in range(m):
            if sum(a)-a[i]+b[j]==sum(b)-b[j]+a[i]:
                if (a[i]+b[j])<va:
                    va=a[i]+b[j]
                    ans=a[i],b[j]
    print(*ans)


Measured memory_bytes: 5604
// -------- START : snippet -------- //

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

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

// -------- START : macro -------- //

#define ll long long
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define len(c) (ll)c.size()
#define all(v) (v).begin(),(v).end()
#define lb(v,x) (lower_bound(all(v),x)-v.begin())
#define ub(v,x) (upper_bound(all(v),x)-v.begin())
#define has(c,x) (c.find(x) != c.end())
#define uniq(v) v.erase(unique(all(v)),v.end())
#define bit(k) (1LL<<(k))
#define INF int(1e9)

template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

// -------- END : macro -------- //

// -------- START : debug macro -------- //

template<class T,class U> ostream& operator<<(ostream& ost, const pair<T,U> &p) { ost << "(" << p.first << ", " << p.second << ")"; return ost; }
#define ostream_container { ost << "{"; for(const auto &t : v) { if (&t != &*v.begin()) ost << ", "; ost << t; } ost << "}"; return ost; }
template<class T> ostream& operator<<(ostream &ost, const vector<T> &v) ostream_container
template<class T> ostream& operator<<(ostream &ost, const set<T> &v) ostream_container
template<class T,class U> ostream& operator<<(ostream &ost, const map<T,U> &v) ostream_container

template<class H> void recursive_debug(string s, H h) {
    cerr << "\033[33m" << s << " = " << h << endl << "\033[m";
}
template<class H,class... T> void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << "\033[33m" << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}
#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)

// -------- END : debug macro -------- //

// -------- END : snippet -------- //

int main(void) {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    int cnt = 0;
    rep(i,n)rep(j,i)rep(k,j){
        if (a[i]+a[j] > a[k] && a[i]+a[k] > a[j] && a[k]+a[j] > a[i] && a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>

int main () {
	int H, W, K;
	scanf("%d", &H);
	scanf("%d", &W);
	scanf("%d", &K);
	char **c;

	c = malloc((1 + H) * sizeof(char*));
	for (int i = 1; i <= H; i++)
	{
		c[i] = malloc((1 + W + 1) * sizeof(char));
		scanf("%s", c[i] + 1);
	}

	// パターンを出す
	int ans = 0;
	for (int i = 0; i <= 1 << H; i++)
	{
		for (int j = 0; j <= 1 << W; j++)
		{
			int count = 0;
			for (int k = 1; k <= H; k++)
			{
				for (int l = 1; l <= W; l++)
				{
					//printf("i: %d, j: %d, k :%d, k_f: %d, l :%d, l_f: %d, (%c), count: %d\n", i, j, k, (i >> (k - 1)) & 1, l, (j >> (l - 1)) & 1, c[k][l], count);
					// 塗り潰されてない
					if (i & 1 << (k - 1) && j  & 1 << (l - 1) && c[k][l] == '#')
						count++;
				}
			}
			if (count == K)
				ans++;
		}
	}
	printf("%d\n", ans);

	return (0);
}


Measured memory_bytes: 1732
M=10**9+7
N=10**5*2
fac=[0]*(N+1)
fac[0]=b=1
for i in range(1,N+1):fac[i]=b=b*i%M
inv=[0]*(N+1)
inv[N]=b=pow(fac[N],M-2,M)
for i in range(N,0,-1):inv[i-1]=b=b*i%M
n,*t=open(0).read().split()
n=int(n)
e=[[]for _ in range(n)]
for a,b in zip(*[map(int,t)]*2):
    e[a-1]+=b-1,
    e[b-1]+=a-1,
o=[]
s=[0]
f=[1]*n
while s:
    v=s.pop()
    f[v]=0
    o+=v,
    l=[]
    for w in e[v]:
        if f[w]:
            l+=w,
            s+=w,
    e[v]=l
sz1,sz2=[0]*n,[0]*n
dp1,dp2=[0]*n,[0]*n
c=[[]for _ in range(n)]
for v in o[::-1]:
    s=1
    c1,c2=[1],[1]
    for w in e[v]:
        u=sz1[w]
        c1+=c1[-1]*dp1[w]*inv[u]%M,
        s+=u
    for w in e[v][::-1]:
        c2+=c2[-1]*dp1[w]*inv[sz1[w]]%M,
    c[v]=c1,c2[::-1]
    sz1[v]=s
    dp1[v]=c1[-1]*fac[s-1]%M
# print(dp1)
sz2[0]=1
dp2[0]=1
for v in o:
    l=len(e[v])
    c1,c2=c[v]
    uv=sz2[v]-1
    tv=dp2[v]*inv[uv]
    for i,w in enumerate(e[v]):
        tw=c1[i]*c2[i+1]%M
        uw=uv+sz1[v]-sz1[w]-1
        dp2[w]=tv*tw*fac[uw]%M
        sz2[w]=uw+2
# print(dp2)
a=[]
for dp1,dp2,sz1,sz2 in zip(dp1,dp2,sz1,sz2):
    sz1-=1
    sz2-=1
    a+=str(dp1*dp2*inv[sz1]*inv[sz2]*fac[sz1+sz2]%M),
print('\n'.join(a))

Measured memory_bytes: 203320
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

cnt = 0
n = int(input())
#if n == 1:
#  print(0)

f_list = factorization(n)

for item in f_list:
  power = item[1]
  counter = 1
  while(True):
    power -= counter
    if power<0:
      break
    cnt+=1
    counter+=1
if n == 1:
  cnt = 0
print(cnt)

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

using S = int;
S op(S a, S b){
    return max(a,b);
}
S e(){
    return -1;
}

int main() {
    int N,K; cin >> N >> K;
    vector<int> A(N);
    REP(i,N){
        cin >> A[i];
    }

    vector<int> dp(N+1,0);
    segtree<S,op,e> seg(400000);
    REP(i,400000){
        seg.set(i,0);
    }

    REP(i,N){
        int next = seg.prod(max(0,A[i]-K), min(400000,A[i]+K+1)) + 1;
        int before = seg.get(A[i]);
        seg.set(A[i], max(before,next) );
    }

    
    cout << seg.all_prod() << endl;
    return 0;
}

Measured memory_bytes: 11212
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>
#include<random>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[200010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc;


int main(){
    cin>>n;
    c=0;
    for(int i=0;i<n;i++){
        cin>>aa[i];
    }
    for(int i=0;i<n;i++){
        cin>>ab[i];
    }
    for(int i=0;i<n;i++){
        if(aa[i]>=ab[i])c+=aa[i]-ab[i];
    }
    C c E;
}



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

typedef long long ll;

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

    int n,k;
    cin >> n >> k;
    vector<int> p(n),sum(n+1,0);
    for(int i=0;i<n;i++){
        cin >> p[i];
        sum[i+1] = sum[i];
        sum[i+1] += p[i];
    }
    ll maxn = 0;
    int idx = 0;
    for(int i=0;i<n-k+1;i++){
        ll val = sum[k+i] - sum[i];
        if(maxn < val){
            maxn = val;
            idx = i;
        }
    }
    double ans = 0.0;
    for(int i=idx;i<idx+k;i++){
        double uku = 0.0;
        for(int j=1;j<p[i]+1;j++){
            uku += j;
        }
        ans += uku / p[i];
    }
    printf("%.12lf\n",ans);
    return 0;
}

Measured memory_bytes: 1792
"use strict";
function main(input) {
    const line = input.split("\n");
    let arr = line[0].split(" ");
    const N = parseInt(arr[0]);
    const M = parseInt(arr[1]);
    const A = line[1].split(" ").map(Number);
    A.sort(function (a, b) {
        return a < b ? 1 : b < a ? -1 : 0;
    });
    const accum = A.reduce((Ai, x) => Ai + x);
    console.log(accum / (4 * M) <= A[M - 1] ? "Yes" : "No");
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

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

  if (S == "AAA" || S == "BBB")
    cout << "No" << endl;
  else
    cout << "Yes" << endl;

  return 0;
}

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

public class Program {
    static Dictionary<int, List<int>> nodes;

    public static void Main() {
        var firstArr = Console.ReadLine().Split(' ').ToArray().Select(i => int.Parse(i)).ToArray();
        var n = firstArr[0];
        var m = firstArr[1];

        nodes = new Dictionary<int, List<int>>();

        for (int i = 1; i <= n; i++) {
            nodes.Add(i, new List<int>());
        }

        for (int i = 0; i < m; i++) {
            var arr = Console.ReadLine().Split(' ').ToArray().Select(a => int.Parse(a)).ToArray();
            nodes[arr[0]].Add(arr[1]);
            nodes[arr[1]].Add(arr[0]);
        }

        Console.WriteLine(CountRoute(1, new List<int>()));
    }

    static int CountRoute(int nowNodeNumber, List<int> checkedNumbers) {
        checkedNumbers.Add(nowNodeNumber);
        var nextNodes = nodes[nowNodeNumber].Where(i => !checkedNumbers.Exists(e => e == i));

        if (nextNodes.Count() == 0) {
            return checkedNumbers.Count == nodes.Count() ? 1 : 0;
        }
        
        return nextNodes.Select(i => CountRoute(i, new List<int>(checkedNumbers))).Sum();
    }
}

Measured memory_bytes: 15680
class Segment_Tree():
    def __init__(self,N,calc,unit,L=[]):
        """calcを演算とするN項のSegment Treeを作成

        N:要素数
        calc:演算(2変数関数,モノイド)
        unit:モノイドcalcの単位元 (xe=ex=xを満たすe)
        """
        self.calc=calc
        self.unit=unit

        N=max(N,len(L))

        d=max(1,(N-1).bit_length())
        k=2**d

        X=[unit]*(k-1)+L+[unit]*(k-len(L))

        self.num=k
        self.depth=d

        for i in range(k-2,-1,-1):
            X[i]=calc(X[2*i+1],X[2*i+2])

        self.data=X

    def index(self,k,index=0):
        return self.data[(self.num-1)+(k-index)]

    def update(self,k,x,index=0):
        """第k要素をxに変え,更新を行う.

        k:数列の要素
        x:更新後の値
        """

        m=(self.num-1)+(k-index)
        self.data[m]=x

        for _ in range(self.depth):
            m=(m-1)//2
            self.data[m]=self.calc(self.data[2*m+1],self.data[2*m+2])


    def sub_array(self,From,To,index=0,left_closed=True,right_closed=True):
        A=From-index+(not left_closed)
        B=To-index-(not right_closed)

        return self.__sub_array_second(A,B+1,0,0,self.num)

    def __sub_array_second(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.unit
        elif a<=l and r<=b:
            return self.data[k]
        else:
            alpha=self.__sub_array_second(a,b,2*k+1,l,(l+r)//2)
            beta=self.__sub_array_second(a,b,2*k+2,(l+r)//2,r)
            return self.calc(alpha,beta)

    def all_prod(self):
        return self.data[0]

    def max_right(self,l,r,cond,index=0):
        """以下の2つをともに満たすxの1つを返す.\n
        (1) r=l or cond(data[l]*data[l+1]*...*d[r-1]):True
        (2) r=x or cond(data[l]*data[l+1]*...*data[r]):False
        ※fが単調減少の時,cond(data[l]*...*data[r-1])を満たす最大のrとなる.

        cond:関数(引数が同じならば結果も同じ)
        cond(unit):True
        0<=l<=r<=n
        """
        l-=index
        #assert 0<=l<=r<=self.num,"添字が範囲外"
        #assert cond(self.unit),"単位元が条件を満たさない."

        if l==r:
            return r+index

        l+=(self.num-1)
        sm=self.unit

        calc=self.calc
        while True:
            while l%2:
                l=(l-1)>>1

            if not cond(calc(sm,self.data[l])):
                while l<self.num-1:
                    l=2*l+1

                    if cond(calc(sm,self.data[l])):
                        sm=calc(sm,self.data[l])
                        l+=1

                return min(l-(self.num-1)+index,r)

            sm=calc(sm,self.data[l])
            l+=1

            m=l+1
            if not (m&(-m) !=m):
                break

        return r+index
#================================================
N,Q=map(int,input().split())
A=list(map(int,input().split()))

S=Segment_Tree(N,lambda x,y:max(x,y),0,A)

X=[]
for _ in range(Q):
    T,alpha,beta=map(int,input().split())

    if T==1:
        S.update(alpha,beta,1)
    elif T==2:
        X.append(S.sub_array(alpha,beta,1))
    else:
        X.append(S.max_right(alpha,N,lambda x:x<beta,1))

print("\n".join(map(str,X)))


Measured memory_bytes: 132400
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cctype>
#include <cstdio>
#include <math.h>
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
const int AMAX = 100000; 
using namespace std;
#define rep(i, n) for (i64 i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (i64 i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define down(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
using LL = long long;
using ULL = unsigned long long;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
 
int main()
{
LL a, b, c,d;
cin >> a >> b >> c >> d;
if(abs(a-c)<=d||(abs(b-c)<=d&&abs(a-b)<=d))
{
 cout <<"Yes";
}else{
 cout<<"No";
}
}

Measured memory_bytes: 256