akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

mia, pla = [], []
for ai in a:
    if ai < 0:
        mia.append(ai)
    elif ai >= 0:
        pla.append(ai)
mia.sort(reverse=True)
pla.sort()

cnt = 1
if len(pla) == 0 and k % 2 == 1:
    for i in mia[:k]:
        cnt = cnt * i % mod
else:
    while k > 0:
        if k == 1 or len(mia) <= 1:
            if len(pla) == 0:
                cnt *= mia.pop()
            elif len(pla) > 0:
                cnt *= pla.pop()
            k -= 1
        elif len(pla) <= 1:
            cnt *= mia.pop() * mia.pop()
            k -= 2
        elif len(pla) >= 2 and len(mia) >= 2:
            if pla[-1] * pla[-2] > mia[-1] * mia[-2]:
                cnt *= pla.pop()
                k -= 1
            elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:
                cnt *= mia.pop() * mia.pop()
                k -= 2
        cnt %= mod
print(cnt)


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

using namespace std;

int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */

int main(){
    int n; cin >> n;
    map<string, int> mp;
    rep(i, n){
        string s; cin >> s;
        mp[s]++;
    }

    vector<string> ls = {"AC","WA","TLE","RE"};
    rep(i, 4){
        string s  =ls[i];
        cout << s + " x " <<  mp[s] << endl;
    }
}

Measured memory_bytes: 3544
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
k=gi
1.upto(k) do |i|
  1.upto(k) do |j|
    1.upto(k) do |kk|
      sum+=i.gcd(j).gcd(kk)
    end
  end
end
puts sum

Measured memory_bytes: 14364
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        int R = Integer.parseInt(sc.next());
        int S = Integer.parseInt(sc.next());
        int P = Integer.parseInt(sc.next());
        String T = sc.next();

        int[] point = new int[N];
        for (int i=0;i<N;i++) {
            if (T.charAt(i)=='r') point[i] = P;
            else if (T.charAt(i)=='s') point[i] = R;
            else if (T.charAt(i)=='p') point[i] = S;
        }
        boolean[] win_flag = new boolean[N];

        long ans = 0;
        for (int i=0;i<N;i++) {
            if (i>=K && T.charAt(i)==T.charAt(i-K) && win_flag[i-K]) continue;
            else {
                ans += point[i];
                win_flag[i] = true;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 28624
#include<iostream>
#include<string>
#include<sstream>
using namespace std;

int main(){
	string map[6];
	map[0] = "abcde";
	map[1] = "fghij";
	map[2] = "klmno";
	map[3] = "pqrst";
	map[4] = "uvwxy";
	map[5] = "z.?! ";
	string str;
	while(cin >> str){
		int num[1000]={0};
		int len = str.size();
		bool flag = false;
		for(int i=0;i<len;i+=2){
			if(str[i] <= '0' || str[i] > '6'){
				flag = true;
				break;
			}
			else if(str[i+1] <= '0' || str[i+1] > '5'){
				flag = true;
				break;
			}
		}
		if(len%2 == 1 || flag){
			cout << "NA" << endl;
			continue;
		}
		for(int i=0;i<len;i+=2){
			for(int j=i;j<i+2;j++){
				string tmp = "";
				tmp += str[j];
				istringstream ss(tmp);
				ss >> num[j];
				//cout << num[j] << endl;
			}
		}
		for(int i=0;i<len;i+=2){
			cout << map[num[i]-1][num[i+1]-1];
		}
		cout << endl;
	}
}

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

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


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

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

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int H, N;
  cin >> H >> N;
  while(N--) {
    int X;
    cin >> X;
    H -= X;
  }
  if(H <= 0) cout << "Yes\n";
  else cout << "No\n";
}

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

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> xi(n), yi(n), hi(n);
    for (int i = 0; i < n; i++) {
        std::cin >> xi[i] >> yi[i] >> hi[i];
    }

    for (int x = 0; x < 101; x++) {
        for (int y = 0; y < 101; y++) {
            int fix = INT_MAX;
            for (int i = 0; i < n; i++) {
                if (hi[i] == 0)
                    continue;
                int tmp = hi[i] + std::abs(x - xi[i]) + std::abs(y - yi[i]);
                if (fix == INT_MAX) {
                    fix = tmp;
                } else if (fix != tmp) {
                    fix = -1;
                    break;
                }
            }
            if (fix < 0)
                continue;

            for (int i = 0; i < n; i++) {
                if (hi[i] != 0)
                    continue;
                int tmp = hi[i] + std::abs(x - xi[i]) + std::abs(y - yi[i]);
                if (fix > tmp) {
                    fix = -1;
                    break;
                }
            }

            if (fix > 0) {
                std::cout << x << " " << y << " " << fix << std::endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int x, y, z;

    double p, area = 0, farea = 0;

    scanf("%d %d %d",&x, &y, &z);

    p = (x + y + z)/ (2 * 1.0);

    area = (p *( (p - x) * (p - y) * (p - z)));

    farea = sqrt(area);

    printf("%.0lf",farea);


    return 0;
}


Measured memory_bytes: 128
S = list(open(0).read())
ss = []
for s in S:
    if 'a' <= s <= 'z':
        ss.append(s.upper())
    elif 'A' <= s <= 'Z':
        ss.append(s.lower())
    else:
        ss.append(s)
print("".join(ss), end="")


Measured memory_bytes: 5572
#include<iostream>
#include<string>


using namespace std;

int main()
{
  string s;
  cin >> s ;
  
  if ((s[0] == 'Y') && (s[1] == 'A') && (s[2] == 'K') && (s[3] == 'I')) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
 
 

Measured memory_bytes: 256
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
		
const double eps = 1e-9;																							   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////

int check[1000005];
int check2[1000005];

///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
   string s, t;
   cin >> s >> t;
   vi a(26);
   vi b(26);
   
   for(int i = 0; i < s.size(); i++){
	   int c = s[i] - 'a';
	   int d = t[i] - 'a';
	   
	   //cout << "c: " << c << endl;
	   //cout << "d: " << d << endl;
	   
	   a[c]++;
	   b[d]++; 
   }
   
   sort(a.begin(), a.end());
   sort(b.begin(), b.end());
   
   if(a == b) cout << "Yes" << endl;
   else cout << "No" << endl;
   
 
	return 0;
}


Measured memory_bytes: 916
#include<stdio.h>
int main()
{
    long int n,k,x,y,s=0;
    scanf("%ld %ld %ld %ld",&n,&k,&x,&y);
    if(n<k)
        s=n*x;
    else s=(k*x+(n-k)*y);
    printf("%ld",s);
    return 0;
}


Measured memory_bytes: 128
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;


int main(){
int A,B;
cin >> A >> B;
int counter = 0;
for(int i = A; i <= B; i++){
    string s = to_string(i);
    string S = to_string(i);
    reverse(S.begin(), S.end());
    if(s == S)counter++;
}

cout << counter << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+9;
const double ep=1e-7;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double pi=acos(-1);
#define debug1 puts("?");
#define debug(x) cout<<"##"<<(x)<<endl;
#define mk make_pair
#define PII pair<int,int>
#define PIII pair<int,PII >
#define PIII1 pair<PII,int>
#define PIL pair<int,ll>
#define PLL pair<ll,ll>
#define eb emplace_back
#define fi first
#define se second
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define dep(i,a,b) for(register int i=(a);i>=(b);--i)
#define sd(x) scanf("%d",&(x))
#define slld(x) scanf("%lld",&(x))
#define sdd(x,y) scanf("%d%d",&(x),&(y))
#define sc(s) scanf("%s",(s))
#define pd(x) printf("%d\n",(x))
#define plld(x) printf("%lld\n",(x))
#define pdk(x) printf("%d ",(x))
#define plldk(x) printf("%lld ",(x))
#define pdd(x,y) printf("%d %d\n",(x),(y))
typedef long long ll;
ll n,dp[maxn][4];//0-9 1-0 2-0,9 3-~
void solve()
{
	slld(n);
	dp[0][3]=1;
	rep(i,1,n)
	{
		dp[i][0]=(dp[i-1][0]*9+dp[i-1][3])%mod;
		dp[i][1]=(dp[i-1][1]*9+dp[i-1][3])%mod;
		dp[i][2]=(dp[i-1][0]+dp[i-1][1]+dp[i-1][2]*10)%mod;
		dp[i][3]=(dp[i-1][3]*8)%mod;
	}
	plld(dp[n][2]);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T=1;
//	sd(T);
	while(T--)solve();
} 

Measured memory_bytes: 35036
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        x_1: i64,
        y_1: i64,
        x_2: i64,
        y_2: i64,
    }
    let l = ((((x_1 - x_2).abs()).pow(2) + ((y_1 - y_2).abs()).pow(2)) as f64).sqrt();
    let  y_3 = y_2 - (x_1 - x_2);
    let  x_3 = x_2 - (y_2 - y_1);
    let  y_4 = y_1 - (x_1 - x_2);
    let  x_4 = x_1 - (y_2 - y_1);
    println!("{} {} {} {}", x_3, y_3, x_4, y_4);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    ll n = s.size();
    ll k;
    cin >> k;

    rep(i, min(n, k)) {
        if (s[i] == '1') continue;
        cout << s[i] << endl;
        return 0;
    }
    cout << 1 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P =  pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

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

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

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

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



int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n,-1) {}

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

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

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return false;
    if(par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  
  int size(int x) {
    return -par[root(x)];
  }
};


  


int main() {
  int N,M,K;
  cin >> N >> M >> K;
  UnionFind uf(N);
  vector<set<int>> v(N);
  
  rep(i,M) {
    int a,b;
    cin >> a >> b;
    a--;b--;
    uf.merge(a,b);
    v[a].insert(b);
    v[b].insert(a);
  }
  rep(i,K) {
    int a,b;
    cin >> a >> b;
    a--;b--;
    if(uf.issame(a,b)) {
      v[a].insert(b);
      v[b].insert(a);
    }
  }

  rep(i,N) {
    int ans = uf.size(i) - v[i].size() - 1;
    cout << ans << endl;
  }
  
  return 0;
}














Measured memory_bytes: 22272
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
int a[MAX_N];

int dist(int n, int k)
{
	if (n % 2 == 0)
	{
		return abs(n/2-k);
	}
	else
	{
		return min(abs(n/2-k),abs(n/2-k+1));
	}
}

int main()
{
	int n;
	cin >> n;
	rep(i,n)
	{
		cin >> a[i];
	}
	sort(a,a+n);
	int ans1 = a[n-1],ans2 = a[0];
	rep(i,n-1)
	{
		if (dist(ans1,a[i]) < dist(ans1,ans2))
		{
			ans2 = a[i];
		}
	}
	cout << ans1 << " " << ans2 << endl;
	return 0;
}

Measured memory_bytes: 640
def print_arr(arr):
    for i in range(len(arr)):
        print(arr[i],sep=" ",end="")
    print()
    

from operator import itemgetter
n = int(input())
a=[]
b=[]
arr = [[0]*n for _ in range(n)]
for i in range(n):
    a.append(list(map(int,input().split())))
    a[-1].append(0)
for i in range(n):
    b.append(list(map(int,input().split())))
    b[-1].append(0)
b.sort(key=itemgetter(0))
a.sort(key=itemgetter(1))
a = a[::-1]
count = 0
for i in range(n):
    for j in range(n):
        if a[j][2] == 0 and b[i][2] == 0:
            if b[i][0] - a[j][0] > 0 and b[i][1] - a[j][1] > 0:
                count += 1
                a[j][2] = 1
                b[i][2] = 1
                continue
            
print(count)

Measured memory_bytes: 3188
n = gets.to_i

t,a = gets.split.map(&:to_i)

harray = gets.split.map(&:to_i)

min = 10**20
ans = -1
i = 0

n.times{
    
    key = (t-0.006*harray[i]-a).abs
    
    
    
    if key<min
    min = [min,key].min
    ans = i
    end
    i+=1
}



p ans+1

Measured memory_bytes: 1788
inputLine=input()
A=int(inputLine.split(" ")[0])
B=int(inputLine.split(" ")[1])
C=int(inputLine.split(" ")[2])
K=int(inputLine.split(" ")[3])

result=0

if A >= K:
    result = 1 * K

else:
    if A + B >= K:
        result = (1 * A) + (0 * (K - A)) 

    else:
        result = (1 * A) + (0 * B) + (-1 * (K - A - B))

print(result)





Measured memory_bytes: 9192
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
namespace mp = boost::multiprecision;

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

	ll a, b = 0;
	string s;
	cin >> a >> s;

	rep(i, s.length()) {
		if (s[i] != '.') {
			b *= 10;
			b += s[i] - '0';
		}
	}

	a *= b;
	a /= 100;
	cout << a << "\n";

	return 0;
}



Measured memory_bytes: 3640
main :: IO ()
solve :: [Int] -> Int -> Int
solve [] res = res
solve (x:xs) res = solve xs res'
  where res' = if abs x < abs res
               then x
               else res

main = do
  [n, l] <- map read . words <$> getLine
  let tastes = map (\n -> l + n - 1) [1..n]
  print $ sum tastes - solve tastes 1000 


Measured memory_bytes: 508
#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 M;
    cin >> M;

    p(24-M + 24);
    return 0;
}

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

int N;
cin >> N;
int a[N];
rep(i,N) cin >> a[i];
int sum=0;
rep(i,N) sum+=a[i]-1;
cout << sum << endl;


}

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

const int maxn = 2e5 + 5;

int n, a[maxn], k;
vector<int> fucks;

bool isSorted(int l, int r) {
	r--;
	return upper_bound(fucks.begin(), fucks.end(), r) == lower_bound(fucks.begin(), fucks.end(), l);
}

int main(int argc, char const *argv[])
{
	// freopen("in", "r", stdin);
	cin >> n >> k;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		if(i != 1) {
			if(a[i-1] > a[i]) {
				fucks.emplace_back(i-1);
			}
		}
	}
	int took_identical = 0, ans = 1;
	if(isSorted(1, k)) took_identical = 1;

	set<int> st;
	for(int i = 2; i <= k; i++) {
		st.insert(a[i]);
	}
	for(int l = 1, r = k + 1; r <= n; l++, r++) {
		if(a[l] < *st.begin() and *st.rbegin() < a[r]) {}
		else {
			if(isSorted(l + 1, r)) {
				if(!took_identical) {
					took_identical = 1;
					ans++;
				}
			} else {
				ans++;
			}
		}
		st.erase(a[l + 1]);
		st.insert(a[r]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10744
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
int n,a;
int t[1000];
int x,y;
int main(){
cin>>n;
rep(i,n)cin>>t[i];
sort(t,t+n);

bool f=1;
for(int i=n-1;i>=0;i--){
	if(f)x+=t[i];
	else y+=t[i];

	f=!f;
}

cout<<x-y<<endl;
	return 0;
}

Measured memory_bytes: 256
my $n = <STDIN>;
my @heights = split / /, <STDIN>;
my $prev_max_height = 0;
my $count = 0;
for my $h (@heights) {
	if ($prev_max_height <= $h) {
    	$prev_max_height = $h;
		$count++;
	}
}
print $count, "\n";

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> b(n-1, 0);
    for (int i=0; i<n-1; i++) cin >> b[i];

    vector<int> a(n, 0);
    for (int i=1; i<n; i++) a[i] = min(b[i-1], b[i]);

    a[0] = b[0];
    a[n-1] = b[n-2];
    for (auto ai : a) cerr<<ai<<" ";cerr<<endl;
    int ans = accumulate(a.begin(), a.end(), 0);

    cout << ans << endl;
}
/*
N
B1 B2 ... Bn-1

3
 2 5
? 5 ?
2 = max(a_1, a_2)
a_0 と a_n は特殊処理
a_i = min(b_i-1, b_{i})
*/

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;
    cin >> a >> b;
    if((a >= 1 && a <= 9) && (b >= 1 && b<= 9)){
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }
}


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)1e5+1;
int N, dist[MAXN], dist2[MAXN], maxDist, ans;
vector<int> g[MAXN];
bool v[MAXN], v2[MAXN];
void dfs(int x)
{

    queue<int> q;
    q.push(x);
    while(!q.empty())
    {
        int a = q.front();
        q.pop();
        v[a] = true;
        for(int i=0; i<g[a].size(); i++)
        {
            if(v[g[a][i]])
                continue;
            dist[g[a][i]] = dist[a]+1;
            q.push(g[a][i]);
        }
    }
}

void dfs2(int x)
{
    queue<int> q;
    q.push(x);
    while(!q.empty())
    {
        int a = q.front();
        q.pop();
        v2[a] = true;
        for(int i=0; i<g[a].size(); i++)
        {
            if(v2[g[a][i]])
                continue;
            dist2[g[a][i]] = dist2[a]+1;
            q.push(g[a][i]);
        }
    }
}



int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int u, v;
    cin >> N >> u >> v;
    u--;
    v--;
    for(int i=0; i<N-1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    dfs(v);
    dfs2(u);
    for(int i=0; i<N; i++)
    {
        if(dist[i] < dist2[i])
        {
            continue;
        }
        ans = max(ans, dist[i]);
    }
    cout << ans-1;

    return 0;
}


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

int32_t main(){
	
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}

	int idx=0,temp=n;

	while(temp>0){
		if(temp==k){
			idx++;
			break;
		}
		else
		{
			temp=temp-(k-1);
			idx++;
		}
	}

	cout<<idx<<endl;

}




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

int main(){
    int N,A,B,pass=0,rank=0;
    cin>>N>>A>>B;
    string S;
    cin>>S;
    for(int i=0;i<S.size();++i){
        if(S.at(i)=='a'){
            if(pass<A+B){
                ++pass;
                cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }
        }else if(S.at(i)=='b'){
            ++rank;
            if(pass<A+B&&rank<=B){
                ++pass;
                cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }
        }else{
            cout<<"No"<<endl;
        }
    }
}


Measured memory_bytes: 896
import numpy as np

N = int(input())
t = [0]*N
x = [0]*N
y = [0]*N
for i in range(N):
    t[i],x[i],y[i] = map(int,input().split())
if t[0] >= x[0]+y[0]:
    pass
else:
    print('No')
    exit()
if (t[0]+x[0]+y[0]) % 2 == 0:
    pass
else:
    print('No')
    exit()
t = np.diff(t)
x = np.diff(x)
y = np.diff(y)

for a,b,c in zip(t,x,y):
    if a >= abs(b)+abs(c):
        pass
    else:
        print('No')
        exit()
    if (abs(a)+abs(b)+abs(c)) % 2 == 0:
        pass
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 22244
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(vector<T> a){
    for (const auto& ai : a) cout << ai << " ";
    cout << endl;
}
vector<string> Yes = {"No", "Yes"};
int check(vlint y, int r){
    for (auto& p : y){
        if (p < r) return 0;
    }
    return 1;
}
int main(){
    INT(n, m, x);
    vlint cost(n);
    vector<vlint> a(n, vlint(m));
    rep(i, n){
        cin >> cost[i];
        line(a[i]);
    }
    lint ans = 100000000;
    lint c; vlint ax(m);
    rep(i, (1 << n)){
        c = 0; fill(all(ax), 0);
        rep(j, n){
            if (i & (1 << j)){
                c += cost[j];
                rep(k, m){
                    ax[k] += a[j][k];
                }
            }
        }
        if (check(ax, x)) chmin(ans, c);
    }
    if (ans == 100000000){
        cout << -1 << endl;
    }
    else{
        cout << ans << endl;
    }
}


Measured memory_bytes: 3580
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int a;
    cin >> a;
    int ans = a + pow(a, 2) + pow(a, 3);
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  long a,b;cin>>a>>b;
  if (a==1 or b==1) cout << 1;
  else {
  long c = (a*b+1) / 2;
  cout << c;
  }
}


Measured memory_bytes: 256
n,m=[int(x) for x in input().split()]
s=[]
for i in range(m):
  k=[int(x) for x in input().split()]
  s.append(k)
p=[int(x) for x in input().split()]

import itertools
l=[]
a=itertools.product(range(2),repeat=n)
for i in a:
  l.append(i)

ans=0
for i in range(2**n):
  ok=[]
  for j in range(m):
    on=0
    for t in range(1,s[j][0]+1):
      e=s[j][t]
      if l[i][e-1]==1:
        on+=1
    if on%2!=p[j]:
      ok.append(False)
  if False not in ok:
    ans+=1

print(ans)

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

for i in range(n):
    for j in range(l):
        print(sum([A[i][k] * B[k][j] for k in range(m)]), end=" " if j < l - 1 else "\n")



Measured memory_bytes: 6580
"use strict"
function Main(input) {
  input = input.trim().split('\n');
  let S = input[1];
  const trg = 'ABC';

  let ret = 0;
  while(true){
    let num = S.indexOf(trg)
    if(num !== -1){
      S = S.slice(num+3);
      ret += 1;
    } else {
      break;
    }
  }

  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    vector<int> v(n);
    for(int&i:v)cin>>i;
    
    sort(v.begin(),v.end(),greater<int>());
    int ans=0;
    for(int i=0; i<n; i++){
        ans+=(i%2?-v[i]:v[i]);
    }
    cout<<ans;
    
   
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
  long long ans=0;
  long long n,m;
  cin>>n>>m;
  cout<<(n*3+m)/2<<endl;
}


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

int main(){
    bool cards[4][14];
    int n, number;
    char mark;
    
    for(int i = 0; i < 4; i++){
        for (int j = 1; j <= 13; j++){
            cards[i][j] = 0;
        }
    }
    
    cin >> n;
    for (int t = 0; t < n; t++){
        cin >> mark >> number;
        if (mark == 'S') cards[0][number] = 1;
        if (mark == 'H') cards[1][number] = 1;
        if (mark == 'C') cards[2][number] = 1;
        if (mark == 'D') cards[3][number] = 1;
    }
    for (int i = 0; i < 4; i++){
        for (int j = 1; j <= 13; j++){
            if(cards[i][j]) continue;
            if(i == 0) mark = 'S';
            if(i == 1) mark = 'H';
            if(i == 2) mark = 'C';
            if(i == 3) mark = 'D';
            cout << mark << " " << j << endl;
        }
    }
    return 0;
}


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

void fnInput(vector<int>& rvnSeq)
{
  int nSeqSiz;
  cin >> nSeqSiz;
  rvnSeq.resize(nSeqSiz);

  for (int& rnSeq : rvnSeq)
    cin >> rnSeq;
}
  
int fnLowerCnt(const vector<int>& cnrvnSeq)
{
  int nMaxSeqCnt = 0;
  int nBgn = 0;

  while (nBgn < cnrvnSeq.size() - 1)
  {
    int nSeqCnt = 0;
    int nFoward = nBgn;

    while ( nFoward < cnrvnSeq.size() - 1  &&
            cnrvnSeq[nFoward] >= cnrvnSeq[nFoward + 1] )
    {
      nSeqCnt++;
      nFoward++;
    }
    nMaxSeqCnt = max(nMaxSeqCnt, nSeqCnt);
    nBgn = nFoward + 1;
  }
  return nMaxSeqCnt;
}
  
int main()
{
  vector<int> vnSeq;

  fnInput(vnSeq);
  cout << fnLowerCnt(vnSeq) << endl;

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll a,b,c;
    cin >> a >> b >> c;
    ll res = 0;
    if(b>=c){
        res += b+c;
    }else{
        if(a+b>=c){
            res += b+c;
        }else{
            res += a+2*b+1;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	int N;
	int a[100010];
	cin >> N;
	int countone = 0, countfour = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		if (a[i] % 4 == 0)countfour++;
		else if (a[i] % 2 != 0)countone++;
	}
	if (countfour + countone != N)countone++;
	if (countone > countfour + 1) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#define MAX 100010
using namespace std;

int main(){
  int a, b, c;
  while(cin>>a>>b>>c){
    int less = 20 - a - b;
    int win_num = 0;
    for(int i = 1; i <= 10; i++){
      if(i == a || i == b || i == c){
        continue;
      }
      if(less >= i) win_num++;
    }
    if(win_num >= 4){
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 3080
n = int(input())
ac_count = 0
wa_count = 0
tle_count = 0
re_count = 0
for i in range(n):
    s = input()
    if s == 'AC':
        ac_count += 1
    elif s == 'WA':
        wa_count += 1
    elif s == 'TLE':
        tle_count += 1
    elif s == 'RE':
        re_count += 1
    else:
        continue

print('AC x ' + str(ac_count))
print('WA x ' + str(wa_count))
print('TLE x ' + str(tle_count))
print('RE x ' + str(re_count))

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

using namespace std;

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

    if (n % 2 == 0) printf("%.12lf\n", 0.5);
    else printf("%.12lf\n", 1.0 * (n + 1) / 2 / n);
}


Measured memory_bytes: 256
class CheckError(Exception):
    pass

def check(wclist, count):
    c = 0
    while True:
        c += wclist.pop(0)
        if c == count:
            return wclist
        elif c > count:
            raise CheckError

def tanku_check(wclist):
    for i in range(len(wclist)):
        try:
            wcl = wclist[:][i:]
            wcl = check(wcl, 5)
            wcl = check(wcl, 7)
            wcl = check(wcl, 5)
            wcl = check(wcl, 7)
            wcl = check(wcl, 7)
            return i+1
        except CheckError:
            pass

def main():
    while True:
        n = int(input().strip())
        if n == 0:
            break
        wclist = [len(input().strip()) for _ in range(n)]
        print(tanku_check(wclist))

if __name__ == '__main__':
    main()



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

int main() {
  string s;
  ll k;
  cin >> s >> k;
  for (ll i = 0; i < k; i++) {
    if (s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
//#define out(a) cout<<fixed<<setprecision((a))
#define YesNo(a) cout<<((a)?"Yes":"No")<<endl
#define YESNO(a) cout<<((a)?"YES":"NO")<<endl



int main(){

	ll n,ans=0;
	cin >> n;
	vector<ll> a(n),x;
	FOR(i,0,n) cin >> a[i];

	SORT(a);

	FOR(i,0,n){
		FOR(j,i+1,n){
			ll ind = POSU(a,a[j]-a[i]);
			ans += max(0LL,i-ind);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
class PriorityQueue
  def initialize(&comp)
    @heap = []
    @node_num = 0
    if !block_given?
      @comp = lambda { |x, y| x <= y }
    else
      @comp = comp
    end
  end

  def push(x)
    i = @node_num # 自分のノード番号
    @node_num += 1
    while i > 0
      par = (i - 1) / 2 # 親のノード番号
      break if @comp.call(@heap[par], x) # 逆転してないなら抜ける
      # 親ノードを下ろして自分を上に
      @heap[i] = @heap[par]
      i = par
    end
    @heap[i] = x
  end

  alias_method(:<<, :push)

  def pop
    # 最(小|大)値
    ret = @heap[0]
    # 根にもってくる値
    @node_num -= 1
    x = @heap[@node_num]
    # 根から下ろしていく
    i = 0
    while i * 2 + 1 < @node_num
      # 子どうしを比較
      a, b = i * 2 + 1, i * 2 + 2
      a = b if b < @node_num && !@comp.call(@heap[a], @heap[b])
      break if @comp.call(x, @heap[a])
      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    return ret
  end

  def get
    @node_num == 0 ? nil : @heap[0]
  end

  def empty?
    return get.nil?
  end
end
def dijkstra(graph, start, inf = Float::INFINITY)
  vertex_num = graph.size
  que = PriorityQueue.new { |x, y| x[0] <= y[0] }
  dist = Array.new(vertex_num, inf)
  dist[start] = 0
  que.push([0, start])
  while !que.empty?
    d, v = que.pop
    next if dist[v] < d
    graph[v].size.times do |i|
      # e is an instance of Edge
      #   Edge = Struct.new(:to, :cost)
      e = graph[v][i]
      if dist[e.to] > dist[v] + e.cost
        dist[e.to] = dist[v] + e.cost
        que.push([dist[e.to], e.to])
      end
    end
  end
  return dist
end

n=gets.to_i
g = Array.new(n){[]}
Edge = Struct.new(:to, :cost)
(n-1).times do
  a,b,c = gets.split.map(&:to_i)
  a -= 1
  b -= 1
  g[a] << Edge.new(b, c)
  g[b] << Edge.new(a, c)
end
q,k=gets.split.map(&:to_i)
d = dijkstra(g, k-1)
ans = []
q.times do
  x,y = gets.split.map(&:to_i)
  ans << d[x-1] + d[y-1]
end
puts ans

Measured memory_bytes: 46532
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int V, E;
	cin >> V >> E;
	vector<vector<int> > G(V);
	for(int i = 0; i < E; ++i) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> dp(V, 1 << 30), par(V), depth(V);
	vector<bool> vis(V, false);
	vector<vector<int> > child(V);
	function<void(int, int)> dfs = [&](int pos, int pre) {
		par[pos] = pre;
		vis[pos] = true;
		dp[pos] = depth[pos];
		for(int i : G[pos]) {
			if(i == pre) continue;
			if(!vis[i]) {
				child[pos].push_back(i);
				depth[i] = depth[pos] + 1;
				dfs(i, pos);
				dp[pos] = min(dp[pos], dp[i]);
			}
			else {
				dp[pos] = min(dp[pos], depth[i]);
			}
		}
	};
	for(int i = 0; i < V; ++i) {
		if(!vis[i]) {
			dfs(i, -1);
		}
	}
	for(int i = 0; i < V; ++i) {
		if(par[i] == -1) {
			if(child[i].size() >= 2) {
				cout << i << '\n';
			}
		}
		else {
			bool ok = false;
			for(int j : child[i]) {
				if(dp[j] >= depth[i]) {
					ok = true;
				}
			}
			if(ok) {
				cout << i << '\n';
			}
		}
	}
	return 0;
}


Measured memory_bytes: 5020
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

typedef pair<int,int> P;
const int max_n = 100000+19;
int N,M;

const int inf = 1001001001;
vector<int> G[max_n];
int S,T;
int dist[max_n][3];

int solve(void) {
    for(int i = 1;i <= N;i++) {
        for(int j = 0;j < 3;j++) {
            dist[i][j] = inf;
        }
    }

    queue<P> q;
    q.push(P(S, 0));
    dist[S][0] = 0;
    while(!q.empty()) {
        int u = q.front().first;
        int l = q.front().second;
        q.pop();
        for(auto v: G[u]) {
            int nl = (l+1)%3;
            if(dist[v][nl] != inf)
                continue;
            dist[v][nl] = dist[u][l]+1;
            q.push(P(v,nl));
        }
    }

    int ans = dist[T][0];
    if(ans == inf)
        return -1;

    return ans/3;
}

int main(void) {
    cin>>N>>M;
    for(int i = 0;i < M;i++) {
        int u,v;
        cin>>u>>v;

        G[u].push_back(v);
    }
    cin>>S>>T;

    cout<<solve()<<endl;

    return 0;
}





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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;
	VL h(n);
	rep(i, n) cin >>h[i];
	sort(h.rbegin(), h.rend());
	rep(i, min(k, n)) h[i]=0;
	cout << accumulate(all(h), 0LL) <<"\n";
	return 0;
}


Measured memory_bytes: 1792
def solve():
  n = int(input())
  h = list(map(int, input().split()))
  ans, now = 0, 0
  for i in range(n-1):
    if h[i] < h[i+1]:
      now = 0
    else:
      now += 1
      if ans < now:
        ans = now
  print(ans)
  return 0
 
if __name__ == "__main__":
  solve()


Measured memory_bytes: 14252
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;

const long long MOD = 1000000007;

int main(){
    int n, l;
    cin >> n >> l;
    int s = 0;
    int a[n];
    int m = 1<<30;
    int m_i = 0;
    for(int i = 0; i < n; i++){
        a[i] = l+i;
        s += a[i];
        if(abs(a[i]) < m){
            m = abs(a[i]);
            m_i = i;
        }
    }
    
    cout << s-a[m_i] << endl;
    
    return 0;
}


Measured memory_bytes: 888