akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <limits.h>
#define N 100010
using namespace std;
const int INF = 2147483647;
struct no{
    int v;//value
    int l;//left
    int r;//right
}t[4*N];
int n, m;
int a[N];//这个数组貌似没有什么用
int cnt = 0;//树中节点的个数
void build(int i, int l, int r){
    cnt++;
    t[i] = (no){INF, l, r};
    if(l == r) return ;
    int mid = (l + r)/2;
    build(2*i, l, mid);
    build(2*i+1, mid+1, r);
}
void pushup(int i){
    t[i].v = min(t[2*i].v, t[2*i+1].v);
}
void update(int i, int x, int k){//当前节点是i，改动的节点是x，x的值改为了k
    //t[i].v = min(t[i].v, k);
    if(t[i].l == t[i].r) {
        if(t[i].l == x) t[i].v = k;
        return ;
    }
    if(x <= t[2*i].r) update(2*i, x, k);
    if(t[2*i+1].l <= x) update(2*i+1, x, k);
    pushup(i);
}
int minv = INF;
void query(int i, int l, int r){
    if(l <= t[i].l && t[i].r <= r){
        minv = min(minv, t[i].v);
        return ;
    }
    if(l <= t[2*i].r){
        query(2*i, l, r);
    }
    if(t[2*i+1].l <= r){
        query(2*i+1, l, r);
    }
}
int main() {
    fill(a, a+N, INF);
    scanf("%d %d", &n, &m);
    build(1, 1, n);
    for(int i = 0; i < m; i++){
        int op, b, c;
        scanf("%d %d %d", &op, &b, &c);
        if(op == 0){//因为b的下标是从0开始的
            update(1, b+1, c);
        }else if(op == 1){//因为b和c的下标都是从0开始的
            minv = INF;
            query(1, b+1, c+1);
            printf("%d\n", minv);
        }
    }
    return 0;
}



Measured memory_bytes: 6676
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline void write_bool(bool b, const string &tval, const string &fval) {
  cout << (b ? tval : fval) << endl;
} 
inline void YESNO(bool b) { return write_bool(b, "YES", "NO"); }
inline void YesNo(bool b) { return write_bool(b, "Yes", "No"); }
inline void yesno(bool b) { return write_bool(b, "yes", "no"); }


int main() {
  int n;
  while (cin >> n) {
    vint v(n);
    REP(i,n) cin >> v[i];
    REP(i,n) {
      if (i == 0) continue;
      if (v[i-1] < v[i]) v[i]--;
    }
    bool ok = true;
    REP(i,n-1) if (v[i] > v[i+1]) ok = false;
    YesNo(ok);
  }
}


Measured memory_bytes: 888
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::collections::HashSet;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let mut a = vec![vec![];n];
    for i in 0..n {
        a[i] = arr(n-1, |_| scan.read::<usize>()-1);
        a[i].reverse();
    }
    let mut env = Env {a: a, t: HashSet::new()};
    for i in 0..n {
        env.check(i);
    }
    let mut day = 0i64;
    while !env.t.is_empty() {
        let t_c = env.t.clone();
        env.t = HashSet::new();
        for &(p, q) in &t_c {
            env.a[p].pop();
            env.a[q].pop();
        }
        for (p, q) in t_c {
            env.check(p);
            env.check(q);
        }
        day += 1;
    }
    for i in 0..n {
        if env.a[i].len() > 0 {
            println!("{}", -1);
            return;
        }
    }
    println!("{}", day);
}

struct Env {
    a: Vec<Vec<usize>>,
    t: HashSet<(usize, usize)>
}
impl Env {
    fn check(&mut self, i: usize) {
        if let Some(&j) = self.a[i].last() {
            if let Some(&op_next) = self.a[j].last() {
                if op_next == i {
                    if i < j {self.t.insert((i, j));}
                    else {self.t.insert((j, i));}
                }
            }
        }
    }
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 12540
N,K = map(int,input().split())
bills = list(map(int,input().split()))
ans = 0
k = 0
while k < K:
	k = 0
	cost =[]
	cosd = {}
	tatekae = {}
	maxh = 0
	for bi,b in enumerate(bills):
		if b > maxh:
			cost.append(0)
			maxh = b
			k = k + 1
		else:
			c = maxh - b + 1
			cost.append(c)
			maxh2 = maxh + 1
			tatekae[bi] = []
			for b2i,b2 in enumerate(bills[bi:]):
				if maxh2 < b2:
					break
				elif maxh2 == b2:
					c = c + 1
					maxh2 = maxh2 + 1
					tatekae[bi].append(b2i + bi)
			cosd[bi] = c
	if k >= K:
		break
	a = min(cosd.items(),key =lambda x: x[1])[0]
	ans = ans + cosd[a]
	bills[a] = bills[a] + cost[a]
	for t in tatekae[a]:
		bills[t] = bills[t] + 1
	k = k + 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
// const ll MOD=998244353;

int main(){
  int N; cin>>N;
  int A[N]; rep(i,N) cin>>A[i];
  double ans=0;
  rep(i,N){
    ans+=1.0/A[i];
  }
  cout<<setprecision(15);
  cout<<1.0/ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    getline(cin,s);
    for(int i=0;i<s.size();i++)
    {
	   if(s[i]=='C')
	   	for(int j=i+1;j<s.size();j++)
		 if(s[j]=='F'){
		 	printf("Yes\n");
		 	return 0;
	   }
	}
	printf("No\n");
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	D := ReadInt()
	cs := ReadInts(26)
	ss := make([][]int, D)
	for i := 0; i < D; i++ {
		ss[i] = ReadInts(26)
	}

	answers := []int{}
	last := make([]int, 26)

	for d := 1; d <= D; d++ {
		maxT, maxScore := -1, math.MinInt32
		for i := 0; i < 26; i++ {
			s := ss[d-1][i] - cs[i]*(d-last[i])
			if s > maxScore {
				maxT, maxScore = i, s
			}
		}
		last[maxT] = d
		answers = append(answers, maxT)
	}

	for _, v := range answers {
		fmt.Println(v + 1)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;
const int nmax=101234;

int n;
ll a[412],dp[412][412],s[412],res;

ll DP(ll l,ll r)
{
    if(dp[l][r] || l==r)
        return dp[l][r];
    dp[l][r]=DP(l,l)+DP(l+1,r);
    for(int i=l+1; i<r; ++i)
        dp[l][r]=min(dp[l][r],DP(l,i)+DP(i+1,r));
    dp[l][r]+=s[r]-s[l-1];
    return dp[l][r];
}

int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; ++i)
    {
        scanf("%lld",&a[i]);
    }
    for(int i=1; i<=n; ++i)
    {
        s[i]=s[i-1]+a[i];
        dp[i][i]=0;
    }
    res=DP(1,n);
    printf("%lld",res);
    return 0;
}


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

int main() {
  while (1)
  {
    int h, w;
    cin >> h >> w;

    for (int i = 0; i < h; i++)
    {
      for (int j = 0; j < w; j++)
      {
        if (i % 2 == 0) {
          if (j % 2 == 0) {
            cout << "#";
          } else {
            cout << ".";
          }
        } else {
          if (j % 2 == 0) {
            cout << ".";
          } else {
            cout << "#";
          }
        }
      }
      cout << endl;
    }

    if (h == 0 && w == 0)
    {
      break;
    }

    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include<cmath>
#include<algorithm>
using namespace std;

pair<long long int,long long int> ar[100005];

double dist(int i,int j){
	return sqrt(pow(ar[i].first-ar[j].first,2)+pow(ar[i].second-ar[j].second,2));
}

int main() {
	int n;
	cin>>n;
	int per[n];
	for(int i=0;i<n;i++)
		per[i]=i;
	double ans=0;
	for(int i=0;i<n;i++)
		scanf("%lld %lld",&ar[i].first,&ar[i].second);//cin>>ar[i].first>>ar[i].second;
	
	int g=1;
	for(int i=2;i<=n;i++)
		g*=i;
	int tmp=g;
	
	while(tmp--){
		double t=0;
		for(int i=0;i<n-1;i++){
			t+=dist(per[i],per[i+1]);
		}
		ans+=t;
		next_permutation(per,per+n);
	}
	printf("%.10f",ans/g);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

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

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint a; string s;
    cin >> a >> s;
    cout << (a >= 3200 ? s : "red") << "\n";
}

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

int main(){
    int n, h;
    cin >> n >> h;

    vector<int> a(n), b(n);
    int maxid = 0;
    int a_ = 0;
    rep(i, n){
        cin >> a[i] >> b[i];
        if(a_ < a[i]){
            maxid = i;
            a_ = a[i];
        }
    }

    vector<int> cand;
    rep(i, n){
        if(b[i]>a_) cand.emplace_back(b[i]);
    }

    sort(cand.begin(), cand.end(), greater<>());

    int ans = 0;
    for(auto bi: cand){
        h -= bi;
        ans++;
        if(h<=0) break;
    }

    if(h>0){
        int q = h%a_;
        int p = h/a_;
        ans += p;
        if(q>0) ans++;
    }

    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 1660
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}
fn main() {
    let _n: usize = read()[0];
    let a: Vec<usize> = read();
    let cnt = a.iter().filter(|&&x| x % 2 == 1).count();
    println!("{}", if cnt % 2 == 0 { "YES" } else { "NO" });
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mod 1e9+7
#define all(x) x.begin(),x.end()

int main() {
	ios_base::sync_with_stdio(false);
	cout.tie(0); cin.tie(0);
	string s;
	cin>>s;
	ll l;
	l=s.length();
	int a[l];
	ll sum=0;
	for(ll i=0;i<l;i++)
	{
	     a[i]=s[i]-'0';
	     sum+=a[i];}
	     if(sum%9==0)
	     cout<<"Yes";
	     else
	     cout<<"No";
	     
}

Measured memory_bytes: 4520
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int number=0;
    for(int i=a;b-i>=0;b=b-i){
        number++;
        if(number==c){
            cout<<c<<endl;
            return 0;
        }
    }
    cout<<number<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<climits>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=(b);i>=(a);i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX

int main(void){
	while(1){
		int a[5];
		scanf("%d",a);
		if(a[0]==0)break;
		int is[3]={};
		rep(i,4){
			scanf("%d",&a[i+1]);
		}
		rep(i,5){
			a[i]--;
			is[a[i]]=1;
		}
		rep(i,5){
			int ans;
			int no = a[i];
			int s=0;
			rep(j,2)if(is[(no+j+1)%3]==1)s+=j+1;
			//printf("    %d\n",s);
			if(s==0 || s==3)ans=3;
			else if(s==1)ans=1;
			else ans=2;
			printf("%d\n",ans);
		}
	}
		
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)

const ll mod = 1e+9 + 7;
const int maxn = 200000 + 10;
ll fact[maxn];
ll rfact[maxn];

ll gcdex(ll a, ll b, ll & x, ll & y)
{
    if (a == 0)
    {
        x = 0; y = 1;
        return b;
    }
    
    ll x1, y1;
    ll d = gcdex(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

ll get(ll a, ll m)
{
    ll x, y;
    ll g = gcdex (a, m, x, y);
    if (g != 1)
    {
        x = -1;
    }
    else
    {
        x = (x % m + m) % m;
    }
    return x;
}

void precalc()
{
    fact[0] = 1;
    rfact[0] = 1;
    for(int i = 1; i < maxn; i++)
    {
        fact[i] = fact[i - 1] * i;
        fact[i] %= mod;
        rfact[i] = get(fact[i], mod);
    }
}



ll cnm(ll m, ll n)
{
    return (fact[n] * ((rfact[n - m] * rfact[m]) % mod)) % mod;
}

ll f(ll m, ll n)
{
    return cnm(m - 1, m + n - 2);
}

void solve()
{
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    precalc();
    ll res = 0;
    for(ll i = b + 1; i <= w; i++)
    {
        res += (f(h - a, i) * f(a, w - i + 1)) % mod;
        res %= mod;
    }
    cout << res << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    solve();
    return 0;
}

Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace lean {
    class Program {
        static void Main() {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(p);
            int goke = 0;
            for (int i = 0; i < a[1]; i++)
            {
                goke += p[i];
            }
            Console.WriteLine(goke);
        }
    }
}

Measured memory_bytes: 28336
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

static int N;
static vector<int> X;
static vector<int> Y;
static vector<long long> H;

void solve(int x0, int y0, long long h0) {
  for (int cx = 0; cx <= 100; cx++) {
    for (int cy = 0; cy <= 100; cy++) {
      long long ch = h0 + abs(x0 - cx) + abs(y0 - cy);
      bool flag = true;
      for (int i = 0; i < N; i++) {
        long long temp = ch - (abs(X[i] - cx) + abs(Y[i] - cy));
        if (temp < 0) {
          temp = 0;
        }
        if (temp != H[i]) {
          flag = false;
          break;
        }
      }
      if (flag) {
        printf("%d %d %lld\n", cx, cy, ch);
        return;
      }
    }
  }
}

int main() {
  cin >> N;
  X.resize(N);
  Y.resize(N);
  H.resize(N);
  int x0 = 0;
  int y0 = 0;
  long long h0 = 0;
  for (int i = 0; i < N; i++) {
    int x, y;
    long long h;
    cin >> x >> y >> h;
    X[i] = x;
    Y[i] = y;
    H[i] = h;
    if (h > 0) {
      x0 = x;
      y0 = y;
      h0 = h;
    }
  }
  solve(x0, y0, h0);
  return 0;
}

Measured memory_bytes: 888
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;
typedef long long ll;

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

    reverse(s.begin(), s.end());
    while (s.size() != 0)
    {
        if (s.substr(0, 5) == "maerd" || s.substr(0, 5) == "esare") {
            s.erase(0, 5);
        } else if (s.substr(0, 6) == "resare") {
            s.erase(0, 6);
        } else if (s.substr(0, 7) == "remaerd") {
            s.erase(0, 7);
        } else {
            break;
        }
    }

    if (s.size() == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

}


Measured memory_bytes: 512
## coding: UTF-8
#import sys

N, K = map(int,input().split())
h = list(map(int,input().split()))
dp = [-1] * N
dp[0] = 0

for i in range(1, N):
    l = []
    m = min(K, i)
    #print()
    #print(m)
    #print('i:{}, m:{}'.format(i, m))
    for j in range(1, m+1):
        #print('i:{}, j:{}, i-j:{}'.format(i, j, i-j))
        l.append(dp[i-j] + abs(h[i] - h[i-j]))
    #print(l)
    dp[i] = min(l)
    #print(dp)
print(dp[-1])

Measured memory_bytes: 52448
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();
		boolean flag = true;
		Deque<Integer> deq = new ArrayDeque<Integer>();
		int now = n;
		A:while(now > 0){
			if(now-m>=0) {
				for (int i = m; i > 0 ; i--) {
					if(s.charAt(now-i) == '0') {
						now -= i;
						deq.addFirst(i);
						break;
					}else if(i == 1) {
						flag = false;
						break A;
					}
				}
			}else {
				deq.addFirst(now);
				break;
			}
		}
		if(flag) {
			while(!deq.isEmpty()) {
				System.out.printf("%d ", deq.pollFirst());
			}
		}else System.out.println(-1);
	}
}


Measured memory_bytes: 54960
s=int(input())
N=map(int,input().split())
guu=[]
wari=[]
for i in N:
    if i%2==0:
        guu.append(i)
        if i%3==0 or i%5==0:
            wari.append(i)
        else:
            print('DENIED')
            exit()
print('APPROVED')


Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>; 

ll N;
vl P, Q;
ll Pnum = 0, Qnum = 0;
ll Pcount = 0, Qcount = 0;

void dfs(vl &now, ll n){
    if(n == 0){
        if(now == P){
            Pnum = Pcount;
        }
        if(now == Q){
            Qnum = Qcount;
        }
        Pcount++;
        Qcount++;
        return;
    }
    FOR(i, 1, N+1){
        bool con = false;
        for(auto nowx : now){
            if(nowx == i) con = true; 
        }
        if(con) continue;
        vl next = now;
        next.push_back(i);
        dfs(next, n-1);
    }
}

int main() {
    cin >> N;
    P.resize(N);
    Q.resize(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];
    vl k;
    dfs(k, N);
    cout << abs(Pnum - Qnum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {

  int n;
  int p[20];
  int count = 0;
  int max = 0;
  
  cin >> n;
  
  for ( int i = 0; i < n; i++ ) cin >> p[i];
  
  for ( int i = 1; i < n-1; i++ ) {
    if ( p[i] < p[i-1] ) max++;
    if ( p[i] < p[i+1] ) max++;
    if ( max == 1 ) count++;
    max = 0;
  }

  cout << count << endl;

  return 0;

}


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

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()


int main() {
  string S;
  cin >> S;
  
  REP(i,SZ(S)){
    if(i==3) cout << 8;
    else cout << S.at(i);
  }
  
  cout << endl;
  
  
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  int max = 0;
  for (int i = 0; i < N; i++) {
    int price;
    cin >> price;
    ans += price;
    if (price > max) max = price;
  }
  cout << ans - max / 2 << endl;
}


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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n), dp(n);
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  
  dp[0] = 0;
  for(int i=1; i<n; i++){
    dp[i] = 1000000000;
    for(int j=max(0, i-k); j<i; j++){
      dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
    }
  }
  cout << dp[n-1] << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int a,b,c,i,n;
    int j,k,s,flag=0;
	cin>>a>>b>>c;
	j = c%b;
	k = a%b;
	s = k;
	while(1){
        if(k == j){
            cout<<"YES"<<endl;
            break;
        }
        k = k+s;
        if(k>=b){
            k = k-b;
        }
        if(k == s){
            flag++;
        }
        if(flag==2){
            cout<<"NO"<<endl;
            break;
        }
	}
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class P{
  class V{
    public long x,y,i;
    public V(long a,long b,int c){x=a;y=b;i=c;}
  }
  static void Main(){
    var n=Console.ReadLine().Split().Select(int.Parse);
    var ls=new List<V>();var lp=new List<V>();
    for(int i=0;i<n.First();i++){
      var r=Console.ReadLine().Split().Select(long.Parse);
      ls.Add(new V(r.First(),r.Last(),0));
    }
    for(int i=0;i<n.Last();i++){
      var r=Console.ReadLine().Split().Select(long.Parse);
      lp.Add(new V(r.First(),r.Last(),i+1));
    }
    foreach(V s in ls)Console.WriteLine(lp.OrderBy(x=>Math.Abs(s.x-x.x)+Math.Abs(s.y-x.y)).First().i);
  }
}

Measured memory_bytes: 11476
N,M,*P = $<.read.split.map &:to_i
A = [[]]*(N+1)
m = 1
M.times {|i|
  r,a = [],P[i+i,2]
  x,y = a.map {|i;j| (r<< i; i=j) while (j=A[i])[0]; r<< i; i}.sort
  g,h = [A[x],A[y]].map{|h| h.empty? ? a.to_h{[_1,0]} : h}.sort_by{_1.size}
  h.merge! g  if h.object_id != g.object_id
  r.each {A[_1] = y}
  A[y] = h
  m < h.size && m = h.size
}
p m

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

int main() {
    while (1){
        int m, f, r, sum;
        cin >> m >> f >>r;
        if (m == -1 && f == -1 && r == -1) break;
        
        sum = m + f;
        if (m == -1 || f == -1){
            cout << "F" << endl;
        }else if (sum >= 80){
            cout << "A" << endl;
        }else if (sum >= 65 && sum < 80){
            cout << "B" << endl;
        }else if (sum >= 50 && sum < 65){
            cout << "C" << endl;
        }else if (sum >= 30 && sum < 50){
            if (r >= 50){
                cout << "C" << endl;
            }else{
                cout << "D" << endl;
            }
        }else if(sum < 30){
            cout << "F" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long tint;
  
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend() 
#define NACHO ios::sync_with_stdio(0); cin.tie(NULL);
 
const int INF = 1111122222;
const int MOD = 1e9+7;
 
int main(){
	tint n, d, a; cin >> n >> d >> a;
	vector<pair<tint,tint>> m (n);
	forn(i, n){
		cin >> m[i].first >> m[i].second;
	}
	sort(all(m));
	vector<tint> c (n+1, 0);
	tint ret = 0;
	forn(i, n){
		int low = i, high = n+1;
		while(high-low > 1){
			int mid = low+(high-low)/2;
			if(m[mid].first <= m[i].first+2*d) low = mid;
			else high = mid;
		}
		tint upd = (m[i].second-c[i])/a+(m[i].second-c[i] >= 0 && (m[i].second-c[i]) % a != 0 ? 1 : 0);
		if(upd < 0) upd = 0;
		ret+=upd;
		c[i]+=tint(a*upd);
		c[low+1]-=tint(a*upd);
		c[i+1]+=c[i];
	}
	cout << ret << "\n";
}


Measured memory_bytes: 4992
import math


def main():
    N = int(input())
    points = []
    for i in range(N):
        x, y = [int(s) for s in input().split()]
        points.append((x, y))

    l = 0
    r = 1000
    for i in range(80):
        c1 = (l * 2 + r) / 3
        c2 = (l + r * 2) / 3
        if g(points, c1) > g(points, c2):
            l = c1
        else:
            r = c2
    print(g(points, l))


def g(points, x):
    l = 0
    r = 1000
    for i in range(80):
        c1 = (l * 2 + r) / 3
        c2 = (l + r * 2) / 3
        if f(points, x, c1) > f(points, x, c2):
            l = c1
        else:
            r = c2
    return f(points, x, l)


def f(points, x, y):
    max_distance = 0
    for i in range(len(points)):
        d = distance(x, y, float(points[i][0]), float(points[i][1]))
        if d > max_distance:
            max_distance = d

    return max_distance


def distance(x1, y1, x2, y2):
    return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 44392
let rec aux m cash drinks shops =
  if drinks >= m then cash
  else
    let a, b = List.hd shops in
    let shops = List.tl shops in
    if m - drinks >= b then aux m (cash + a * b) (drinks + b) shops
    else if m - drinks < b then aux m (cash + a * (m - drinks)) m shops
    else assert false 

let _ =
  let n, m = Scanf.scanf "%d %d\n" (fun n m -> (n, m)) in
  let pairs = ref [] in
  for i=1 to n do
    Scanf.scanf "%d %d\n" (fun a b -> pairs := (a, b)::!pairs)
  done;
  !pairs
  |> List.fast_sort (fun (a, _) (a', _) -> if a > a' then 1 else if a < a' then -1 else 0)
  |> aux m 0 0
  |> print_int


Measured memory_bytes: 15232
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class Point
{
public:
    long long y, x;
    Point(){
        y = x = 0;
    }
    Point(long long y, long long x){
        this->y = y;
        this->x = x;
    }
    long long dist(const Point& other) const{
        return abs(x - other.x) + abs(y - other.y);
    }
};

bool solve(long long k, const Point& goal, vector<Point>& ans)
{
    long long dist = goal.dist(Point());
    if(k % 2 == 0 && dist % 2 != 0)
        return false;

    static const Point diff[] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};

    for(long long step = (dist + k - 1) / k; ; ++step){
        long long rest = step * (long long)k - dist;
        if(rest % 2 != 0)
            continue;

        long long dy = 0;
        long long dx = 0;
        if(step == 3){
            dy = min(goal.x - goal.y, rest / 2);
            rest -= dy * 2;
            dy += (rest + 2) / 4;
            dx = rest / 4;
        }
        else{
            dy = rest / 2;
        }

        vector<long long> len = {0, goal.y, goal.x, 0};
        len[0] += dx;
        len[2] += dx;
        len[1] += dy;
        len[3] += dy;

        ans.resize(step);
        Point curr(0, 0);
        int j = 0;
        for(int i=0; i<step; ++i){
            long long rest = k;
            for(;;){
                long long move = min(rest, len[j]);
                curr.y += diff[j].y * move;
                curr.x += diff[j].x * move;
                rest -= move;
                len[j] -= move;
                if(rest == 0)
                    break;
                ++ j;
            }
            ans[i] = curr;
        }

        bool ok = ans[0].dist(Point()) == k;
        for(int i=0; i<step-1; ++i){
            if(ans[i].dist(ans[i+1]) != k)
                ok = false;
        }
        if(ok)
            return true;
    }
}

int main()
{
    long long k;
    Point goal;
    cin >> k >> goal.x >> goal.y;

    vector<vector<int> > mat = {{1, 0}, {0, 1}};
    if(goal.y < 0){
        goal.y *= -1;
        mat[0][0] *= -1;
    }
    if(goal.x < 0){
        goal.x *= -1;
        mat[1][1] *= -1;
    }
    if(goal.x < goal.y){
        swap(goal.y, goal.x);
        swap(mat[0][0], mat[0][1]);
        swap(mat[1][0], mat[1][1]);
    }

    vector<Point> ans;
    if(solve(k, goal, ans)){
        cout << ans.size() << endl;
        for(const auto& p : ans){
            long long y = p.y * mat[0][0] + p.x * mat[0][1];
            long long x = p.y * mat[1][0] + p.x * mat[1][1];
            cout << x << ' ' << y << endl;
        }
    }
    else{
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 5376
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;

const int MAXN = 1003;
int n;
vector<int> adjList[MAXN * MAXN];
int grid[MAXN][MAXN];
int idx[MAXN][MAXN];
int vis[MAXN * MAXN];
int res;
int ans[MAXN * MAXN];
bool f = false;

void dfs(int u) {
    vis[u] = 1;
    ans[u] = 0;
    for (int v : adjList[u]) {
        if (vis[v] == 1) {
            f = true;
            return;
        } else if (vis[v] == 0) {
            dfs(v);
            if (f)
                return;
        }
        ans[u] = max(ans[u], ans[v] + 1);
    }
    res = max(res, ans[u]);
    vis[u] = 2;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    cin >> n;
    int id = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < n - 1; ++j) {
            cin >> grid[i][j];
            int u = min(i, grid[i][j]);
            if (idx[u][i + grid[i][j] - u] == 0) idx[u][i + grid[i][j] - u] = id++;
        }
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < n - 2; ++j) {
            int u = min(i, grid[i][j]);
            int v = min(i, grid[i][j + 1]);
            adjList[idx[u][i + grid[i][j] - u]].push_back(idx[v][i + grid[i][j + 1] - v]);
        }
    }

    for (int i = 1; i < id; ++i) {
        if (vis[i] == 0)
            dfs(i);
        if (f) {
            cout << -1 << '\n';
            return 0;
        }
    }

    cout << res + 1 << '\n';

    return 0;
}

Measured memory_bytes: 55168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  string s;cin>>s;
  int i=0,ans=0;
  while(i<s.size()/2){
    if(s[i]!=s[s.size()-1-i]) ans++;
    ++i;
  }
  cout<<ans<<endl;
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    int K,  S;
    cin >> K >> S;
    int res = 0;
    for (int i = 0; i <= K; i++){
        for (int j = 0; j <= K; j++){
            int x = S - (i + j);
            if (x >= 0 && x <= K) res++;
        }
    }
    cout << res << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MX = 1'000'000 + 1;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), p(MX);
  for (int &i : a) {
    cin >> i;
    p[i]++;
  }
  int pw = 1;
  for (int i = 2; i < MX; i++) {
    int cnt = 0;
    for (int j = i; j < MX; j += i) cnt += p[j];
    if (cnt > 1) { pw = 0; break; }
  }
  if (pw) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = 0;
  for (int i = 0; i < n; i++) g = gcd(g, a[i]);
  if (g == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  return 0;
}

Measured memory_bytes: 11080
# -*- coding: utf-8 -*-

x = int(input())#所持金
a = int(input())
b = int(input())

if(x < a):
    print(x)
    exit()

x = x - a

if(x < b):
    print(x)
    exit()
while(True):
    x = x - b
    if(x < b):
        print(x)
        exit()


Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int t,n,a[4],i,j;
	for(i=0;i<4;i++){
		scanf("%d %d",&t,&n);
		if(t==1){
			a[i]=n*6000;
		}
		if(t==2){
			a[i]=n*4000;
		}
		if(t==3){
			a[i]=n*3000;
		}
		if(t==4){
			a[i]=n*2000;
		}
	}
	for(j=0;j<4;j++){
		printf("%d\n",a[j]);
	}
	return 0;
}

Measured memory_bytes: 1028
import sys
input = sys.stdin.readline
N = int(input())
XD = [tuple(map(int,input().split())) for i in range(N)]
XD.sort()
MOD = 998244353
ns = [-1] * N

for i,(x,d) in reversed(list(enumerate(XD))):
    tmp = i
    while tmp < N-1:
        nx,_ = XD[tmp+1]
        if nx < x+d:
            tmp = ns[tmp+1]
        else:
            break
    ns[i] = tmp

dp = [0] * (N+1)
dp[N] = 1
for i in range(N-1,-1,-1):
    dp[i] = (dp[i+1] + dp[ns[i]+1]) % MOD
print(dp[0])

Measured memory_bytes: 54024
#include <stdio.h>

int main(void){
  int n,i,num1,num2,num3;
  scanf("%d",&n);
  if(n==2){
    scanf("%d",&num1);
    scanf("%d",&num2);
    for(i=1;i<=num1&&i<=num2;i++){
      if(num1%i==0&&num2%i==0){
        printf("%d\n",i);
      }
    }
  }
  else if(n==3){
    scanf("%d",&num1);
    scanf("%d",&num2);
    scanf("%d",&num3);
    for(i=1;i<=num1&&i<=num2&&i<=num3;i++){
      if(num1%i==0&&num2%i==0&&num3%i==0){
        printf("%d\n",i);
      }
    }
  }

  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
using namespace std;

long long k = 0, bnr, pls, allnum;
long long memo[35][2][2] = {0}, fmemo[2][2][2] = {0},
          f[2] = {0};

long long binary();
void memoset();
long long solve();
void calcfmemo(int x, int p);

int main() {
  memoset();
  cin >> k;
  bnr = binary();
  allnum = bnr / 2;
  pls = k - allnum * ((bnr - 1) / 2);
  if((allnum + 1) / 2 >= pls) {
    f[0] = pls * 2 - 1;
    f[1] = bnr - f[0];
  }
  else {
    f[0] = 2 * (allnum + 1 - pls);
    f[1] = bnr - f[0];
  }
  cout << solve() << endl;
  return 0;
}

long long binary() {
  long long l = 2, r = 10000000000, now;
  while(r - l > 0) {
    if(r - l == 1) {
      if((l / 2) * ((l + 1) / 2) < k)
        now = r;
      else
        now = l;
      break;
    }
    now = (l + r) / 2;
    if((now / 2) * ((now + 1) / 2) < k)
      l = now;
    else
      r = now;
  }
  return now;
}

void memoset() {
  memo[0][0][0] = memo[0][0][1] = memo[0][1][0] = 1;
  for(int i = 1; i <= 32; ++i) {
    for(int j = 0; j < 2; ++j)
      for(int l = 0; l < 2; ++l)
        for(int m = 0; m < 2; ++m) {
          memo[i][j][l] +=
              (memo[i - 1][j][m] * memo[i - 1][m][l]) % N;
          memo[i][j][l] %= N;
        }
  }
}

long long solve() {
  int fnum, i;
  long long ans = 1, now;
  for(fnum = 0; fnum < 2; ++fnum) {
    fmemo[fnum][0][0] = fmemo[fnum][1][1] = 1;
    now = 30;
    while(f[fnum] > 0) {
      if(f[fnum] >= (1 << now)) {
        calcfmemo(fnum, now);
        f[fnum] -= (1 << now);
      }
      --now;
    }
  }
  for(i = 0; i < 2; ++i)
    ans *= (fmemo[i][1][0] + fmemo[i][1][1]) % N;

  return ans % N;
}
void calcfmemo(int x, int p) {
  long long dummy[2][2] = {0};
  for(int i = 0; i < 2; ++i)
    for(int j = 0; j < 2; ++j)
      for(int l = 0; l < 2; ++l) {
        dummy[i][j] += fmemo[x][i][l] * memo[p][l][j];
        dummy[i][j] %= N;
      }
  for(int i = 0; i < 2; ++i)
    for(int j = 0; j < 2; ++j) fmemo[x][i][j] = dummy[i][j];
}


Measured memory_bytes: 3108
n = int(input())
l = []

for i in range(n):
    a, b = map(int, input().split())
    l.append(a)
    l.append(b)

x = 0
z = ""

while n > x:
    y = l[x*2] - l[x*2+1]
    z = z + str(y)
    x+=1

if "000" in z:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62456
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
   
// ここから
function main(){
  var primeNumbers = calcPrimeNumbers();
  for(var i = 0, len = input.length - 1; i < len; i++){
    console.log(primeNumbers[input[i] - 0]);
  }
  
    
}
  
function calcPrimeNumbers(){
  var max = 999999;
  var primeNumbers = new Int8Array(max + 1);
  
  // 除外
  primeNumbers[0] = primeNumbers[1] = 1;
  for(var i = 2, maxI = ~~Math.sqrt(max); i <= maxI; i++){
    if(primeNumbers[i]){
      continue;
    }
      
    for(var j = (i<<1); j <= max; j+=i){
      primeNumbers[j] = 1;
    }
  }
  
  var primeNums = new Int32Array(max + 1);
   for(var i = 1; i <= max; i++){
    primeNums[i] += primeNums[i-1] + 1 - primeNumbers[i];
  }
    
  return primeNums;
}

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

typedef long long ll;

const ll INF = LLONG_MAX;
const int mxn= 1e5 + 5;
int a[mxn];
ll dp[mxn];

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
	ll n , m; 
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort (a, a + n);

	int le = 0, ri = 2e5 + 1;
	ll cnt, happiness = 0LL;
  while (le <= ri) {
    int mid = (le + ri)/2;
    cnt = 0;
    for (int i = 0; i < n; i++) {
      ll ptr = lower_bound(a, a + n, mid - a[i]) - a;
      cnt += n - ptr;
    }
    if (cnt > m) {
      le = mid + 1;
    } else {
      ri = mid - 1;
    }
  }

	le--;
	cnt = 0LL;

  // compute suffix sums
	for (int i = n - 1; i >= 0; i--) {
		dp[i] = dp[i + 1] + (ll) a[i];
	}

	for (int i = 0; i < n; i++) {
		int left = a[i];
		ll ptr = lower_bound(a, a + n, le - left) - a;
		cnt += n - ptr;
		happiness += dp[ptr] + (n - ptr) * left;
	}

	cnt = cnt - m;
	happiness -= cnt * le;
	cout << happiness << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
ll a[maxn],pre[maxn],suf[maxn],p[maxn];
int main(){
    boost;
    
    int n,k;
    cin>>n>>k;

    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)p[i]=p[i-1]+a[i];
    for(int i=1;i<=n;i++)pre[i]=pre[i-1]+max(0ll,a[i]);
    for(int i=n;i>=1;i--)suf[i]=suf[i+1]+max(0ll,a[i]);

    ll ans=0;
    for(int i=1;i<=n-k+1;i++){
        //cout<<pre[i-1]<<" "<<p[i+k-1]-p[i-1]<<" "<<suf[i+k]<<endl;
        ans=max(ans,max(0ll,p[i+k-1]-p[i-1])+pre[i-1]+suf[i+k]);
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3456
<?php
  fgets(STDIN);
  $numArray = explode(" ", trim(fgets(STDIN)));
  $count = 0;
  foreach($numArray as $num){
     while(true){
       if($num % 2 == 0){
         $num /= 2;
         $count++;
       }else{
         break;
       }
     }
  }
  echo $count;

Measured memory_bytes: 4856
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

enum P = 10L^^9+7;

void main()
{
    auto nm = readln.split.to!(long[]);
    auto N = nm[0];
    auto M = nm[1];
    auto xx = readln.split.to!(long[]);
    auto yy = readln.split.to!(long[]);
    long[] xs, ys;
    foreach (i; 1..N) xs ~= xx[i] - xx[i-1];
    foreach (i; 1..M) ys ~= yy[i] - yy[i-1];

    long e;
    foreach (i; 0..N-1) (e += xs[i] * (i+1) % P * (N-i-1) % P) %= P;
    long r;
    foreach (i; 0..M-1) (r += ys[i] * e % P * (i+1) % P * (M-i-1) % P) %= P;
    writeln(r);
}

Measured memory_bytes: 11992
/*
*	author:		richardjcy
*	created:	2020/09/26/08:26.04
*/

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

vector<vector<pair<int, ll>>> adj;
vector<int> color;
vector<bool> vis;

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

    int n;
    cin >> n;
    adj = vector<vector<pair<int, ll>>>(n, vector<pair<int, ll>>());
    color = vector<int>(n);
    vis = vector<bool>(n);
    for (int i = 0; i < n - 1; i++)
    {
        int x, y;
        ll w;
        cin >> x >> y >> w;
        --x; --y;
        adj[x].push_back({y, w});
        adj[y].push_back({x, w});
    }
    color[0] = 0;
    vis[0] = true;
    queue<int> q;
    q.push(0);
    while (!q.empty())
    {
        int u = q.front(); q.pop();
        for (auto p: adj[u])
        {
            int node = p.first;
            ll w = p.second;
            if (!vis[node])
            {
                vis[node] = true;
                if (w & 1)
                {
                    color[node] = 1 - color[u];
                    q.push(node);
                }
                else
                {
                    color[node] = color[u];
                    q.push(node);
                }
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << color[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 11092
[x,n] = list(map(int, input().split()))
pList = list(map(int, input().split()))
pSet = set(pList)
step = 0
small = False
big = False
while True:
    if x - step not in pSet:
        small = True
        break
    if x + step not in pSet:
        big = True
        break
    step += 1
if small:
    print(x-step)
else:
    print(x+step)

Measured memory_bytes: 9184
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double EPS = 1e-7;
const double INF = 1e12;
struct Vec {
    double x,y;
    Vec(){}
    Vec(double x,double y){ this->x=x,this->y=y; }
    void read(){ scanf("%lf%lf",&x,&y); }
    void prt() {printf("%.9f %.9f\n",x,y); }
    double len(){ return sqrt(x*x+y*y); }
    double len2(){ return x*x+y*y; }
    
    Vec operator+(const Vec&o)const{ return Vec(x+o.x,y+o.y); }
    Vec operator-(const Vec&o)const{ return Vec(x-o.x,y-o.y); }
    Vec operator*(const double&k)const{ return Vec(k*x,k*y); }
    double operator*(const Vec&o)const {return x*o.x+y*o.y; }
    double operator^(const Vec&o)const {return x*o.y-y*o.x; }
    Vec rotate(double ang){ return Vec(x*cos(ang)-y*sin(ang), x*sin(ang)+y*cos(ang)); }
    Vec change(double l){ if(len()<EPS) return *this; return (*this)*(l/len()); }
    double disToLine(Vec A, Vec B) {
        return abs((A-*this)^(B-*this))/(B-A).len();
    }
};

Vec Lineintersect(Vec A1,Vec A2,Vec B1,Vec B2) {
    if (abs((A2-A1)^(B2-B1)) < EPS) return Vec(INF,INF);
    return A1 + (A2 - A1) * (( ((A2-A1)^(B2-B1)) - ((A2-B1)^(B2-B1)) ) / ((A2-A1)^(B2-B1)) );
}

Vec Segintersect(Vec A1,Vec A2,Vec B1,Vec B2) {
    Vec P = Lineintersect(A1,A2,B1,B2);
    //P.prt();
    if ((P-A1)*(P-A2)<=0 && (P-B1)*(P-B2)<=0) return P; 
    return Vec(INF,INF);
}

bool onseg(Vec P,Vec A,Vec B){
    if(P.disToLine(A,B) > EPS) return 0;
    return (P-A)*(P-B) <= 0;
}

Vec A,B,C,D; int q;
int main(){
    scanf("%d",&q);
    while(q--){
        A.read(); B.read(); C.read(); D.read();
        if(onseg(A,C,D) || onseg(B,C,D) || onseg(C,A,B) || onseg(D,A,B)) {
            printf("1\n"); continue;
        }

        if (Segintersect(A,B,C,D).x == INF)
            printf("0\n");
        else 
            printf("1\n");
    }
}


Measured memory_bytes: 3224
N, K = list(map(int, input().split()))
P = list(map(float, input().split()))

p = [0]
for i in range(N):
    p.append(p[-1] + (P[i] + 1) / 2)

print(max(p[i+K] - p[i] for i in range(N-K+1)))


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

using namespace std;


int main() {
      
   long int n;
   scanf("%ld",&n);
   long int i;
   long int ans=0;;
   for(i=n;;--i)
      {
          ans=sqrt(i);
          if((ans*ans)==i)
              break;
      }
      
      printf("%ld",i);
     
	return 0;
}

Measured memory_bytes: 256