akhauriyash/Code-Regression huggingface dataset:
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))


a = list(itertools.permutations(p))
b = list(itertools.permutations(q))

a.sort()
b.sort()

ans1 = a.index(p) + 1
ans2 = b.index(q) + 1

print(abs(ans1 - ans2))


Measured memory_bytes: 51184
#include <bits/stdc++.h>
#define VI vector<int> 
#define SI set<int>
#define QI queue<int> 
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define REP(i,a,b) for(int i = a; i < b; ++i)
#define F for(int i = 0; i < n; ++i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define M 1000000007
using namespace std;

int main()
 {  
    FIO
    int a,b,c; cin>>a>>b>>c;
    cout<<min(b/a, c);
    
    return 0;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

using namespace std;

int main(){
    int n;
    cin >> n;
    int i=1;
    while (i<=n){
        i *= 2;
    }
    cout << i/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
typedef long long ll;
typedef long double ld;
int n, k;
string s;
int thesis(int numseg, int k) {
	if (k == 0) return numseg;
	if (numseg == 1) return 1;
	if (numseg <= 3 && k>0) return 1;
	int phase = numseg / 3;
	if (k >= phase)
		return thesis(phase + numseg % 3, k - phase);
	else return thesis(numseg - 3 * k + k, 0);
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k >> s;
	int num = 1, seg=0; char x = s[0];
	for (int i = 1; i < n; ++i) {
		if (s[i] != x) {
			seg++;
			num = 1;
			x = s[i];
		}
		else num++;
	}
	if (num > 0) {
		seg++;
	}
	cout << n-thesis(seg, k) << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
#include<queue>
using namespace std;
const long long INF = 1LL<<60;
long long mx(long long a, long long b){
  if(a>b) return a;
  else return b;
}

int main(){
  int N ;cin>>N;
  long long W; cin>>W;
  long long w[110],v[110];

  for(int i=0;i<N;i++)
  cin>>w[i]>>v[i];

  long long dp[110][100100]={0};

  for(int i=1;i<=N;i++){
    for(int j=0;j<=W;j++){
      if(j-w[i-1]>=0) dp[i][j]=mx(dp[i][j],dp[i-1][j-w[i-1]]+v[i-1]);
      dp[i][j]=mx(dp[i-1][j],dp[i][j]);
    }}

    cout<<dp[N][W]<<endl;
  }


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

typedef long long ll;
typedef pair<int, int> pi;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

int n;
ll ans = 0;
ll a[222222][2];
vector<pair<ll,ll> > score;

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

    cin>>n;
    for(int i = 0; i < n; i++){
        cin >> a[i][0] >> a[i][1];
        score.pb(mp(a[i][0]+a[i][1],i));
    }
    sort(score.begin(),score.end());

    for(int i = n-1; i >= 0; i--){
        if((n-i)%2==1) ans+=a[score[i].se][0];
        else ans-=a[score[i].se][1];
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3568
n, m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
g = Array.new(n, 0)
m.times do
  a, b = gets.split.map(&:to_i)
  g[a - 1] = h[b - 1] if g[a - 1] < h[b - 1]
  g[b - 1] = h[a - 1] if g[b - 1] < h[a - 1]
end
cnt = 0
n.times do |i|
  cnt += 1 if h[i] > g[i]
end
puts cnt

Measured memory_bytes: 22376
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int h,w;
    cin>>h>>w;
    vector<string>s(h);
    rep(i,h){
        cin>>s[i];
    }
    rep(i,h){
        cout<<s[i]<<endl;
        cout<<s[i]<<endl;
    }
}


Measured memory_bytes: 256
N = list(map(int,input()))
if N[0] > N[1] or (N[0] == N[1] and N[1] >= N[2]):
    print(N[0]*100+N[0]*10+N[0])
else:
    print((N[0]+1)*100+(N[0]+1)*10+(N[0]+1))



Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        s: chars
    }
    let mut rl = vec![0; n + 1];
    let mut rr = vec![0; n + 1];
    let mut gl = vec![0; n + 1];
    let mut gr = vec![0; n + 1];
    let mut bl = vec![0; n + 1];
    let mut br = vec![0; n + 1];
    for i in 0..n {
        if s[i] == 'R' {
            rl[i + 1] = 1;
            rr[i] = 1;
        } else if s[i] == 'G' {
            gl[i + 1] = 1;
            gr[i] = 1;
        } else {
            bl[i + 1] = 1;
            br[i] = 1;
        }
    }
    for i in 0..n {
        rl[i + 1] += rl[i];
        gl[i + 1] += gl[i];
        bl[i + 1] += bl[i];
        rr[n - i - 1] += rr[n - i];
        gr[n - i - 1] += gr[n - i];
        br[n - i - 1] += br[n - i];
    }
    let mut ans: usize = 0;
    for i in 0..n {
        if s[i] == 'R' {
            ans += gl[i] * br[i + 1];
            ans += bl[i] * gr[i + 1];
        } else if s[i] == 'G' {
            ans += rl[i] * br[i + 1];
            ans += bl[i] * rr[i + 1];
        } else {
            ans += rl[i] * gr[i + 1];
            ans += gl[i] * rr[i + 1];
        }
        for j in 1..min(i + 1, n - i) {
            if s[i - j] != s[i] && s[i + j] != s[i] && s[i - j] != s[i + j] {
                ans -= 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2312
/*
 *  Created on: 19 / 9 / 2020
 *  Author:     Eslam Waheed
 */

#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO

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

#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define ld   long double

#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   s.size()
#define endl    '\n'

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

//const ld PI = acos(-1);
//const ll mod = 1e9 + 7;
//const ld EPS = 1e-8;
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed;
    ll n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans += (n - 1) / i;
    }
    cout << ans;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <string>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

int main() {
    int a, b;
    scanf("%d", &a);
    printf("%d\n", a*800 - (a/15)*200);
}


Measured memory_bytes: 256
#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++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n;
int main(){
    cin>>n;
    vector<int> v(n);
    rep(i,n) cin>>v[i];
    int ans=0;
    sort(v.begin(),v.end());
    int wa,r,l;
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            wa = v[i]+v[j];
            r = lower_bound(v.begin(),v.end(),wa)-v.begin();
            l = i+1;
            //cout<<v[j]<<" "<<v[i]<<":"<<r<<" "<<l<<endl;
            ans+=r-l;
        }
        //ans+=r-l;
    }
    cout<<ans<<endl;
    return 0;
}

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
using namespace std;

int main() {
  int A, B, X;
  cin >> X;
  for(double i = -100; i < 1000; i+=1){
    for(double j = -100; j < 1000; j+= 1){
      if(pow(i, 5) - pow(j, 5) == X){
 A = i;
        B = j;
        break;
      }

    }
  }

  cout << A << " " << B << endl;
}
 

  

Measured memory_bytes: 3600
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N, M;
    cin >> N >> M;

    vector<ll> A(N+1);
    A[0] = 0;
    FOR(i, 1, N+1){
        cin >> A.at(i);
    }

    vector<ll> B(N+1);
    B[0] = A[0];
    FOR(i, 1, N+1){
        B[i] = B[i-1] + A[i];
    }

    map<ll, ll> mp;
    FOR(i, 0, N+1){
        ll a = B[i] % M;
        mp[a]++;
    }

    ll answer = 0;
    for(auto p : mp){
        ll n = p.second;
        answer += n * (n-1) / 2;
    }

    p(answer);
    
    return 0;
}

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

int main() {
    bool ok[4] = {};
    string S;
    cin >> S;
    int ans = 0;
    int now = 0;
    for(char c : S) {
        if(c == 'L') {
            now--;
            now += 4;
            now %= 4;
        } else {
            now++;
            now %= 4;
            ok[now] = true;
            if(!now) {
                bool check = true;
                for(int i = 0; i < 4; i++) check &= ok[i];
                ans += check;
            }
        }
        if(!now) for(int i = 0; i < 4; i++) ok[i] = false;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3220
s = input().strip()

buf = s[0]
count = 0
popa  = []
suma = 0
for i in s:
  if i=="<":
    count+=1
    suma += count
  elif i==">" and buf=="<":
    popa.append(count)
    suma -= count
    count = 0
  buf = i
buf = s[-1]
count = 0
dupa  = []
for i in s[::-1]:
  if i==">":
    count+=1
    suma += count
  elif i=="<" and buf==">":
    dupa.append(count)
    suma -= count
    count = 0
  buf = i

for i,j in zip(dupa[::-1],popa):
  suma+=max(i,j)
print(suma)
# print(sum(map(int,"0 3 2 1 0 1 2 0 1 2 3 4 5 2 1 0 1".split())))


Measured memory_bytes: 6840
class Segment_Tree:
    __slots__ = ['ide_ele', 'size', 'num', 'seg', 'segfunc']

    def __init__(self, size, func, element):
        #####単位元######
        self.ide_ele = element
        self.size = size

        #num:n以上の最小の2のべき乗
        self.num = 2 ** (self.size - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num

        #####segfunc######
        self.segfunc = func

    def apply(self, apply_seq):
        #set_val
        for i in range(self.size):
            self.seg[i + self.num - 1] = apply_seq[i]    
        #built
        for i in range(self.num - 2, -1, -1) :
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) 
        
    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k-1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1],  self.seg[k * 2 + 2])
        
    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2 
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res

n,q = map(int,input().split())
st = Segment_Tree(n,min,float("inf"))
for _ in range(q):
  typo,x,y = map(int,input().split())
  if typo == 0:
    st.update(x,y)
  else:
    out = st.query(x,y+1)
    print(out if out != float("inf") else 2**31-1)


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

using namespace std;

typedef long long LL;

const int N = 100003;

int n, m, a[5][5];
bool st[5][5];
char s[N];

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i+=1) s[i] = '+';
    for (int i = 1; i <= m; i+=1)
    {
        int u, v;
        cin >> u >> v;
        if (s[u] == '+') s[u] = v + '0';
        else if (s[u] != v + '0') {puts("-1"); return 0;}
    }
    if (n == 1 && s[1] == '+') {puts("0"); return 0;}
    if (n == 1 && s[1] == '0') {puts("0"); return 0;}
    if (s[1] == '0') {puts("-1"); return 0;}
    if (s[1] == '+') s[1] = '1';
    for (int i = 1; i <= n; i+=1)
        if (s[i] == '+') printf("0");
        else printf("%c", s[i]);
    puts("");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct mint{
	ll x;
	mint(ll x=0):x((x%mod+mod)%mod){}
	friend ostream &operator<<(ostream& os,const mint& a){
		return os<<a.x;
	}
	friend istream &operator>>(istream& is,mint& a){
		ll t;
		is>>t;
		a=mint(t);
		return (is);
	}
	mint& operator+=(const mint a){
		if((x+=a.x)>=mod) x-=mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x+=mod-a.x)>=mod)x-=mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x*=a.x)%=mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if (!t) return 1;
		mint a=pow(t>>1);
		a*=a;
		if(t&1) a*=*this;
		return a;
	}
	// for prime mod
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this)*=a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
};

struct combination{
  vector<mint> fact,ifact;
  combination(int n):fact(n+1),ifact(n+1){
	assert(n<mod);
	fact[0]=1;
	for(int i=1;i<=n;i++) fact[i]=fact[i-1]*i;
	ifact[n]=fact[n].inv();
	for(int i=n;i>=1;i--) ifact[i-1]=ifact[i]*i;
  }
  mint operator()(int n,int k){
	if (k<0 || k>n) return 0;
	return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	combination comb(3*n);
	if(k>=n-1) cout<<comb(2*n-1,n)<<endl;
	else{
		mint ans=0;
		rep(i,k+1){//0人の数の部屋
			mint now=comb(n,i)*comb(n-1,n-i-1);
			ans+=now;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 9600
#include<iostream>

using namespace std;

int conssum(int a,int b)
{
	return (b*(b+1)-(a-1)*a)/2;
}

int main()
{
	for(int n;cin>>n,n;){
		int cnt=0;
		for(int a=1;a<n;a++)for(int b=a+1;b<=n;b++){
			if(conssum(a,b)==n)	cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;
	return 0;
};


Measured memory_bytes: 256
//=================================
// Created on: 2018/07/03 05:20:29
//=================================
#include <bits/stdc++.h>
using namespace std;
int main()
{
    for (int N, M;;) {
        cin >> N >> M;
        if (N == 0 and M == 0) { break; }
        vector<int> C(M), x(N);
        for (int i = 0; i < M; i++) { cin >> C[i]; }
        for (int i = 0; i < N; i++) { cin >> x[i]; }
        constexpr int INF = 1 << 30;
        vector<int> dp(256, INF);
        dp[128] = 0;
        for (int i = 0; i < N; i++) {
            vector<int> tmp(256, INF);
            for (int j = 0; j < 256; j++) {
                if (dp[j] == INF) { continue; }
                for (int k = 0; k < M; k++) {
                    const int next = max(0, min(255, j + C[k]));
                    tmp[next] = min(tmp[next], dp[j] + (next - x[i]) * (next - x[i]));
                }
            }
            dp = tmp;
        }
        cout << *min_element(dp.begin(), dp.end()) << endl;
    }
    return 0;
}



Measured memory_bytes: 3168
#include<iostream>
#include<vector>
#include<algorithm>
#define NMAX 105
#define WMAX 10005
#define DIAGONAL 1
#define TOP 0

using namespace std;

struct Item{
  int value, weight;
};

int N, W;
Item items[NMAX + 1];
int C[NMAX + 1][WMAX + 1], G[NMAX + 1][WMAX + 1];

void compute(int &maxValue, vector<int> &selection){
  for(int w = 0; w <= W; w++){
    C[0][w] = 0;
    G[0][w] = DIAGONAL;
  }

  for(int i = 1; i <= N; i++) C[i][0] = 0;

  for(int i = 1; i <= N; i++){
    for(int w = 1; w <= W; w++){
      C[i][w] = C[i - 1][w];
      G[i][w] = TOP;
      if(items[i].weight > w) continue;
      if(items[i].value + C[i - 1][w - items[i].weight] > C[i - 1][w]){
        C[i][w] = items[i].value + C[i - 1][w - items[i].weight];
        G[i][w] = DIAGONAL;
      }
    }
  }

  maxValue = C[N][W];
  selection.clear();
  for(int i = N, w = W; i >= 1; i--){
    if(G[i][w] == DIAGONAL){
      selection.push_back(i);
      w -= items[i].weight;
    }
  }

  reverse(selection.begin(), selection.end());
}

void input(){
  cin >> N >> W;
  for(int i = 1; i <= N; i++){
    cin >> items[i].value >> items[i].weight;
  }
}

int main(){
  int maxValue;
  vector<int> selection;
  input();
  compute(maxValue, selection);

  cout << maxValue << endl;

  return 0;
}

Measured memory_bytes: 9408
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    int max = -1000;
    if (a + b >= max) {
      max = a + b;
    }
    
    if (a - b >= max) {
      max = a - b;
    }
    
    if(a * b >= max) {
      max = a * b;
    }
    
    System.out.println(max); 
  }
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	cin>>n;
	vector<int> deg(n);
	for(int i = 1; i < n; i++){
		int x;
		cin>>x;
		deg[x - 1]++;
	}
	for(auto x : deg){
		cout<<x<<"\n";
	}

	return 0;
}

Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    ll n;cin>>n;
    ll res = INF;
    rep(a,1,sqrt(n)+1){
        ll b = n/a;
        if(n % a != 0) continue;
        ll tmp = max(a,b);
        ll tmp2 = 0;
        while(tmp > 0){
            tmp /= 10;
            tmp2++;
        }
        res = min(res,tmp2);
    }
    cout << res << ednl;
}

Measured memory_bytes: 256
####################################################################
import sys
def _p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
def _pa(_aa):
  #return
  for _a in _aa: _p(_a)
####################################################################
H,W = map(int, input().split())
ch,cw = map(int, input().split())
dh,dw = map(int, input().split())
M = list( list(input()) for _ in range(H) )

if ch==dh and cw==dw:
  print(0)
  exit()

INF = 10**18

for h in range(H):
  for w in range(W):
    if M[h][w] == ".": M[h][w] = INF
    # if M[h][w] == "#": M[h][w] = -1

ch -= 1
cw -= 1
dh -= 1
dw -= 1

M[ch][cw] = 0
# M[dh][dw] = "G"

# _pa(M)


from collections import deque
Q = deque()
Q.append((ch,cw))

ans = INF

while Q:
  h,w = Q.popleft()

  for ih,iw in [(1,0), (-1,0), (0,1), (0,-1)]:
    nh = h + ih
    nw = w + iw
    if nh < 0 or H <= nh: continue
    if nw < 0 or W <= nw: continue
    if M[nh][nw] == "#": continue

    if nh == dh and nw == dw:
      M[nh][nw] = min(M[h][w], M[dh][dw])
      ans = min(ans, M[nh][nw])
      continue

    if M[h][w] < M[nh][nw]:
      M[nh][nw] = M[h][w]
      Q.appendleft((nh,nw))
      continue

    if M[h][w] > M[nh][nw]:
      M[h][w] = M[nh][nw]
      Q.appendleft((h,w))

  for ih,iw in [(1,1), (1,-1), (-1,1), (-1,-1), (2,0), (2,1), (2,2), (2,-1), (2,-2), (1,2), (1,-2), (0,2), (0,-2), (-1,2), (-1,-2), (-2,0), (-2,1), (-2,-2), (-2,-1), (-2,-2)]:
    nh = h + ih
    nw = w + iw
    if nh < 0 or H <= nh: continue
    if nw < 0 or W <= nw: continue
    if M[nh][nw] == "#": continue

    if nh == dh and nw == dw:
      M[nh][nw] = min(M[h][w]+1, M[dh][dw])
      ans = min(ans, M[nh][nw])
      continue

    if M[h][w]+1 < M[nh][nw]:
      M[nh][nw] = M[h][w]+1
      Q.append((nh,nw))
      continue

    if M[h][w] > M[nh][nw]+1:
      M[h][w] = M[nh][nw]+1
      Q.append((h,w))

# _pa(M)

if ans == INF: ans = -1
print(ans)






Measured memory_bytes: 148736
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

string s;
ll ans;
ll calc(int i, int j, ll sum) {
    if(i >= s.size())
        return (sum+stod(s.substr(j)));
    else {
        ll sub = stod(s.substr(j, i-j));
        ll a = calc(i+1, i, sum+sub); // +を入れる場合
        ll b = calc(i+1, j, sum);
        return a + b;
    }
}

int main(){
    cin >> s;
    ans = 0;
    //calc(1, 0, 0);
    cout << calc(1, 0, 0)<< endl;
}


Measured memory_bytes: 256
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import math
# isprime, prime_division

def isprime(x):
    q = int(math.sqrt(x))  # int() rounds to zero
    for i in range(2,q+1):   # upto q
        if x%i == 0:
            return False
    return True

def prime_division(x):
    q = int(math.sqrt(x))
    a = []
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            a.append([i,ex])
    if x>q:
        a.append([x,1])
    return a

def prime_division2(x):
    q = int(math.sqrt(x))
    h = {}
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            h[i] = ex
    if x>q:
        h[x] = 1
    return h

def divisorlist(z): # z : output of prime_division
    if len(z)==1:
        return [z[0][0]**i for i in range(z[0][1]+1)]
    y = divisorlist(z[1:])
    s = []
    for i in range(z[0][1]+1):
        for j in y:
            s.append((z[0][0]**i)*j)
    return s

n = inn()
sm = 0
pes = prime_division(n)
for p,e in pes:
    for i in range(1,50):
        if e<2*i+1:
            break
        sm += 1
        e -= i
    sm += 1
print(sm)


Measured memory_bytes: 63680
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        map.put(1, 0);
        map.put(2, 0);
        map.put(3, 0);
        map.put(4, 0);

        for (int i = 0; i < 3; i++) {

            String arr01[] = mylist.get(i).split(" ");

            int a = Integer.valueOf(arr01[0]);
            int b = Integer.valueOf(arr01[1]);

            map.put(a, map.get(a) + 1);
            map.put(b, map.get(b) + 1);

        }

        List<Integer> list01 = new ArrayList<>(map.values());

        int maxdata = list01.stream()
                .mapToInt(x -> x)
                .max()
                .orElse(0);

        int mindata = list01.stream()
                .mapToInt(x -> x)
                .min()
                .orElse(0);

        //        System.out.println(maxdata + " " + mindata);

        if (maxdata == 2 && mindata == 1) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }
}


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

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
   int x, y, z;
   cin >> x >> y >> z;
   swap(x, y);
   swap(x, z);
   cout << x << " " << y << " " << z << endl;
return 0;}

Measured memory_bytes: 256
// copied
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 100005
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int sums[MN],sumt[MN];
int a,b,c,d,q,ls,lt,res1,res2;
char s[MN],t[MN];
int main()
{
	scanf("%s%s",s,t);q=in();
	ls=strlen(s);lt=strlen(t);
	for (int i=1;i<=ls;++i)
	sums[i]=sums[i-1]+1+(s[i-1]=='B');
	for (int i=1;i<=lt;++i)
	sumt[i]=sumt[i-1]+1+(t[i-1]=='B');
	for (int i=1;i<=q;++i){
		a=in();b=in();c=in();d=in();
		res1=sums[b]-sums[a-1];
		res2=sumt[d]-sumt[c-1];
		if ((res1%3)==(res2%3)) puts("YES");else puts("NO");
	} return 0;
}


Measured memory_bytes: 2636
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner in = new Scanner(System.in);
	static boolean[][] r;
	public static void main(String[] args){
		int N = in.nextInt(), M  = in.nextInt();
		r = new boolean[N][N];
		
		for(int i = 0; i < N; i++){
			Arrays.fill(r[i], false);
		}
		
		for(int i = 0; i < M; i++){
			int a = in.nextInt() - 1, b = in.nextInt() - 1;
			r[a][b] = true;
			r[b][a] = true;
		}
		
		boolean[] v = new boolean[N];
		Arrays.fill(v, false);
		System.out.println(route(0,  v));
	}
	
	public static int route(int p, boolean[] v){
		v[p] = true;
		
		boolean all = true;
		for(int i = 0; i < v.length; i++){
			if(!v[i]) all = false;
		}
		if(all){
			return 1;
		}
		
		int sum = 0;
		for(int i = 0; i < v.length; i++){
			if(!v[i] && r[p][i]){
				boolean[] nv = new boolean[v.length];
				for(int j = 0; j < v.length; j++){
					nv[j] = v[j];
				}
				sum += route(i, nv);
			}
		}
		return sum;
	}
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int t = sc.nextInt();
		int a = x-t;
		if (a>=0) {
			System.out.println(a);
		} else {
			System.out.println("0");
		}
	}		
}

Measured memory_bytes: 21716
fun main(args: Array<String>) {
    val strArr = readLine()!!.split(" ")
    val intArr = strArr.map { it.toInt() }
    val dblArr = strArr.map { it.toDouble() }
    println("%d %d %f".format(intArr[0]/intArr[1], intArr[0]%intArr[1], dblArr[0]/dblArr[1]))
}


Measured memory_bytes: 31840
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n); cin >> as;
    auto as2 = as;
    sort(as2.rbegin(), as2.rend());
    for(int i = 0; i < n; i++){
        cout << (as2[0] == as[i] ? as2[1] : as2[0]) << '\n';
    }
}


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

const int N = 100010;
int v[N], oddFreq[N], evenFreq[N], mx1[N], mx2[N];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i){
		cin >> v[i];
		if (i & 1)
			++oddFreq[v[i]];
		else
			++evenFreq[v[i]];
	}
	mx1[0] = oddFreq[0];
	mx2[N - 1] = oddFreq[N - 1];
	for (int i = 1; i < N; ++i){
		mx1[i] = max(mx1[i - 1], oddFreq[i]);
		mx2[N - 1 - i] = max(mx2[N - i], oddFreq[N - 1 - i]);
	}
	/*
	mx1 -> max element to the left
	mx2 -> max element to the right
	*/
	int ans = 1e9;
	for (int i = 1; i < N - 1; ++i){
		ans = min(ans, n - evenFreq[i] - max(mx1[i - 1], mx2[i + 1]));
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 2176
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
L = list(map(int, input().split()))
N = len(L)

cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if L[i] == L[j] or L[i] == L[k] or L[j] == L[k]:
                continue
            if L[i] < L[j] + L[k] and L[j] < L[k] + L[i] and L[k] < L[i] + L[j]:
                cnt += 1

print(cnt)

Measured memory_bytes: 9580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
const int INF=0x7fffffff;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
ull n, a[200005], b[200005], ans[200005],tot;
int main(){
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout); 
	scanf("%d", &n);
	int i;
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[a[i]]++;
	}
		
	for(i=1;i<=n;i++)
	{
		if(b[i]==2) tot++;
		else if(b[i]>2) tot+=b[i]*(b[i]-1)/2;

		if(b[a[i]]>3) ans[i]=-(b[a[i]]-1);
		else if(b[a[i]]==3) ans[i]=-2;
		else if(b[a[i]]==2) ans[i]=-1;		
	}
	
	for(i=1;i<=n;i++)
		printf("%lld\n", tot+ans[i]);
	return 0;
}

Measured memory_bytes: 6912
#include<iostream>
#include<utility>
#include<stack>
using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> P2;

int main(){
  int r,c;
  string grid[30];
  bool v[30][30][4][20];
  int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};
  bool f = false;

  cin >> r >> c;
  for(int i=0;i<r;i++){
    cin >> grid[i];
    for(int j=0;j<c;j++)
      for(int k=0;k<4;k++)
	for(int l=0;l<16;l++)v[i][j][k][l] = false;
  }

  v[0][0][0][0] = true;
  stack<P2> q;
  q.push(P2(P(0,0),P(0,0)));

  while(q.size()){
    P2 p = q.top(); q.pop();
    int y = p.first.first, x = p.first.second;
    int d = p.second.first, m = p.second.second;

    for(;;){
      if(grid[y][x] == '?'){
	for(int i=0;i<4;i++){
	  int ty = (y+dy[i]+r)%r, tx = (x+dx[i]+c)%c;
	  if(v[ty][tx][i][m])continue;
	  v[ty][tx][i][m] = true;
	  q.push(P2(P(ty,tx),P(i,m)));
	}
	break;
      }else if(grid[y][x] == '@'){
	f = true;
	break;
      }else{
	if(grid[y][x] == '>')d = 0;
	else if(grid[y][x] == 'v')d = 1;
	else if(grid[y][x] == '<')d = 2;
	else if(grid[y][x] == '^')d = 3;
	else if(grid[y][x] == '_'){
	  if(m)d = 2;
	  else d = 0;
	}
	else if(grid[y][x] == '|'){
	  if(m)d = 3;
	  else d = 1;
	}
	else if(grid[y][x] == '+')m = (m+1)%16;
	else if(grid[y][x] == '-')m = (m+15)%16;
	else if(grid[y][x] != '.')m = grid[y][x] - '0';
	
	y = (y+dy[d]+r)%r; x = (x+dx[d]+c)%c;
	if(v[y][x][d][m])break;
	v[y][x][d][m] = true;
      }
    }
    if(f)break;
  }

  if(f)cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	ll N, Q;
	cin >> N >> Q;
	vector<ll> A(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	vector<ll> sum;
	vector<ll> odd;
	vector<ll> even;
	auto tempSum = 0ll;
	auto tempOdd = 0ll;
	auto tempEven = 0ll;
	for (auto i = 0; i < N; ++i)
	{
		tempSum += A[i];
		sum.push_back(tempSum);
		if (i % 2 > 0)
		{
			tempOdd += A[i];
			odd.push_back(tempOdd);
		}
		else
		{
			tempEven += A[i];
			even.push_back(tempEven);
		}
	}

	vector<ll> ans;
	for (auto i = 0; i < Q; ++i)
	{
		ll X;
		cin >> X;

		auto leftIndex = -1ll;
		auto rightIndex = -1ll;
		auto low = 0ll;
		auto high = (ll)1e9;
		while (low <= high)
		{
			auto mid = (low + high) / 2;
			auto left = lower_bound(A.begin(), A.end(), X - mid);
			auto right = upper_bound(A.begin(), A.end(), X + mid);
			auto numA = (ll)(right - left);
			auto numT = (ll)(A.end() - right);
			if (numA == numT)
			{
				rightIndex = (ll)(right - A.begin()) - 1;
				leftIndex = (ll)(left - A.begin()) - 1;
				break;
			}
			else if (numA == numT + 1
				&& numA >= 2
				&& (X - *left) == *(right - 1) - X)
			{
				rightIndex = (ll)(right - A.begin()) - 2;
				leftIndex = (ll)(left - A.begin()) - 2;
				break;
			}
			else if (numA > numT)
			{
				high = mid - 1;
			}
			else
			{
				low = mid + 1;
			}
		}

		if (rightIndex < 0)
		{
			if (high >= 0)
			{
				auto left = lower_bound(A.begin(), A.end(), X - high);
				auto right = upper_bound(A.begin(), A.end(), X + high);
				rightIndex = (ll)(right - A.begin()) - 1;
				leftIndex = (ll)(left - A.begin()) - 2;
			}
			else
			{
				rightIndex = N - 1;
				leftIndex = N - 1;
			}
		}

		auto sumT = sum[N - 1] - sum[rightIndex];
		if (leftIndex >= 0)
		{
			if (leftIndex % 2 == 0)
			{
				sumT += even[leftIndex / 2];
			}
			else
			{
				sumT += odd[leftIndex / 2];
			}
		}

		ans.push_back(sumT);
	}

	for (auto i = 0; i < Q; ++i)
	{
		cout << ans[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 6008
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
 
const int MAXN=200005;
 
int n,k;
long long a[MAXN],s[MAXN],b[MAXN];
map<long long,int> mp;
 
int lowbit(int x)
{
    return (x&-x);
}
 
void modify(int x,int num)
{
    while(x<=n+1){
        a[x]+=(long long)num;
        x+=lowbit(x);
    }
}
 
long long sum(int x)
{
    long long ans=0;
    while(x>0){
        ans+=a[x];
        x-=lowbit(x);
    }
    return ans;
}
 
int main()
{
    scanf("%d %d",&n,&k);
    s[0]=0;b[0]=0;
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        s[i]=s[i-1]+(long long)(x-k);
        b[i]=s[i];
    }
    sort(b,b+1+n);
    int tot=0;
    for(int i=0;i<=n;i++)
        if(!mp.count(b[i]))mp[b[i]]=++tot; 
    long long cnt=0;
    memset(a,0,sizeof(a));
    for(int i=0;i<=n;i++){
        cnt+=sum(mp[s[i]]);
        modify(mp[s[i]],1);
    }
    printf("%lld\n",cnt);
    return 0;
} 

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

using namespace std;



void hawawa()
{
	int a, b;
	cin >> a >> b;
	if (a * b == 15) {
		cout << "*\n";
	}else if(a + b == 15) {
		cout << "+\n";
	}
	else {
		cout << "x\n";
	}
}

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


Measured memory_bytes: 256
import java.util.Scanner;

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

    int x;
    int i = 0;

    while(true){
      x = sc.nextInt();
      if(i==10000 || x==0) break;
      System.out.printf("Case %d: %d\n", i+1, x);
      i++;
    }

    //for(int j=0; j<i; j++) System.out.printf("Case %d: %d\n", j+1, num[j]);
  }
}



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

int a[4];

int main(void) {
  string input;
  cin >> input;
  rep(i,input.size()) a[i] = input[i] - '0';
  
  rep(x,8) {
    int sum = a[0];
    string S;
    S += (char)('0' + a[0]);
    rep(i,3) {
      if(x & (1<<i)) {
        sum += a[i+1];
        S += '+';
        S += (char)('0' + a[i+1]);
      }
      else {
        sum -= a[i+1];
        S += '-';
        S += (char)('0' + a[i+1]);
      }
    }
    if (sum == 7) {
      cout << S + "=7" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import sys
n, limit = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
#print(L)
dp = [{} for i in range(n+1)]

for i in range(n):
    Lw, Lv =L[i][0], L[i][1] #①i番目の価値を重さテーブルに代入
    dp[i+1][Lw] = Lv 
    for w, v in dp[i].items():
        dp[i+1][w] = max(dp[i+1].get(w, 0), v) #② 一つ上の行の価値と比べて大きい方を代入
        if w + Lw <=limit:
            dp[i+1][w+Lw] = max(dp[i].get(w+ Lw, 0), Lv + v) #③一つ上の行の価値をループで1つづつ取り出し、i番目の価値と足し合わせる
        
print(max(dp[-1].values()))

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

int main(){
    ll a;
    string b;
    cin >> a >> b;
    if(b.size() == 1) b += ".00";
    else if(b.size() == 3) b += '0';
    ll b100 = 100*(b[0]-'0') + 10*(b[2]-'0') + (b[3]-'0');
    cout << (a*b100)/100 << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#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 trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
#define left sefude
#define right sefudermano
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 1e7 + 10;
int f[N];
int32_t main(){
  fastio;
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j+=i)f[j]++;
  }
  ll res=0;
  for(int i=1;i<=n;i++){
    res+=1LL*i*f[i];
  }
  cout << res << endl;
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
} 

Measured memory_bytes: 42668
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0
using namespace std;
using ll = long long;

void testcase() {
    int n, k; cin >> n >> k;

    vector<int> v(n);
    for (int i=0; i<k; i++) {
        cin >> v[i];
    }
    for (int i=k; i<n; i++) {
        cin >> v[i];
        if (v[i] > v[i-k]) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x;
    cin >> x;
    cout << (int)ceil( ( sqrt( 1 + 8 * x ) - 1 ) / 2.0 );
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int nf[101]={0};
	int f[101]={0};
	int i,temp,j;
	
	while(scanf("%d",&n)!=EOF){
		if(n==0) break;
		f[n]++;
		nf[n]=n;
	}
	
	for(i=100;i>0;i--){
		for(j=0;j<i;j++){
			if(f[j]<f[j+1]){
				temp=f[j];
				f[j]=f[j+1];
				f[j+1]=temp;
				temp=nf[j];
				nf[j]=nf[j+1];
				nf[j+1]=temp;
			}
			else if(f[j]==f[j+1] && nf[j] < nf[j+1]){
				temp=f[j];
				f[j]=f[j+1];
				f[j+1]=temp;
				temp=nf[j];
				nf[j]=nf[j+1];
				nf[j+1]=temp;
			}
		}
	}
	int F=0;
	while(1){
		if(f[F]==f[F+1]){
			F++;
		}
		else break;
	}
	
	for(i=F;i>=0;i--){
		printf("%d\n",nf[i]);
	}
	
	return 0;
}

Measured memory_bytes: 0
N,M=map(int,input().split())
s=[0]*M
c=[0]*M
d=dict()
for i in range(M):
    s[i],c[i] = map(int,input().split())
    if s[i] in d:
        if d[s[i]]!=c[i]:
            ans=-1
            break
    else:
        d[s[i]]=c[i]
else:
    ans=""
    for i in range(1,N+1):
        if i in d:
            ans += str(d[i])
        else:
            if i>=2 and ans!="" and ans[0]=="0":
                ans=-1
                break
            elif N>=2 and i==1:
                ans +=str(1)
            else:
                ans +=str(0)
            
print(ans)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll inf = 100100100100100;
const ll mod = 1000000007;
#define fi first
#define se second
class UF{
public:
	vector<int> par,num;
 
	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UF(int N):par(N),num(N,1){
		iota(par.begin(),par.end(),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return ;
		if(num[u]<num[v])swap(u,v);
		num[u] += num[v];
		par[v] = u;
	}
	bool same(int u,int v){
		return find(u) == find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};
int main(){
    ll n,m;
    cin>>n>>m;
    UF uf(n);
    vector<P> a(m);
    for(int i=0;i<m;i++){
        int p,q;
        cin>>p>>q;
        a.at(i)=P(p,q);
    }
    vector<ll> ans;
    ll now=n*(n-1)/2;
    for(int i=m-1;i>=0;i--){
        ans.push_back(now);
        if(!uf.same(a.at(i).fi-1,a.at(i).se-1)){
        now-=uf.size(a.at(i).fi-1)*uf.size(a.at(i).se-1);
        uf.unite(a.at(i).fi-1,a.at(i).se-1);
        }
    }
    for(int i=m-1;i>=0;i--)cout<<ans.at(i)<<endl;

}

Measured memory_bytes: 4596