akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>

using namespace std;

char s[1001];

int main() {
    int n, f1 = 0, f2 = 0, i;
    
    scanf("%s", s);
    
    n = strlen(s);
    
    for (i = 0; i < n; i++) {
        if (s[i] == 'N') {
            f1 |= 1;
        } else if (s[i] == 'W') {
            f2 |= 1;
        } else if (s[i] == 'S') {
            f1 |= 2;
        } else {
            f2 |= 2;
        }
    }
    
    if ((f1 == 0 || f1 == 3) && (f2 == 0 || f2 == 3)) {
        puts("Yes");
    } else {
        puts("No");
    }
    
    return 0;
}


Measured memory_bytes: 128
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).
*/

main :-
    get_number(A),
    get_number(B),
    get_number(C),
    X is max(0, C - (A - B)),
    writeln(X).


Measured memory_bytes: 8184
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = readln.chomp.split.to!(int[]);
  auto ave = a.sum / n.to!double;
  int res;
  double minVal = double.max;
  foreach (i; 0..n) {
    auto d = abs(ave - a[i]);
    if (minVal > d) {
      minVal = d;
      res = i;
    }
  }
  res.writeln;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

int main() {
	int  N; cin >> N;
	vector<int> vec(N);
	rep(i, N) cin >> vec[i];

	sort(ALL(vec));
	int Amax = vec[N - 1];
	vector<bool> table(Amax + 1, true); //1-index
	vector<bool> isIndependent(Amax + 1, false);

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			if (vec[i] != vec[i + 1]) {
				isIndependent[vec[i]] = true;
			}
		}
		else if (i < N - 1) {
			if (vec[i] != vec[i - 1] && vec[i] != vec[i + 1]) {
				isIndependent[vec[i]] = true;
			}
		}
		else {
			if (vec[i] != vec[i - 1]) {
				isIndependent[vec[i]] = true;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		int Ai = vec[i];

		if (table[Ai] == true) {
			if (isIndependent[Ai] == true) ans++;
			int temp = Ai;
			while (temp < Amax + 1) {
				table[temp] = false;
				temp += Ai;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 4268
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int m, d;
    cin >> m >> d;
    int x[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    cout << (d == x[m - 1]);
    return 0;
}


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

vector<int> ret(int v,int n){
  n-=v;
  vector<int> r(4);
  r[3]=n/500; n%=500;
  r[2]=n/100; n%=100;
  r[1]=n/50; n%=50;
  r[0]=n/10;
  return r;
}
int main(){
  int n;
  int t[] = {10,50,100,500};
  int T = 0;
  while(cin>>n,n){
    vector<int> c(4);
    for(int i=0;i<4;++i) cin >> c[i];
    int s = c[0]*10+c[1]*50+c[2]*100+c[3]*500;
    vector<int> r = ret(n,s);
    if(T) cout << endl;
    for(int i=0;i<4;++i){
      if(c[i]-r[i]>0) cout << t[i] << " " << c[i]-r[i] << endl;
    }
    ++T;
  }
  return 0;
}

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

int n;
int a[200005];
bool cmp(const int x,const int y)
{
	return x>y;
}
int main()
{
	cin>>n;
    for(int i=0;i<n;i++)
		cin>>a[i];
    sort(a,a+n,cmp);
    int tot=n-1;
    long long ans=0;
    for(int i=0;i<n;i++)
	{
        if(tot)
		{
            ans+=a[i];
            tot--;
        }
        if(tot && i){
            ans+=a[i];
            tot--;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4368
#define w 200001
i;x;y;p;main(n,m,j,u){
  long int k,a[w],A[w],b[w],B[w];
  for(scanf("%d%d%ld",&n,&m,&k);x<n;x++)scanf("%ld",&a[x]),A[x+1]=A[x]+a[x];
  for(;y<m;y++)scanf("%ld",&b[y]),B[y+1]=B[y]+b[y];
  
  for(j=u=m;i<=n;i++){
    if(A[i]>k)break;
    for(;j+1;j--){if(A[i]+B[j]<=k){if(i+j>p)p=i+j;u=j;break;}}
  }
  printf("%d",p);
}

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

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

    string n;
    cin >> n;
    string s = n;
    string temp = s;
    s.front() = n.back();
    s.back() = temp.front();
    if (n == s) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

Measured memory_bytes: 256
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int x = sc.nextInt();
        
        for (int i = -1000; i <= 1000; i++) {
            for (int h = -1000; h <= 1000; h++) {
                
                if (x == (Math.pow(i, 5) - Math.pow(h, 5)) ) {
                    System.out.println(i + " " + h);
                    return;
                }
            }
        }
        
    }
}

Measured memory_bytes: 38828
#include <stdio.h>
 
 
int main()
{
    int a,b;

    scanf("%d%d",&a,&b);

    if (a < b)  printf ("a < b\n");

    else if (a > b)  printf ("a > b\n");

    else if(a == b)  printf ("a == b\n");
  
    return 0;
}

 

Measured memory_bytes: 1744
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int n = Integer.parseInt(stdin.readLine());
        int[] x = new int[n];
        int[] y = new int[n];
        Pattern space = Pattern.compile(" ");
        for (int i = 0; i < n; i++) {
            int[] line = space.splitAsStream(stdin.readLine()).mapToInt(Integer::parseInt).toArray();
            x[i] = line[0];
            y[i] = line[1];
        }

        Map<Tuple, Integer> counter = new HashMap<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    continue;
                }

                int p = x[i] - x[j];
                int q = y[i] - y[j];
                Tuple key = new Tuple(p, q);
                counter.put(key, counter.getOrDefault(key, 0) + 1);
            }
        }

        int max = counter.values().stream().max(Comparator.naturalOrder()).orElse(0);
        System.out.println(n - max);
    }

    private static class Tuple {
        private int x;
        private int y;
        public Tuple(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (o == null || !(o instanceof Tuple)) {
                return false;
            }

            Tuple that = (Tuple)o;
            return this.x == that.x && this.y == that.y;
        }

        @Override
        public int hashCode() {
            return Objects.hash(x, y);
        }

        @Override
        public String toString() {
            return String.format("[x=%d, y=%d]", x, y);
        }
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 26708
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int A[n];
    for (int i = 0; i < n; ++i) cin >> A[i];
    sort(A, A+n);
    int d = abs(A[0] - A[1]);
    for (int i = 1; i < n; ++i) d = min(d, abs(A[i]-A[i-1]));
    cout << d << endl;
  }
  return 0;
}

Measured memory_bytes: 3140
let () =
  try
    while true do
      let (x1, y1, x2, y2, x3, y3, xp, yp) =
        Scanf.scanf "%f %f %f %f %f %f %f %f " (fun x1 y1 x2 y2 x3 y3 xp yp ->
          x1, y1, x2, y2, x3, y3, xp, yp) in
      let pa = (x1 -. x3) *. (yp -. y1) -. (y1 -. y3) *. (xp -. x1) in
      let pb = (x2 -. x1) *. (yp -. y2) -. (y2 -. y1) *. (xp -. x2) in
      let pc = (x3 -. x2) *. (yp -. y3) -. (y3 -. y2) *. (xp -. x3) in
      print_endline
        (if pa > 0. && pb > 0. && pc > 0. || pa < 0. && pb < 0. && pc < 0. then "YES" else "NO")
    done
  with _ -> ()

Measured memory_bytes: 2260
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
//#define mod 1000000007
#define PI acos(-1.0)
const long long MAX=200005;
typedef long long ll;
//const int INF=0x3f3f3f3f;
//int d[8][2]={-1,0,0,-1,0,1,1,0,1,1,-1,-1,-1,1,1,-1};
int n,m,t=0;
char b[9]={'A','K','I','H','A','B','A','R','A'};
char s[100005];
int a[5]={0};
int main()
{
    scanf("%s",&s);
    int l=strlen(s);
    for(int i=0;i<l;i++)
    {
        a[s[i]-'a']++;
    }
    int k=min(a[0],min(a[1],a[2]));
    for(int i=0;i<3;i++)
    {
        if(a[i]-k>=2)
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
ll dp[3000000]={};
ll expo(ll a,ll b){ll r=1;a=a%mod;while(b){if(b%2)r=(r*a)%mod;a=(a*a)%mod;b=b/2;}
return r;}
int main(){
	ll n;
	cin>>n;
	dp[0]=1;
	ll a[n+1][n+1]={};
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)
		cin>>a[i][j];
	}
	for(ll i=0;i<(expo(2,n));i++){
		ll z=i,k=0;
		/*while(z){
			if(z%2)
			k++;
			z=z/2;
		}*/
		z=i;
		k=(ll)__builtin_popcount(i);
		ll cc=0;
		for(ll j=0;j<n;j++){
			if((z & (1<<j))==0){
				if(a[k][j]==1){
					//cc++;
					dp[(z | (1<<j))]=(dp[(z | (1<<j))]+dp[z])%mod;
				}
			}
		}
		//dp[k+1]=(dp[k+1]+(dp[k]))%mod;
	}
	cout<<dp[expo(2,n)-1];
	return 0;
}

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

int main()
{
    char al;
    cin >> al;
    string AL = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ai = "abcdefghijklmnopqrstuvwxyz";
    for (int i = 0; i < AL.size();i++)
    {
        if(al==ai.at(i))
        {
            cout << 'a' << endl;
            break;
        }
        else if (al == AL.at(i))
        {
            cout << 'A' << endl;
            break;
        }
    }
}


Measured memory_bytes: 3628
#include <stdio.h>
int main(void)
{
	long long int a,b,x,i,j;
	scanf("%lld%lld%lld",&a,&b,&x);
	if(a%x==0){
		i=a;
	}else{
		i=a/x*x+x;
	}
	if(b%x==0){
		j=b;
	}else{
		j=b/x*x;
	}
	printf("%lld\n",(j-i)/x+1);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){

	char c;
	int num;
	int n,i;
	int S[13] = {0};
	int H[13] = {0};
	int C[13] = {0};
	int D[13] = {0};

	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf(" %c", &c) ;
		scanf("%d",&num);

		if(c == 'S')
			S[num-1] = 1;
		else if(c == 'H')
			H[num-1] = 1;
		else if(c == 'C')
			C[num-1] = 1;
		else if(c == 'D')
			D[num-1] = 1;
	}
	for(i=0; i<13; i++){
		if(S[i] == 0)
			printf("S %d\n",(i+1));
	}
	for(i=0; i<13; i++){
		if(H[i] == 0)
			printf("H %d\n",(i+1));
	}
	for(i=0; i<13; i++){
		if(C[i] == 0)
			printf("C %d\n",(i+1));
	}
	for(i=0; i<13; i++){
		if(D[i] == 0)
			printf("D %d\n",(i+1));
	}

	return 0;
}

Measured memory_bytes: 596
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = (double)sc.nextInt();
		double b = (double)sc.nextInt();
		double average = (a+b)/2;
		if(average-(int)average>=0.5){
			System.out.println((int)average+1);
		}else{
			System.out.println((int)average);
		}
	}
}

Measured memory_bytes: 19924
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	cin >> S;
	int ans = INF;
	rep(i, 0, SZ(S) - 2)
	{
		string ts = S.substr(i, 3);
		stringstream ss;
		int n;
		ss << ts;
		ss >> n;
		chmin(ans, abs(753 - n));
	}

	cout << ans << endl;

	return 0;
}

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

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

int main() {
  int N,d,n,left,right,top,bottom;
  int pos[200][2];
  while(cin >> N) {
    if(N == 0) break;
    memset(pos,0,sizeof(pos));
    left = 0;right = 0;top = 0;bottom = 0;
    for(int i=1;i<N;i++) {
      cin >> n >> d;
      pos[i][0] = pos[n][0] + dx[d]; // x
      pos[i][1] = pos[n][1] + dy[d]; // y
      left = min(left,pos[i][0]);
      right = max(right,pos[i][0]);
      top = max(top,pos[i][1]);
      bottom = min(bottom,pos[i][1]);
    }
    cout << right - left + 1 << " " << top - bottom + 1 << endl;
  }
}

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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int n, ans = 0; string s; cin >> n >> s;

    for(int i = 1; i < n; i++) {
        int d = 1;
        for(int j = 0; i + j < n; j++) {
            if(s[j] == s[i+j]) ans = max(ans, min(i, d++));
            else d = 1;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3632
import math
N,M=map(float,input().split())


a=math.factorial(N)*math.factorial(M)
if abs(N-M)>1:
    print(0)
elif abs(N-M)==1:
    print(int(a%(1000000000+7)))
elif M==N:
    print(int(a*2%(1000000000+7)))
    


Measured memory_bytes: 5196
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	if abs(a, c) <= d {
		fmt.Println("Yes")
		return
	}
	if abs(a, b) <= d && abs(b, c) <= d {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func abs(a, b int) int {
	v := a - b
	if v < 0 {
		return -v
	}
	return v
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

  int N;
  cin >> N;
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++)cin >>B[i];
  
  int ans = B[0]+B.back();
  for(int i= 0;i<N-2;i++){
  ans += min(B[i],B[i+1]);
  }
  cout << ans<<endl;

}

Measured memory_bytes: 256
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

string to_string(const string& s) { return '"' + s + '"'; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
    #define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 3
#endif
 
#define cin_exception cin.exceptions(cin.failbit);
#define cout_precision cout.setf(ios::fixed); cout.precision(15);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using ll = int_fast64_t; using ld = long double;

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

void solve() {
    set<int> s;
    for (int i = 0; i < 3; ++i) {
        int x; cin >> x;
        s.insert(x);
    }
    if (s.size() == 2) cout << "Yes\n";
    else cout << "No\n";
}


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


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x,y;
  cin >> x >> y;
  if(x < y) cout << 0 << endl;
  else cout << 10 << "\n";
  return 0;
}


Measured memory_bytes: 892
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll mult(ll a,ll n)  //求a^n%mod
{
    ll s=1;
    while(n)
    {
        if(n&1)s=s*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return s;
} //mult(a,n-2);

int permutation(ll n, ll x) {
    ll res = 1, pos = 1, xk = 1;;
    for (ll i = n; i >= n - x + 1; i--) {
        res = ((res % mod* i % mod ) % mod * mult(pos, mod - 2) % mod ) % mod;
        pos++;
    }
   // cout << res % mod<<"   "<< xk << "  x    \n";
    return res % mod ;

}
int quickmod(ll a, ll n) {
    ll res = 1;
    a = a % mod;
    while (n) {
        if (n & 1) res = (res % mod * a % mod) % mod;
        a = (a % mod* a % mod) % mod;
        n >>= 1;
    }
    return res % mod;
}
int main () {
    ll n, x1, x2;
    cin >> n >> x1 >> x2;
    ll res =  ( quickmod(2,n) - 1 - permutation(n, x1) - permutation(n, x2) + mod + mod) % mod;
  //  cout << quickmod(2,n) << " quickmod    " <<  permutation(n, x1) << " x1  " << permutation(n, x2 )  << " x2   \n";
    cout << res;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define NMAX 300005
using namespace std;
typedef long long ll;
ll segmTree[NMAX*4],l[NMAX*4],r[NMAX*4],leaves[NMAX];
void init(size_t nd){
    if(nd==0) l[0]=0,r[0]=NMAX-1;
    else{
        if(nd&1) l[nd]=l[nd/2],r[nd]=(l[nd/2]+r[nd/2])/2;
        else l[nd]=r[nd-1]+1,r[nd]=r[nd/2-1];
    }
    if(l[nd]==r[nd]) leaves[l[nd]]=nd;
    else{
        init(nd*2+1);
        init(nd*2+2);
    }
}
void upd(ll p, ll x){
    ll nd=leaves[p];
    if(segmTree[nd]>=x)
        return;
    segmTree[nd]=x;
    do{
        nd=(nd-1)/2;
        segmTree[nd]=max(segmTree[nd*2+1],segmTree[nd*2+2]);
    }while(nd>0);
}
ll query(ll L, ll R){
    ll ans=0;
    while(L<=R){
        ll nd=leaves[L];
        while(nd>0 && l[(nd-1)/2]>=L && r[(nd-1)/2]<=R)
            nd=(nd-1)/2;
        ans=max(ans,segmTree[nd]);
        L=r[nd]+1;
    }
    return ans;
}
ll dp[NMAX],v[NMAX];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    init(0);
    ll n,k,ans=0;
    cin>>n>>k;
    for(ll i=0;i<n;i++)
        cin>>v[i];
    for(ll i=n-1;i>=0;i--){
        dp[i]=query(max(0ll,v[i]-k),min((ll)NMAX-1,v[i]+k))+1;
        upd(v[i],dp[i]);
        ans=max(ans,dp[i]);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 35224
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

///////////////////////////////////////////////////////////////////////////

int main(){
	int n,l[205] ={};
    cin >> n;
    ull cnt = 0;

    rep(i,0,2*n)cin >> l[i];
    sort(l,l+(2*n));

    rep(i,0,2*n){
        cnt += l[i];
        i++;
    }
    cout <<cnt <<endl;
	return  0;
}

Measured memory_bytes: 256
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 10000)

func readLine() string {
	buf := make([]byte, 0, 10000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	input := strings.Split(readLine(), " ")
	a, _ := strconv.Atoi(input[0])
	b, _ := strconv.Atoi(input[1])
	t, _ := strconv.Atoi(input[2])

	var ans, time, count int
	count++

	for {
		time = a * count
		if float64(time) > float64(t)+0.5 {
			break
		}
		ans += b
		count++
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
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("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let s: Vec<char> = read::<String>().chars().collect();
    let mut is_white = s[0] == 'W';
    let mut ret = 0;
    for c in &s {
        if ('B' == *c && is_white) || ('W' == *c && !is_white) {
            is_white = !is_white;
            ret += 1;
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 2668
#define errOut(s) { std::cerr << "LINE:" << __LINE__ << " " << #s << " = " << s << std::endl; }

#include <bits/stdc++.h>

using namespace std;

#ifndef errOut
#define errOut(s)
#endif

using Value = int64_t;

struct ValueInfo {
    Value value;
    int idx;
};

std::vector<Value> calc(const std::vector<Value> &as) {
    auto n = static_cast<const int>(as.size());
    auto m = n  / 2;
    std::vector<Value> ret(n, 0);
    std::vector<ValueInfo> valueInfos(n, ValueInfo());

    for (int i = 0; i < n; ++i) {
        valueInfos[i].value = as[i];
        valueInfos[i].idx = i;
    }
    std::sort(valueInfos.begin(), valueInfos.end(), [](const ValueInfo& x, const ValueInfo& y) {
       return x.value < y.value;
    });
    std::vector<int> infoIdxes(n, 0);
    for (int i = 0; i < n; ++i) {
        infoIdxes[valueInfos[i].idx] = i;
    }
    for (int i = 0; i < n; ++i) {
        if (infoIdxes[i] >= m) {
            ret[i] = valueInfos[m - 1].value;
        } else {
            ret[i] = valueInfos[m].value;
        }
    }
    return ret;
}

int main() {
    int n;
    std::cin >> n;
    std::vector<Value> as(n, 0);
    for (int i = 0; i < n; ++i) {
        std::cin >> as[i];
    }
    auto ret = calc(as);
    for (int i = 0; i < n; ++i) {
        std::cout << ret[i] << std::endl;
    }
    return 0;
}


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

int main() {
  int s;
  cin >> s;
  int s1 = s / 100;
  int s_10 = s % 100;
  int s2 = s_10 / 10;
  int s3 = s_10 % 10;
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
    string s1,s2;
    cin>>s1>>s2;
    ll n=s1.length(),f=0;
    f(i,n)
    {
        if(s1[i]!=s2[i])
        {
            f=1;
            break;
        }
    }
    if(f==1)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3640
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>

using namespace std;

const int INF = 1000000007;

template<class T> void gc(T &x)
{
    int k, s = 0;
    x = 0;

    k = getchar_unlocked();

    if (k == '-') s = 1;
    else if ('0' <= k && k <= '9')  x = k - '0';

    while (true)
    {
        k = getchar_unlocked();

        if (k < '0' || k > '9') break;
        x = x * 10 + k - '0';
    }

    if (s) x = -x;
}

// aとbを掛けた値をmodする(a * b mod p)
int modmulti(int a, int b)
{
    int res = 0;
    int mod = a % INF;
    while (b > 0)
    {
        if ((b & 1) == 1)
        {
            res += mod;
            if (res > INF)
            {
                res -= INF;
            }
        }
        mod <<= 1;
        if (mod > INF)
        {
            mod -= INF;
        }
        b >>= 1;
    }
    return res;
}

// aとbを足した値をmodする(a + b mod p)
int modadd(int a, int b)
{
    return (a + b) % INF;
}

int main()
{
    int n, m;

    gc(n);
    gc(m);

    int x;
    int xsum = 0;
    for (int i = 0; i < n; i++)
    {
        gc(x);

        int t1 = 2 * i - n + 1;
        int s1 = 1;
        if (((t1 < 0) && (0 < x)) || ((x < 0) && (0 < t1))) s1 = -1 * s1;

        int t2 = t1 == 0 ? 0 : x == 0 ? 0 : s1 * modmulti(abs(t1), abs(x));
        xsum = modadd(xsum, t2);
    }

    int y;
    int ysum = 0;
    for (int i = 0; i < m; i++)
    {
        gc(y);

        int t1 = 2 * i - m + 1;
        int s1 = 1;
        if (((t1 < 0) && (0 < y)) || ((y < 0) && (0 < t1))) s1 = -1 * s1;

        int t2 = t1 == 0 ? 0 : y == 0 ? 0 : s1 * modmulti(abs(t1), abs(y));
        ysum = modadd(ysum, t2);
    }

    printf("%d\n", modmulti(xsum, ysum));
    return 0;
}


Measured memory_bytes: 128
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int  r, c, black; 
    cin>> r >> c >> black; 
    for (int i=0;i<=r;i++)
    	for (int j=0;j<=c;j++)
    		if (i*c+j*r-2*i*j==black) cout << "Yes" << endl,exit(0) ; 
    cout << "No" << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3620
n = int(input())
a = list(map(int, input().split()))
s = list(set(a))
d = {str(si): 0 for si in s}

for ai in a:
    d[str(ai)] += 1

cd = dict()
for k, v in d.items():
    cd[k] = v*(v-1)//2

sm = sum(list(cd.values()))

for ai in a:
    di = d[str(ai)]
    print(sm - cd[str(ai)] + (di-1)*(di-2)//2)

Measured memory_bytes: 38844
n = int(input())
d = dict()
p = []
for i in range(n):
    x,y = map(int,input().split())
    for j in p:
        if str(x-j[0])+" "+str(y-j[1]) in d:
            d[str(x-j[0])+" "+str(y-j[1])] += 1
        else:
            d[str(x-j[0])+" "+str(y-j[1])] = 1
        if str(j[0]-x)+" "+str(j[1]-y) in d:
            d[str(j[0]-x)+" "+str(j[1]-y)] += 1
        else:
            d[str(j[0]-x)+" "+str(j[1]-y)] = 1
    p.append([x,y])

if len(d.values()) == 0:
    ans = 0
else:
    ans = max(d.values())
print(n-ans)


Measured memory_bytes: 3316
process.stdin.resume();
process.stdin.setEncoding('utf8');

var stdin = '';
process.stdin.on('data', function (chunk) {
  stdin += chunk;
}).on('end', function() {
  var lines = stdin.trim().split('\n');
  var numStr = lines[0].split(' ');
  var num = numStr[0]
  var numLength = num.length;
  var total = 0;
  for(var i = 0; i < numLength; i++) {
    if('1' === num[i]) {
      total += Number(num[i])
    }
  }
  console.log(total);
});


Measured memory_bytes: 7500
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#define ull unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
void close(){
   	std::ios::sync_with_stdio(false);
   	std::cin.tie(0);
}
const int maxn=1e5+10;
int h,w;
char ma[25][25];
bool vis[25][25];
int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};
struct node{
	int x,y,s;
};
node n;
void init(int x,int y,int s){
	n.x=x;
	n.y=y;
	n.s=s;
}
int bfs(int sx,int sy,int gx,int gy){
	init(sx,sy,0);
	queue <node> q;
	q.push(n);
	memset(vis,false,sizeof(vis));
	vis[sx][sy]=true;
	while(!q.empty()){
		n=q.front();
		q.pop();
		int x=n.x;
		int y=n.y;
		int s=n.s;
		if(x==gx&&y==gy) {
			//cout<<s<<endl;
			return s;
		}

		for(int i=0;i<4;i++){
			int xx=x+dx[i];
			int yy=y+dy[i];
			if(xx<0||xx>=h||yy<0||yy>=w) continue;
			if(ma[xx][yy]=='#') continue;
			if(vis[xx][yy]) continue;
			init(xx,yy,s+1);
			q.push(n);
			vis[xx][yy]=true;
		}
	}
	return -1;
}
int main(){
	cin>>h>>w;
	for(int i=0;i<h;i++){
		cin>>ma[i];
	}
	int ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(ma[i][j]=='#') continue;
			for(int k=0;k<h;k++){
				for(int l=0;l<w;l++){
					if(ma[i][j]=='#') continue;
					int s=bfs(i,j,k,l);
					ans=max(ans,s);
				}
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll strlength(const char *s) {
	ll l = 0;
	while (*s++)l++;
	return l;
}

int main()
{
	char O[50], E[50]; cin >> O >> E;
	rep(i, 0, 50) {
		if (O[i])	cout << O[i];
		if (E[i])	cout << E[i];
		if (!O[i] || !E[i])break;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
(function main() {
  const n = Number(require('fs').readFileSync('/dev/stdin', 'utf8'));

  const cache = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144];
  const fib = function fib(n) {
    return cache[n] || (cache[n] = fib(n - 1) + fib(n - 2));
  };
  console.log(fib(n));
})();



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

int main() {
  int n;
  string s;
  cin >> n >> s;
  bool ans = false;
  
  if(n%2==0){
    for(int i = 0; i < n/2; i++){
      if(s.at(i)==s.at(n/2+i)){
        ans = true;
      }
      else{
        ans = false;
        break;
      }
    }
  }
  
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i,n) for(int (i)=0; (i)<n; ++(i))
#define rep1(i,n) for(int (i)=1; (i)<=n; ++(i))
#define repU(i,bottom,ceiling) for(int (i) = (bottom); (i) <= (ceiling); ++(i))
#define repD(i,ceiling,bottom) for(int (i) = (ceiling); (i) >= (bottom); --(i))
#define pub push_back
#define pob pop_back
#define prf printf
#define scf scanf
#define mkp make_pair
#define fir first
#define sec second
#define clr(a) memset((a),0,sizeof(a))

typedef long long ll;
typedef double db;

const vector<pair<int,int>> DIR = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF = -1 + (1<<30);
const int MOD = (int)1e9 + 7;

template<typename T> inline T gcd(T a,T b){ if(a % b){ return gcd(b,a % b); }else{ return b; } }

template<typename T> inline T lcm(T a,T b){ return a / gcd(a,b) * b; }

inline long long Pow(const long long n,long long m,const int mod = MOD){
	long long res = 1,pow = n;
	while(m) {
		if(m & 1) res = (res * pow) % mod;
		pow = (pow * pow) % mod;
		m >>= 1;
	}
	return res;
}

inline vector<long long> Frac(const int range,const int mod = MOD){
	vector<long long> frac;
	frac.push_back(1);
	for(int i = 1; i <= range; ++i) frac.push_back((long long)frac.back() * i % mod);
	return frac;
}

vector<long long> frac;

inline long long Comb(const int n,const int m,const int mod = MOD){
	if(n < m || m < 0) return 0;
	//vector<long long> frac(Frac(n,mod));
	long long rev = Pow((long long)frac[m] * frac[n-m] % mod,mod-2,mod);
	return rev * frac[n] % mod;
}

template<typename T> inline bool v_find(const vector<T> v,const T obj){
	auto itr = find(v.begin(), v.end(), obj);
	size_t index = distance(v.begin(),itr);
	if (index != v.size()) { return true; }
	return false; 
}

template<typename T> inline bool v_erase(vector<T> &v,const T obj){
	auto itr = find(v.begin(), v.end(), obj);
	size_t index = distance(v.begin(),itr);
	if (index != v.size()) {
		v.erase(itr);
		return true;
	}
	return false;	
}

template<class T,class U> inline auto LB(const T v,const U in){ return lower_bound(v.begin(),v.end(),in); }

template<class T,class U> inline auto UB(const T v,const U in){ return upper_bound(v.begin(),v.end(),in); }

inline unsigned long long nextsub(unsigned long long sub){
	unsigned long long tem = sub + (sub & -sub);
	unsigned long long btm = (~(tem) & sub) / (sub & -sub);
	return btm | tem;
}

inline void solve(){
	int a,b; cin>>a>>b;
	if(!(a%3)||!(b%3)||!((a+b)%3)) cout<<"Possible";
	else cout<<"Impossible";
	return;
}

inline void input(){

	return;
}

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





Measured memory_bytes: 256
import java.util.*;

public class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		
		if((r*100+g*10+b)%4 == 0){
			System.out.println("YES");
		} else{
			System.out.println("NO");
		}
	}
}

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

int gcd(int x, int y) {
  if (y == 0ll)
    return x;
  else
    return gcd(y, x % y);
}

signed main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (auto &&w : a)
    cin >> w;

  b[0] = a[0];
  c[n - 1] = a[n - 1];
  for (int i = 0; i < n - 1; i++) {
    b[i + 1] = gcd(b[i], a[i + 1]);
  }
  for (int i = n - 1; i > 0; i--) {
    c[i - 1] = gcd(c[i], a[i - 1]);
  }
  int ans = max(b[n - 2], c[1]);
  for (int i = 0; i < n - 2; i++) {
    int t = gcd(b[i], c[i + 2]);
    ans = max(ans, t);
  }
  cout << ans << endl;
  // for (auto &&w : b) cout << w << " ";
  // cout << endl;
  // for (auto &&w : c) cout << w << " ";
  // cout << endl;
  // cout << c[1] << " " << b[n - 2] << endl;
}

Measured memory_bytes: 2560
n = int(input())

dic = {}
for i in range(1, n+1):
    s = str(i)
    i0 = int(s[0])
    i1 = int(s[-1])
    k = (i0, i1)
    if k in dic:
        dic[k] += 1
    else:
        dic[k] = 1

m = 0
for k, n in dic.items():
    i0, i1 = k
    kk = (i1, i0)
    if kk in dic:
        m += n * dic[kk]

print(m)


Measured memory_bytes: 3060
n, m = map(int, input().split())
A = []
B = []
for i in range(n):
  A.append(input())
for i in range(m):
  B.append(input())

ans = False
for iy in range(0, n-m+1):
  if ans:
    break
  for ix in range(0, n-m+1):
    tmp = True
    for y in range(0, m):
      for x in range(0, m):
        if A[iy+y][ix+x] != B[y][x]:
          tmp = False
    if tmp:
      ans = tmp
      break
      
if ans:
  print("Yes")
else:
  print("No")


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

int main() {
    string s;
    cin >> s;
    bool flag1 = false, flag2 = false;
    rep(i, s.size()) {
        if (s[i] == 'C') flag1 = true;
        if (flag1 && s[i] == 'F') flag2 = true;
    }
    cout << (flag2 ? "Yes" : "No") << endl;
    return 0;
}

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

void main_()
{
    string s;
    cin >> s;
    ll K;
    cin >> K;

    for (auto&& ch : s) {
        auto to_a = (26 - (ch - 'a')) % 26;
        if (to_a <= K) {
            ch = 'a';
            K -= to_a;
        }
    }

    s.back() = 'a' + (((s.back() - 'a') + K) % 26);

    cout << s << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    set<string> s;
    string t;
    for(int i=0;i<n;i++)
    {
        cin>>t;
        s.insert(t);
    }
    cout<<s.size()<<endl;
}

Measured memory_bytes: 19156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j;
    cin>>n;
    ll a[n];
    unordered_map<ll,ll>mp;
    for(i=0;i<n;i++){
    cin>>a[i];mp[a[i]]++;}
    sort(a,a+n);
    reverse(a,a+n);
    ll ans=0;
    for(i=0;i<n;i++)
    {
        if(mp[a[i]]<1)
        continue;
        
        ll cur=1;
        while(cur<=a[i]) 
            cur<<=1;
        if(mp[cur-a[i]]>0)
        {
            //cout<<a[i]<<" "<<cur-a[i]<<endl;
            if(cur-a[i]==a[i] and mp[a[i]]==1)
            continue;
            ans++;
            mp[a[i]]--;
            mp[cur-a[i]]--;
        }
    }
    cout<<ans;
}

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

template <typename T>
class SegmentTree {
	using func_t = function<T(const T&, const T&)>;
	const int n;
	const T id;
	func_t merge;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
	ll sub(int l, int r, int node, int lb, int ub, ll val) {
		if (ub <= l || r <= lb) return 0;
		if (l <= lb && ub <= r) return upper_bound(data[node].begin(), data[node].end(), val) - data[node].begin();
		return sub(l, r, node * 2, lb, (lb + ub) / 2, val) + sub(l, r, node * 2 + 1, (lb + ub) / 2, ub, val);
	}
public:
	SegmentTree(const vector<T>& data_, T id_, func_t merge_) :
		n(size(data_.size())), id(id_), merge(merge_), data(n * 2, id_) {
		for (int i = 0; i < (int)data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = merge(data[i * 2], data[i * 2 + 1]);
	}
	void Update(int p, T val) {
		p += n;
		data[p] = val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	void Add(int p, T val) {
		p += n;
		data[p] += val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	ll Find(int l, int r, ll val) {
		return sub(l, r + 1, 1, 0, n, val);
	}
};

int main()
{
	ll N, K;
	cin >> N >> K;
	vector<ll> a(N), sum(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> a[i]; a[i] -= K;
		sum[i + 1] = sum[i] + a[i];
	}
	vector<vector<ll>> b(N + 1);
	for (int i = 0; i <= N; i++) {
		b[i].push_back(sum[i]);
	}
	SegmentTree<vector<ll>> st(b, vector<ll>(), [](const vector<ll>& l, const vector<ll>& r) {
		int nl = l.size(), nr = r.size();
		vector<ll> res(nl + nr);
		for (int i = 0, j = 0, k = 0; i < nl || j < nr; k++) {
			if (j == nr) {
				res[k] = l[i++];
				continue;
			}
			if (i == nl) {
				res[k] = r[j++];
				continue;
			}
			if (l[i] <= r[j]) {
				res[k] = l[i++];
			}
			else {
				res[k] = r[j++];
			}
		}
		return res;
	});
	ll res = 0;
	for (int i = 0; i < N; i++) {
		res += st.Find(0, i, sum[i + 1]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 65792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  cin>>s;
  int n=s.size();
  vi a(26,0);
  rep(i,n)a[s[i]-'a']++;
  rep(i,26)if(a[i]%2==1){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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 MRINF = 5000000000000000;


int main() {

  ll N, M;
  cin >> N >> M;

  if(N==1&&M==1){
    cout << 1 << endl;
    return 0;
  }

  if(N==1){
    cout << max(M-2, (ll)0) << endl;
    return 0;
  }else if(M==1){
    cout << max(N-2, (ll)0) << endl;
    return 0;  
  }else {
    cout << N*M-(N+M+N+M-4) << endl;
    return 0;  
  }




}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3620
import std.stdio, std.algorithm, std.conv, std.range, std.string;
 
void main(){
    string line;
    while(line = readln.chomp, line.length){
        auto d = line.to!int;
        int s;
        for(int x = 0; x < 600; x += d){
            s += x * x * d;
        }
        //auto s2 = reduce!((a, b) => a + b * b * d)(0, iota(d, 600, d));
        //if(s != s2) throw new Exception(text(s, " ", s2));
        s.writeln;
    }
}

Measured memory_bytes: 972
#include<iostream>
#include<cmath>
#include<unordered_map>
#include<math.h>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#include<iomanip>
#include<string>
#include<map>
#define PI 3.14159265
#define mod 998244353    
using namespace std;

 

void func(){
    long long n , w , inf = 1e15 , maxi = -1;
    cin >> n >> w;
    vector<long long> val(n) , wt(n); 

    for(int i = 0 ; i < n ; ++i){
      cin >> wt[i] >> val[i] ; 
    }
    vector<vector<long long>> dp(n + 1, vector<long long>(1e5 + 1 , inf));


    for(int i = 0 ; i <= n ; ++i){
        for(int j = 0 ; j <= 100001 ; ++j){
            if(j == 0){
              dp[i][0] = 0;
            }
            else if(i == 0){
              dp[0][j] = inf;
            }
            else if(val[i - 1] > j){
              dp[i][j] = dp[i - 1][j];
            }
            else{
              dp[i][j] = min(dp[i - 1][j] , dp[i - 1][j - val[i - 1]] + wt[i - 1]);
            }
            if(dp[i][j] <= w && maxi < j ){
              maxi = j;
            }
        }
    }
  cout << maxi << "\n";
}
int main(){
    int t = 1 , cnt = 0 ;
  // cin >> t;
    
    while(t--){
        
        func();
    }
}

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

class RangeMin {
public:
	int size_ = 1;
	vector<long long> dat;

	void init(int sz) {
		while (size_ <= sz) size_ *= 2;
		dat.resize(size_ * 2, 0);
	}
	void update(int pos, long long x) {
		pos += size_;
		dat[pos] = x;
		while (pos >= 2) {
			pos >>= 1;
			dat[pos] = min(dat[pos * 2], dat[pos * 2 + 1]);
		}
	}
	long long query_(int l, int r, int a, int b, int u) {
		if (l <= a && b <= r) return dat[u];
		if (r <= a || b <= l) return (1LL << 60);
		long long v1 = query_(l, r, a, (a + b) >> 1, u * 2);
		long long v2 = query_(l, r, (a + b) >> 1, b, u * 2 + 1);
		return min(v1, v2);
	}
	long long query(int l, int r) {
		return query_(l, r, 0, size_, 1);
	}
};

long long N, M;
long long L[1 << 18], R[1 << 18], C[1 << 18];
long long dp[1 << 18];
vector<int> G[1 << 18];
RangeMin Z;

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) cin >> L[i] >> R[i] >> C[i];
	for (int i = 1; i <= M; i++) G[R[i]].push_back(i);
	for (int i = 2; i <= N; i++) dp[i] = (1LL << 60);

	Z.init(N + 2);
	for (int i = 2; i <= N; i++) {
		for (int j : G[i]) {
			long long cl = L[j], cost = C[j];
			long long v = Z.query(L[j], i);
			dp[i] = min(dp[i], v + cost);
		}
		Z.update(i, dp[i]);
	}

	if (dp[N] == (1LL << 60)) cout << "-1" << endl;
	else cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 19712