akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long m = sc.nextLong();
        int v = sc.nextInt();
        int p = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int l = -1;
        int r = n-1;
        int tgt = a[n-p];
        long maxNoVote = (n-v)*1L*m;
        while(l+1 < r){
            int mid = (r+l)/2;
            if(n-p <= mid) r = mid;
            else{
                if(a[mid]+m < tgt) l = mid;
                else{
                    long max = a[mid]+m;
                    long noVote = 0L;
                    boolean able = true;
                    for (int i = mid+1; i <= n-p; i++) {
                        long nv = m - (max - a[i]);
                        if(m < nv){
                            able = false;
                            break;
                        }
                        noVote += nv;
                    }
                    if(!able || maxNoVote < noVote){
                        l = mid;
                    }else{
                        r = mid;
                    }
                }
            }
        }
        System.out.println(n - r);
        sc.close();

    }

}


Measured memory_bytes: 52352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		
		int [] A = new int [M];
		for (int i=0; i<M; i++)
			A[i]=sc.nextInt();
		
		int cur=0;
		while (cur<M && A[cur]<X)
			cur++;
		
		//System.out.println(cur);
		System.out.println(Math.min(cur, M-cur));
		
		
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define     fast                    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define     ll                      long long
#define     pb                      push_back
#define     M                       1000000007
using namespace std;
int main()
{
    ll n;
    cin>>n;
    if(n%2==0) n = n;
    else n = n*2;
    cout<<n<<endl;

}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int func(int n){
    int cnt = 0;
    while(n){
        if(n%2 == 0){
            cnt++;
            n /= 2;
        }
        else{
            break;
        }
    }
    return cnt;
}
int main(){

    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i = 0; i < n-1; i++){
        ans += v[i+1] - v[i];
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	vint N(4);
	for (int i = 0; i < 4; i++) {
		cin >> N[i];
	}

	vbool check(10);
	for (int i = 0; i < 10; i++) {
		check[i] = false;
	}


	for (int i = 0; i < 4; i++) {
		check[N[i]] = true;
	}

	if (check[1] && check[4] && check[9] && check[7]) {
		cout << "YES";
		return 0;
	}
	
	cout << "NO";

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < n; ++i)
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n+2);
    for (int i=1;i<n+1;i++){
        cin >> a.at(i);
    }
    int sum = 0;
    for (int i=1;i<n+2;i++){
        sum+= abs(a.at(i)-a.at(i-1));
    }
    vector<int> ans(n);
    for (int i=0;i<n;i++){
        ans.at(i) = sum;
        if((a.at(i+2)-a.at(i+1))*(a.at(i+1)-a.at(i))>=0)
            continue;
        ans.at(i) -= abs(a.at(i+1)-a.at(i))+abs(a.at(i+2)-a.at(i+1))
            -abs(a.at(i+2)-a.at(i));
    }
    for (int i=0;i<n;i++){
        cout << ans.at(i) << endl;
    }
    return 0;
}



Measured memory_bytes: 2048
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n,scan,i;
	scan = scanf("%d",&n);
	int a[n];
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	int min = *min_element(a, a + n);
	int Max = *max_element(a, a + n);
	printf("%d",Max - min);
}

Measured memory_bytes: 128
long long n,i,j,c,ans=0;main(){
scanf("%lld",&n);
for(i=2;i*i<n;i++){for(c=0;n%i==0;c++)n/=i;
 for(j=0;j*(j+1)/2<=c;j++);
 ans+=j-1;}
if(n-1)ans++;
printf("%lld\n",ans);}

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

const int mod = 10000;
int dp[101][3][3], n, k, a, b;
int s[101];

int main() {
  cin>>n>>k;
  for (int i=0; i<k; ++i) {
    cin>>a>>b; a--;
    s[a] = b;
  }

  for (int i=0; i<3; ++i) {
    if (s[0] != 0 && s[0]-1 != i) continue;
    dp[0][i][0] = 1;
  }
  for (int i=0; i<n-1; ++i) {
    for (int j=0; j<3; ++j) {
      if (s[i+1] != 0 && s[i+1]-1 != j) continue;
      for (int p=0; p<3; ++p) {
        for (int q=0; q<3; ++q) {
          if (j == p && q == 1) continue;
          int next = ((j!=p)?0:(q+1));
          dp[i+1][j][next] += dp[i][p][q];
          dp[i+1][j][next] %= mod;
        }
      }
    }
  }

  int ans = 0;
  for (int i=0; i<3; ++i) {
    for (int j=0; j<3; ++j) {
      ans += dp[n-1][i][j];
      ans %= mod;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1164
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

struct P{ P(int x, int y) : x(x), y(y) {} int x, y;	};

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<vint> field(n, vint(n, -1));

		P p = P(n/2, n/2+1);
		rep(i, n*n)
		{
			if(field[p.y][p.x] == -1)
			{
				field[p.y][p.x] = i + 1;
			}
			else
			{
				while(field[p.y][p.x] != -1)
				{
					if(field[(p.y + 1) % n][(p.x + 1) % n] == -1)
					{
						p = P((p.x + 1) % n, (p.y + 1) % n);
						break;
					}
				
					p = P(p.x, (p.y + 2) % n);
				}
				i--;
			}
		}

		rep(i, n)
		{
			rep(j, n)
				printf("%4d", field[i][j]);
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
  int a, b, c;
  cin >> a >> b >> c;
  int e=a+b; int f=a-b; int g=a*b;
  int j=max(e,f);
  cout<<max(j,g)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 89;
	while (kkt) {
		ll n, m; scanf("%lld %lld", &n, &m);
		if (n == 0 && m == 0) break;
		vector<pair<ll, ll>> vp(n);
		for (int i = 0; i < n; i++) scanf("%lld %lld", &vp[i].second, &vp[i].first);
		sort(vp.rbegin(), vp.rend());
		ll res = 0;
		for (int i = 0; i < n; i++) {
			if (vp[i].second <= m) {
				m -= vp[i].second;
			}
			else if(m > 0){
				vp[i].second -= m;
				m = 0;
				res += vp[i].first * vp[i].second;
			}
			else {
				res += vp[i].first * vp[i].second;
			}
		}
		cout << res << "\n";
	}
	return 0;

}


Measured memory_bytes: 3312
import sys
from collections import defaultdict


def dfs(root, links):
    status = {}
    topological = []
    q = [(r, 0, 1) for r in root]
    while q:
        node = q.pop()
        if node[1] == 0:
            v, _, d = node
            q.append((v, 1))
            status[v] = 1
            d += 1
            for u in links[v]:
                if u in status:
                    if status[u] == 1:
                        return False
                else:
                    q.append((u, 0, d))
        else:
            v = node[0]
            status[v] = 2
            topological.append(v)
    topological.reverse()
    return topological


n = int(input())
links = defaultdict(set)
may_root = set()
lines = sys.stdin.readlines()
matches = []
for i in range(n):
    line = lines[i]
    aaa = list(map(int, line.split()))
    match_order = []
    for j in aaa:
        j -= 1
        a, b = (i, j) if i < j else (j, i)
        key = a * n + b
        match_order.append(key)
    matches.append(match_order)
    may_root.add(match_order[0])

for i in range(n):
    kkk = matches[i]
    prev = kkk[0]

    for key in kkk[1:]:
        links[prev].add(key)
        may_root.discard(key)
        prev = key

if not may_root:
    print(-1)
    exit()

topological = dfs(may_root, links)
if topological == False:
    print(-1)
    exit()

ans = 0
depth = defaultdict(lambda: 1)
for v in topological:
    d = depth[v] + 1
    for u in links[v]:
        depth[u] = max(depth[u], d)

print(max(depth.values()))


Measured memory_bytes: 289020
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9+7;
const ll inf = (LLONG_MAX>>1);
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  for(char c : s){
    if(c == '?') cout << 'D';
    else cout << c;
  }
  return 0;
}

Measured memory_bytes: 3748
import sys
import math
input = sys.stdin.readline

MOD = 10 ** 9 + 7


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


def main():
    N, K = map(int, input().split())
    red = N - K
    blue = K

    # print(blue, red)

    if red == 0:
        for i in range(N):
            if i == 0:
                print(1)
            else:
                print(0)
        return

    for i in range(1, K+1):
        if i > red + 1:
            print(0)
        else:
            ans = cmb(red + 1, i)
            # print('blue', blue)
            # print(blue - 1, i - 1, cmb(blue + 1, i - 1))
            ans *= cmb(blue - 1, i - 1)
            print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 49500
#include <iostream>
#include <cstdio>

using namespace std;

char str_ans[200000];

int main(){
	
	int N;
	
	cin >> N;
	
	string str;
	
	cin >> str;
	
	string ans_list[4] = {"SS", "SW", "WS", "WW"};
	
	for(int loop = 0; loop < 4; loop++){
		
		str_ans[0] = ans_list[loop][0];
		str_ans[1] = ans_list[loop][1];
		
		for(int i = 1; i <= N; i++){
			char add_str;
			if((str[i % N] == 'o' && str_ans[i] == 'S') || (str[i % N] == 'x' && str_ans[i] == 'W')){
				add_str = str_ans[i - 1];
			}else{
				if(str_ans[i - 1] == 'S'){
					add_str = 'W';
				}else{
					add_str = 'S';
				}
			}
			str_ans[i + 1] = add_str;
		}
		
		//cout << str_ans << endl;
		
		if(str_ans[0] == str_ans[N] && str_ans[1] == str_ans[N + 1]){
			for(int i = 0; i < N; i++){
				printf("%c", str_ans[i]);
			}
			printf("\n");
			return 0;
		}
	}
	
	cout << "-1" << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <stack>
#include <sstream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define ff		first
#define sd      second
#define mod 	1000000007
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define inf 	1e18
#define vi          vector<int>
#define pb  	push_back
#define full(x) x.begin(), x.end()
#define int 	long long
#define pq 	priority_queue<int,int>
#define ford(i, a, b) for (int i=a; i<(b); i++)
#define foro(i, a) for (int i=0; i<(a); i++)
#define w(t)	int t; cin>>t; while(t--)

const int N = 1e5 + 5;



using namespace std;

#define IOS ios:: sync_with_stdio(0);cin.tie(0); cout.tie(0);


void abc()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int pow1(int n, int p, int md)
{
	int ans  = 1;

	while (p > 0)
	{
		int last = (p & 1);
		if (last == 1)
		{
			ans = (ans * n) % md ;
		}
		n = (n * n) % md;
		p = p >> 1;
	}

	return ans;
}
int x, y, GCD;
void ExtendedEuclid(int a, int b)
{
	if (b == 0)
	{
		y = 0;
		x = 1;
		GCD = a;
		return;
	}

	ExtendedEuclid(b, a % b);
	int cx = y;
	int cy = x - (a / b) * y;

	x = cx;
	y = cy;
}

int inv(int n, int md)
{
	ExtendedEuclid(n, md);
	return (x + md) % md;
}
int fact[2000005];
void facto()
{
	fact[0] = 1;
	fact[1] = 1;
	for (int i = 2; i <= 2000005; i++)
	{
		fact[i] = (i * fact[i - 1]) % mod ;
	}
}
int lucas(int a, int md)
{
	return pow1(a, md - 2, md);
}

void solve()
{
	//Code here;
	int x, y;
	cin >> x >> y;
	int count = 0;
	for (int i = 0; i < x; i++)
	{
		int a, b;
		cin >> a >> b;

		int l = pow(a, 2);
		int m = pow(b, 2);

		int jog = l + m;

		if (sqrt(jog) <= y)
		{
			count++;
		}
	}

	cout << count << endl;


}
int32_t main()
{
	IOS;
	


	solve();


	return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include <vector>
#include <array>
using namespace std;
using ll = long long;

template <class T>
struct fenwick_tree {
  vector<T> x;
  fenwick_tree(int n) : x(n, 0) { }
  T sum(int i, int j) {
    if (i == 0) {
      T S = 0;
      for (j; j >= 0; j = (j & (j + 1)) - 1) S += x[j];
      return S;
    } else return sum(0, j) - sum(0, i-1);
  }
  void add(int k, T a) {
    for (; k < x.size(); k |= k+1) x[k] += a;
  }
};

ll go(const string& s, const string& t) {
  vector<vector<int>> pos(26);
  vector<int> ind(26, 0);

  for (int i = 0; i < t.size(); i++) {
    pos[t[i] - 'a'].push_back(i);
  }

  vector<int> perm;
  for (char c : s) {
    int k = c - 'a';
    int p = pos[k][ind[k]++];
    perm.push_back(p);
  }

  fenwick_tree<ll> ft(s.size()); 
  ll res = 0;
  for (int i = 0; i < perm.size(); i++) {
    res += i - ft.sum(0, perm[i]);
    ft.add(perm[i], 1);
  }

  return res; 
}

ll solve(const string& s) {
  vector<int> freq(26, 0);
  for (char c : s) {
    ++freq[c - 'a'];
  }

  int odd = 0;
  for (int c : freq) {
    if (c % 2 == 1) {
      ++odd;
    }
  }
  if (odd > 1) {
    return -1;
  }

  vector<int> used(26, 0);
  string f = "";
  for (char c : s) {
    int k = c - 'a';
    if (used[k] >= freq[k] / 2) {
      continue;
    }
    f += c;
    ++used[k];
  }

  string t = f;
  if (s.size() % 2 == 1) {
    for (int i = 0; i < 26; i++) {
      if (freq[i] % 2 == 1) {
        t += 'a' + i;
        break;
      }
    }
  }
  t += string(f.rbegin(), f.rend());

  return go(s, t);
}

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

  cout << solve(s) << endl;

  return 0;
}


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)//  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 3e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;

vector<ll> A;
ll dp[MAXN], sm[MAXN];

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, m;
	cin >> n >> m;
	str s;
	cin >> s;
	
	ll cnt = 1;
	for(int i = 1; i < m; i++){
		if(s[i] == s[i - 1]) cnt ++;
		else {
			A.pb(cnt);
			cnt = 1;
		}
	}
	A.pb(cnt);
	if(A.size() == 1){
		//debug("S");
		dp[1] = 1;
		dp[2] = 0;
		sm[1] = 1;
		sm[2] = 1;
		for(int i = 3; i <= n; i++){
			dp[i] = sm[i - 2];
			sm[i] = (dp[i] + sm[i - 1]) % MOD;
		}
		ll ans = 1;
		for(int len = 1; len <= n - 1; len ++){
			ans += (len + 1ll) * dp[n - len];
			ans %= MOD;
		}
		cout << ans;
		return 0;
		/////
	}
	
	ll mx;
	
	if(A[0] % 2 == 0) mx = A[0] + 1;
	else mx = A[0];
	for(int i = 2; i + 1 < A.size(); i += 2){
		if(A[i] % 2 == 1) mx = min(mx, A[i]);
	}
	debug(mx);
	dp[0] = 0;
	dp[1] = 1;
	dp[3] = 1;
	for(int i = 5; i <= n; i++){
		dp[i] = dp[i - 2] + dp[i - 2];
		if(i >= mx + 3) dp[i] -= dp[i - mx - 3];
		dp[i] %= MOD;
	}
	//debug(dp[1]);
	//debug(dp[3]);
	ll ans = 0;
	for(ll len = 1; len <= min(n-1ll, mx); len += 2){
		ans += ((len + 1ll) * dp[n - len]);
		ans %= MOD;
	}
	cout << ((ans % MOD) + MOD)%MOD;
	
	return 0;
}


/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/



Measured memory_bytes: 4244
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int a,b,c;
	cin >> a >> b >> c;
	if((a * 100 + b * 10 + c) % 4 == 0) YES();
	else NO();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
 int n;
 cin >> n;
 int *a = new int[n];
 for(int i = n-1; i>=0; --i) cin >> a[i];
 for (int i=0; i<n; ++i)
 {
  cout << a[i];
  if(i != n-1) cout << " ";
 }
 cout << endl;
 return 0;
}

Measured memory_bytes: 3100
// 1_7_D
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int n, m, l, i, j, k;
  cin >> n >> m >> l;
  vector< vector<int> > A(n, vector<int>(m, 0));
  vector< vector<int> > B(m, vector<int>(l, 0));
  vector< vector<long> > C(n, vector<long>(l, 0));

  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      cin >> A[i][j];
    }
  }
  for(j = 0; j < m; j++){
    for(k = 0; k < l; k++){
      cin >> B[j][k];
    }
  }

  for(i = 0; i < n; i++){
    for(k = 0; k < l; k++){
      for(j = 0; j < m; j++){
        C[i][k] += A[i][j] * B[j][k];
      }
    }
  }

  for(i = 0; i < n; i++){
    for(k = 0; k < l; k++){
      if(k != 0) cout << " ";
      cout << C[i][k];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3200
import sys
X=int(input())
for i in range(500):
  for j in range(500):
    if (i-100)**5-(j-100)**5==X:
      A=[]
      A.append(i-100)
      A.append(j-100)
      A=[str(n) for n in A]
      print(' '.join(A))
      sys.exit()

Measured memory_bytes: 9184
#include <bits/stdc++.h>
//#include "graph.cpp"
#define loop(i,n) for(int i=0 ; i<n ; ++i)
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)
using namespace std;
int n;
int arr[205];
int main(){
    cin>>n;
    loop(i,2*n){
        cin>>arr[i];
    }
    sort(arr,arr+2*n);
    int res=0;
    loop(i,2*n){
        if(i%2 == 0){
            res+=arr[i];
        }
    }
    cout<<res<<endl;
}
/* */


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 7;
int n;
int a[maxx];
map <int, int> mp;
bool flg;
bool vis[maxx];
int cnt;

int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) a[i] = i;
	for(int i = 1; i <= n; i++) cin >> mp[a[i]];
	int p = 1;
	while(p != 2) {
		if(vis[p]) flg = 1;
		if(flg) break;
		vis[p] = 1;
		p = mp[a[p]];
		cnt++;
	}
	if(flg) puts("-1");
	else cout << cnt << endl;
}

Measured memory_bytes: 5376
def resolve():
    from itertools import combinations
    n = int(input())
    l = list(map(int, input().split()))
    ans = 0
    if n < 3:
        print(0)
        return

    for i in range(n):
        for j in range(n):
            for k in range(n):
                if i >= j or j >= k or i >= k:
                    continue
                if l[i] == l[j] or l[j] == l[k] or l[k] == l[i]:
                    continue
                if l[i] >= l[j] + l[k] or l[j] >= l[i] + l[k] or l[k] >= l[i] + l[j]:
                    continue
                ans += 1

    print(ans)

resolve()

Measured memory_bytes: 9200
c[2];i;m;main(j,s)char*s;{gets(s);for(gets(s);s[++i];m=fmax(__builtin_popcount(*c&c[1]),m))for(*c=c[1]=j=0;s[j];)c[j<i]|=1<<s[j++]-97;printf("%d",m);}

Measured memory_bytes: 128
def d_equeue(N, K, V):
    ans = 0
    for l in range(K + 1):
        for r in range(K - l + 1):  # 左右から宝石を何個取り出すか
            if l + r > N:
                continue

            # 決めた「取り出す個数」に従い宝石を取り出す
            get_jewelry = V[:l] + V[N - r:]
            now_value = sum(get_jewelry)

            # 価値が負の宝石を、価値が小さなものから戻す
            d = K - l - r  # 戻す操作にかける回数
            get_jewelry.sort()
            for i in range(d):
                if i >= len(get_jewelry) or get_jewelry[i] > 0:
                    break  # 戻せないか、戻す必要がない
                now_value -= get_jewelry[i]
            ans = max(ans, now_value)
    return ans

N, K = [int(i) for i in input().split()]
V = [int(i) for i in input().split()]
print(d_equeue(N, K, V))

Measured memory_bytes: 3064
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

fn main() {
    input!{
        N: isize,
        L: isize,
    }
    let L = (1..N+1).map(|i| {
        L + i - 1
    }).collect::<Vec<isize>>();
    let mut sum = 0;
    let mut min: isize = 100;
    for i in 0..N {
        let li = L[i as usize];
        sum += li;
        if li.abs() < min.abs() {
            min = li;
        }
    }
    println!("{}", sum-min);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
signed main(){
	int n,k,s;
	cin>>n>>k>>s;
	int ma=1000'000'000;
	if(s<ma){
		loop(k){
			cout<<s<<endl;
		}
		loop(n-k) cout<<ma<<endl;
	}else{
		loop(k) cout<<s<<endl;
		loop(n-k) cout<<1<<endl;
	}


	return 0;
}



Measured memory_bytes: 3608
import java.util.Scanner;
class Main{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int low = scan.nextInt();
        int high = scan.nextInt();
        int i;
        int a = 0;
        for( i = 1;i < 1000; i ++){
            a = num * i;
            if(low <= a && a <= high ){
                //System.out.println("OK");
                //System.out.println(i);
                break;
            }
        }
        if(low <= a && a <= high){
            System.out.println("OK");
        }else{
            System.out.println("NG");
        }
    }

}

Measured memory_bytes: 35748
from collections import defaultdict, deque

N, M = map(int, input().split())

AB = [list(map(int, input().split())) for _ in range(M)]

graph = defaultdict(set)

check = set([i + 1 for i in range(N)])

for a, b in AB:
    graph[a].add(b)
    graph[b].add(a)

    if a in check:
        check.remove(a)
    if b in check:
        check.remove(b)

if len(check) != 0:
    print('No')
    exit()

dq = deque([])
dq.append(1)

# noの扱う
ans = [-1] * (N + 1)

visited = set()
visited.add(1)
while dq:
    node = dq.popleft()

    for c in graph[node]:
        if c in visited:
            continue

        ans[c] = node
        visited.add(c)
        dq.append(c)


print('Yes')
for a in ans[2:]:
    print(a)


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

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  ll money = 1000;
  ll kabu=0;
  rep(i,n-1){
    if(a[i] < a[i+1]){
      kabu = money/a[i];
      money -= kabu*a[i];
      money += kabu*a[i+1];
      kabu = 0;
    }
  }
  cout << money << endl;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#define buf_size 20

typedef struct node{
  struct node *next;
  struct node *prev;
  int key;
}Node;

Node *head, *tail;

void init(){
  Node *node = ( Node * )malloc( sizeof( Node ) );
  head = node;
  tail = node;
  node -> next = tail;
  node -> prev = head;
}

void kill(){
  Node *node = head -> next;
  while( node != tail ){
    Node *next = node -> next;
    free( node );
    node = next;
  }
  free( tail );
}

void insert( int key ){
  Node *node = ( Node * )malloc( sizeof( Node ) );
  node -> key = key;
  node -> prev = head;
  node -> next = head -> next;
  head -> next -> prev = node;
  head -> next = node;
}

void delete( int key ){
  Node *node = head -> next;
  while( node != tail ){
    if( node -> key == key ){
      node -> next -> prev = node -> prev;
      node -> prev -> next = node -> next;
      free( node );
      break;
    }
    node = node -> next;
  }
}

void deleteFirst(){
  if( head -> next == tail ) return;
  Node *node = head -> next;
  node -> next -> prev = head;
  head -> next = node -> next;
  free( node );
}

void deleteLast(){
  if( head -> next == tail ) return;
  Node *node = tail -> prev;
  node -> prev -> next = tail;
  tail -> prev = node -> prev;
  free( node );
}

void print(){
  if( head -> next == tail ) return;
  Node *node = head -> next;
  while( node -> next != tail ){
    printf("%d ", node -> key );
    node = node -> next;
  }
  printf("%d\n", node -> key );
}

int main( void ){
  int n, key;
  scanf("%d\n", &n );
  init();
  while( n-- > 0 ){
    char buf[ buf_size ];
    scanf("%s", buf );
    if( buf[0] == 'i' ){
      scanf("%d\n", &key );
      //printf("Insert [%d]\n", key );                                                                                        
      insert( key );
      //print();                                                                                                              
    }
    else if( buf[6] == '\0' ){
      scanf("%d\n", &key );
      //printf("Delete [%d]\n", key );                                                                                        
      delete( key );
      //print();                                                                                                              
    }
    else if( buf[6] == 'F' ){
      scanf("\n");
      //printf("DeleteFirst\n");                                                                                              
      deleteFirst();
      //print();                                                                                                              
    }
    else if( buf[6] == 'L' ){
      scanf("\n");
      //printf("DeleteLast\n");                                                                                               
      deleteLast();
      //print();                                                                                                              
    }
  }
  print();
  return 0;
}
    
    
    
    


Measured memory_bytes: 32992
#include <bits/stdc++.h>
using namespace std;
long N;
long Q;
vector<char > t_ls;
vector<char > d_ls;
string s;

bool check_left(long ind){
    for(int i=0; i< ::Q; i++){
        if(::t_ls[i] == ::s[ind]){
            if(::d_ls[i] == (char)'L'){
                ind -= 1;
            }
            else{
                ind += 1;
            }
        }
        if (ind >= N){
            return false;
        };
        if (ind <= -1){
            return true;
        }
    }
    return false;
}
bool check_right(long ind){
    for(int i=0; i< ::Q; i++){
        if(::t_ls[i] == ::s[ind]){
            if(::d_ls[i] == (char)'L'){
                ind -= 1;
            }
            else{
                ind += 1;
            }
        }
        if (ind >= N){
            return true;
        };
        if (ind <= -1){
            return false;
        }
    }
    return false;
}

int main(){
    long last;
    long ind;
    long dif;
    long tmp;
    long _sum;
    int flg;
    cin >> ::N >> ::Q;
    cin >> ::s;
    ::t_ls.resize(Q);
    ::d_ls.resize(Q);
    for(int i=0; i<Q; i++){
        cin >> ::t_ls[i] >> ::d_ls[i];
    }
    last = ::N-1;
    ind = ::N / 2;
    flg = 0;
    while(true){
        dif = abs((int)(last - ind));
        if(check_left(ind)){
            if(dif <= 1 && flg == 0){
                break;
            } else if(dif < 1){
                break;
            }
            flg = 1;
            tmp = ind;
            ind += 1 < dif / 2 ? dif / 2 : 1;
            last = tmp;
        }
        else{
            if(dif <= 1 && flg == 1){
                ind -= 1;
                break;
            } else if(dif < 1){
                ind = -1;
                break;
            }
            flg = 0;
            tmp = ind;
            ind -= 1 < dif / 2 ? dif / 2 : 1;
            last = tmp;
        }
        ind = ind > ::N-1 ? ::N-1 : ind;
        ind = ind < 0 ? 0 : ind;
    }
    _sum = ind + 1;
    last = ::N-1;
    ind = ::N / 2;
    flg = 0;
    while(true){
        dif = abs((int)(last - ind));
        if(check_right(ind)){
            if(dif <= 1 && flg == 0){
                break;
            } else if(dif < 1){
                break;
            }
            flg = 1;
            tmp = ind;
            ind -= 1 < dif / 2 ? dif / 2 : 1;
            last = tmp;
        }
        else{
            if(dif <= 1 && flg == 1){
                ind += 1;
                break;
            } else if(dif < 1){
                ind = N;
                break;
            }
            flg = 0;
            tmp = ind;
            ind += 1 < dif / 2 ? dif / 2 : 1;
            last = tmp;
        }
        ind = ind > ::N-1 ? ::N-1 : ind;
        ind = ind < 0 ? 0 : ind;
    }
    _sum += ::N - ind;
    cout << ::N - _sum << endl;
}


Measured memory_bytes: 900
from heapq import heappush,heappop
from collections import deque
N,M,s,t=map(int,input().split())
table=[[] for i in range(N)]
rtable=[[] for i in range(N)]
for i in range(M):
    u,v,a,b=map(int,input().split())
    table[u-1].append([a,v-1])
    table[v-1].append([a,u-1])
    rtable[u-1].append([b,v-1])
    rtable[v-1].append([b,u-1])
dij=[]
heappush(dij,[0,s-1])
val=[10**16]*N
val[s-1]=0
while dij:
    q,x=heappop(dij)
    if val[x]<q:
        continue
    for d,y in table[x]:
        if val[y]>val[x]+d:
            val[y]=val[x]+d
            heappush(dij,[val[y],y])
rdij=[]
heappush(rdij,[0,t-1])
rval=[10**16]*N
rval[t-1]=0
while rdij:
    q,x=heappop(rdij)
    if rval[x]<q:
        continue
    for d,y in rtable[x]:
        if rval[y]>rval[x]+d:
            rval[y]=rval[x]+d
            heappush(rdij,[rval[y],y])
ans=deque()
t=val[N-1]+rval[N-1]
mod=pow(10,15)
ans.append(mod-t)
for i in range(N-2,-1,-1):
    t=min(t,val[i]+rval[i])
    ans.appendleft(mod-t)
print('\n'.join(map(str,ans)))

Measured memory_bytes: 106352
#include <bits/stdc++.h>
using namespace std;
int N;
long long A[200010], dp[200010];
int main () {
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> A[i];
    dp[0] = dp[1] = 0;
    long long x = A[1];
    for (int i = 2; i <= N; i++) {
        if (i % 2 == 0) {
            dp[i] = max(dp[i-2]+A[i], x);
        }
        else {
            dp[i] = max(dp[i-2]+A[i], dp[i-1]);
            x += A[i];
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 6792
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
typedef pair<int, int> pii;

ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}
ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}
ll gcd(ll a, ll b){
    if(!a) return b;
    return gcd(b%a, a);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n, k; cin>>n>>k;
	n %= k;
	n = min(n, k-n);
	cout<<n<<endl;
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val (H, W, N) = listOfInt()
    val M = mutableMapOf<Pair<Int, Int>, Int>()
    repeat(N) {
        val (a, b) = listOfInt(-1)
        for (h in -1 .. 1) for (w in -1 .. 1) {
            val key = a + h to b + w
            if ((key.first in 1 until H - 1) && (key.second in 1 until W - 1))
                M.set(a + h to b + w, M.getOrElse(a + h to b + w, { 0 }) + 1)
        }
    }
    val ans = LongArray(10)
    M.values.forEach { n -> ans[n] = ans[n] + 1 }
    ans[0] = (1L * (H - 2) * (W - 2)) - ans.sum()
    ans.forEach { println(it) }
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }



Measured memory_bytes: 202784
let for_range s e step f =
  let rec loop i =
    if i <= e then begin f i;loop (i + step) end
  in loop s;;
 
let sieve num =
  let p = Array.init num (fun x -> x mod 2) in
  let rec loop i =
    if i*i < num then
      begin
        if p.(i) = 1 then for_range (i*i) num (i*2) (fun x -> p.(x) <- 0);
        loop (i+2)
      end
  in
  p.(0) <- 0; p.(1)<-(0);p.(2)<-1;loop 3;p
;;
 
let () =
  let p = sieve 50000 in
  let rec read () =
    let n = read_int () in
    if n = 0 then ()
    else
      begin
        let count = ref 0 in
        if n = 4 then count := 1
        else
          if n mod 2 = 1 then
            if p.(n-2) = 1 then incr count else ()
          else
            begin
              let m = n/2 in
              for_range 3 m 2 (fun i -> if p.(i)=1 && p.(n-i)=1 then incr count)
            end
        ;print_int !count;print_newline ();read ()
      end
  in read ()
;;

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n, m;
    cin >> n >> m;
    vector<vector<int>> c(n, vector<int>(n, 0));

    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        c[a][b]++;
        c[b][a]++;
    }

    for (const auto &row : c)
    {
        int count = 0;
        for (const auto &e : row)
        {
            count += e;
        }
        cout << count << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int mod){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%mod;Rac[n-1]=modInv(Fac[n-1],mod);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 2e5;
ll n, k;
double d[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  FOR(i, 0, n){
    cin >> d[i];
    d[i]++;
  }
  int s=0, ans=0;
  FOR(i, 0, n){
    s += d[i];
    if(i>=k) s -= d[i-k];
    maxs(ans, s);
  }
  printf("%.12f\n", double(ans)/2);
}

Measured memory_bytes: 1792
n, m = map(int, input().split())
h = tuple(map(int, input().split()))
i = 0
c = [1]*n
while i<m:
    a, b=map(int, input().split())
    if h[a-1] > h[b-1]:
        c[b-1] = 0
    elif h[a-1] == h[b-1]:
        c[a-1] = c[b-1] = 0
    else:
        c[a-1] = 0
    i += 1

ans = 0
i = 0
while i<n:
    if c[i] == 1:
        ans+=1
    i+=1

print(ans)


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

using ll = long long;
using pii = pair<int, int>; using pll = pair<ll, ll>;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ s >> p.first >> p.second; return s;}

int main()
{
    int X, Y; cin >> X >> Y;


    for (int t = 0; t <= X; t++) {
        int ashi = t * 2 + (X-t) * 4;
        if (ashi == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    } 
    cout << "No" << endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int x[1005][1005], H, W;
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
int dp[1005][1005];
pair<int, int>c[1000000];
int main() {
	cin >> H >> W;
	for (int i = 0; i < 1005 * 1005; i++)x[i / 1005][i % 1005] = 999999999;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> x[i][j];
			c[x[i][j]] = make_pair(i, j);
		}
	}
	for (int i = 1; i <= H*W; i++) {
		int ax = c[i].first, ay = c[i].second;
		vector<int>vec; bool flag = false;
		for (int j = 0; j < 4; j++) {
			int tox = ax + dx[j], toy = ay + dy[j];
			if (dp[tox][toy] == 0)continue;
			if (dp[tox][toy] == -1)flag = true;
			vec.push_back(dp[tox][toy]);
		}

		if (flag == true)dp[ax][ay] = -1;
		else if (vec.size() == 0)dp[ax][ay] = ax * 10000 + ay;
		else {
			sort(vec.begin(), vec.end());
			bool flag2 = false;
			for (int i = 1; i < vec.size(); i++) {
				if (vec[i - 1] != vec[i])flag2 = true;
			}
			if (flag2 == true)dp[ax][ay] = -1;
			else dp[ax][ay] = vec[0];
		}
	}
	int cnt = 0;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (dp[i][j] == -1)cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 18820
M,s=998244353,0
d=[1]+[0]*7**6
e=d[:]
n=input()
for _ in'_'*n:
 a=input();s+=a;i=s
 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1
print(3**n+~s%2*e[s//2]*3-3*sum(d[-~s//2:]))%M

Measured memory_bytes: 157576
n, m = map(int,input().split())
n, m = min(n,m), max(n,m)
def bi(x):
    count = 1
    for i in range(1,x+1):
        count = (count * i)%(10**9+7)
    return count
if abs(n-m) > 1:
    print(0)
elif n == m:
    print((bi(n)*bi(n)*2)%(10**9+7))
else:
    print((bi(m)*bi(n))%(10**9+7))



Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	int N, K, i, j, x;

	cin >> N >> K;
	vector<int> a_(N);
	for (i = 1; i <= N; i++){
		cin >> a_[i];
	}

	for (i = K+1; i <= N; i++){
		if (a_[i-K] < a_[i])
		{
			cout << "Yes" << endl;
			}
			else
			{
				cout << "No" << endl;
			}
	}

		return 0;
}

Measured memory_bytes: 3976
'use strict';
function main(input) {
  const num = Number(input.split('\n')[0]);
  const weightList = input.split('\n')[1].split(' ').map(i => Number(i));
  const distList = [];
  for (let i = 0; i < num - 1; i++) {
    distList.push(Math.abs(weightList.slice(0, i + 1).reduce((prev, current) => prev + current) - weightList.slice(i + 1).reduce((prev, current) => prev + current)));
  }
  console.log(Math.min(...distList));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7628