akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
using namespace std;

int main(){
	double a;
	while(scanf("%lf", &a), a >= 0.0){
		a *= 16.0;
		int b = a;
		if(a != b || b >= (1 << 12)){
			puts("NA");
		}
		else{
			for(int i = 11; i >= 0; --i){
				putchar((b >> i & 1) + '0');
				if(i == 4){ putchar('.'); }
			}
			puts("");
		}
	}
}

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

int main(){
    long long n, u, v, res; std::cin >> n;
    res = n * (n + 1) * (n + 2) / 6;
    while(std::cin >> u >> v) res -= std::min(u, v) * (n + 1 - std::max(u, v));
    std::cout << res << '\n';
}

Measured memory_bytes: 3624
T = list(input())

length = len(T)
count = 0
ans = 0
for i in T:
    if i == '?':
        T[count] = 'D'
        ans += 1
    elif i == 'P' and count != length-1:
        if T[count+1] == 'D' or T[count+1] == '?':
            ans += 1
    elif i == 'D':
        ans += 1

    count += 1

print(''.join(T))

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

using namespace std;

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

    int n, i = 0, ans = 0;
    string str;
    cin >> n >> str;
    
    while (i < n)
    {
        ans++;
        int cur = str[i];
        while (cur == str[i])
            i++;
    }
    
    cout << ans << "\n";
    
    return 0;
}


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


template<typename T> 
struct BIT{
  Int n;
  vector<T> bit;
  //1-indexed
  BIT():n(-1){}
  BIT(Int n_,T d):n(n_),bit(n_+1,d){}
  
  T sum(Int i){
    T s=0;
    for(Int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }
  void add(Int i,T a){
    if(i==0) return;
    for(Int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }
  
  Int lower_bound(Int w){
    if(w<=0) return 0;
    Int x=0,r=1;
    while(r<n) r<<=1;
    for(Int k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
	w-=bit[x+k];
	x+=k;
      }
    }
    return x+1;
  }
  
  T sum0(Int i){
    return sum(i+1);
  }
  void add0(Int i,T a){
    add(i+1,a);
  }
};

signed main(){
  string s;
  cin>>s;
  Int n=s.size();
  {
    vector<Int> c(26,0);
    for(Int i=0;i<n;i++) c[s[i]-'a']++;
    Int x=0;
    for(Int i=0;i<26;i++) if(c[i]&1) x++;
    if(x>1){
      cout<<-1<<endl;
      return 0;
    }
  }

  vector<deque<Int> > x(26);
  for(Int i=0;i<n;i++) x[s[i]-'a'].push_back(i);


  BIT<Int> bit(n+1000,0);
  
  Int ans=0;
  Int cnt=0,pos=-1;
  vector<Int> used(n,0);
  for(Int i=0;i<n;i++){
    if(used[i]) continue;
    Int c=s[i]-'a';
    if(x[c].size()==1u){
      pos=cnt++;
      bit.add0(i,1);
      continue;
    }
    Int a=x[c].front(),b=x[c].back();
    assert(a==i);
    x[c].pop_front();x[c].pop_back();
    used[b]=1;
    //cout<<n-(cnt+1)<<" "<<(b-bit.sum0(b))<<endl;
    ans+=(n-(cnt+1))-(b-bit.sum0(b));
    bit.add0(b,1);
    cnt++;
  }
  //cout<<pos<<endl;
  if(~pos) ans+=(n/2-pos);
  cout<<ans<<endl;
  return 0;
}


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

import heapq
q = [] # プライオリティキュー


n = int(input())
V = dict()
d = dict()

for i in range(n):
    data = list(map(int, input().split()))
    V[data[0]] = data[2:]
    d[data[0]] = float('inf')

d[0] = 0
heapq.heappush(q, (0, 0)) #(d[id], id)
S = set()

while len(S) != len(V):
    dist, node_id = heapq.heappop(q)
    S.add(node_id)
    for u, c in zip(V[node_id][0::2], V[node_id][1::2]): #隣接ノード
        if c + d[node_id] < d[u]:
            d[u] = c + d[node_id]
            heapq.heappush(q, (d[u], u))
            #print("Update:", u, d[u])
for i in range(n):
    print(i, d[i])


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

int main(){
    int N,num;
    int sum=0,max=0;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> num;
        sum += num;
        if(max < num) max = num;
    }
    if(sum > max*2) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#![allow(dead_code,unused_variables,unused_imports)]
use proconio::{fastout, input};
use proconio::marker::Chars;
use std::cmp::{max,min};
use std::collections::HashSet;

#[fastout]
fn main() {
    input!{
        x:i32,
        n:usize,
        p:[usize;n],
    }
    
    let mut st : HashSet<usize> = HashSet::new();
    for e in p{
        st.insert(e);
    }
    let mut ans = 103;
    let mut d = 200;
    for i in 0..=101{
        if !st.contains(&i){
            if (x-i as i32).abs() < d{
                ans = i;
                d = (x-i as i32).abs();
            }
        }
    }
    println!("{}",ans);
}

fn lower_bound(x: &Vec<usize>, key:usize) -> usize{
    let mut l = 0;
    let mut r = x.len();

    while l+1 < r{
        let mid = (r-l)/2 + l;

        if key < x[mid]{
            r = mid;
        }else{
            l = mid;
        }
    }
    l
}

Measured memory_bytes: 2216
#include <iostream>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main(){
    int A,B,C,X,count;
    cin>>A>>B>>C>>X;

    count=0;

for (size_t a = 0; a <= A; a++)
{
    for (size_t b = 0; b <= B; b++)
    {
        for (size_t c = 0; c <= C; c++)
        {
            if ((500*a + 100*b + 50*c)==X)
            {
                count++;
            }
            
        }
        
    }
    
}

cout<<count<<endl;




}

Measured memory_bytes: 3600
#include <iostream>
int main()
{
    int N;
    std::cin >> N;
    bool odd = false;
    for (int i = 0; i < N; i++) {
        int a;
        std::cin >> a;
        if (a % 2 == 1) { odd = true; }
    }
    std::cout << (odd ? "first" : "second") << std::endl;
    return 0;
}


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

vector<int> arr;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int p;
		cin>>p;
		arr.push_back(p);
	}
	int ans=0;
	for(int j=1;j<n-1;j++){
		vector<int> a={arr[j-1], arr[j], arr[j+1]};
		sort(a.begin(), a.end());
		if(arr[j]==a[1])ans++;
	}
	cout<<ans;
}



Measured memory_bytes: 3604
#include <iostream>
using namespace std;
#define ll long long int

int main() {
    int arr[5];
    for(int i=0;i<5;i++)
        cin>>arr[i];
    for(int i=0;i<5;i++)
        if(arr[i] == 0)
        {
            cout<<i+1;
            break;
        }
	return 0;
}

Measured memory_bytes: 3580
package main

import "fmt"

func scanNums(len int) []int {
	var num int
	var nums []int
	for i := 0; i < len; i ++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}

	return nums
}

func main() {
	var N int
	fmt.Scan(&N)
	
	nums := scanNums(N)

	flg := true
	count := 0

	for flg {
		for i, s := range nums {
			if s % 2 != 0 {
				flg = false
			}
			nums[i] = s / 2
		}
		count ++
	}
	fmt.Println(count - 1)
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{
	char a[10],b[10];
	cin>>a>>b; //输入
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <string>
#include <utility>
#include <map> 
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>
#include <cstring>
#define MP make_pair
#define PB push_back
#define SZ size()
#define B begin()
#define E end()
#define ll long long
#define REP(i,a,n) for(ll i=a; i<n; ++i)
#define RED(i,n,a) for(ll i=n; i>=a; --i)
#define m9 1000000007
#define endl "\n"
#define F first
#define S second
#define ld long double
#define eps 0.00000000001
#define MAX 1000000007
#define vll vector <ll> 
#define pll pair <ll,ll> 

using namespace std;

ll gcd(ll a, ll b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b, a%b);
    }
}
ll powc(ll a, ll b){
    if(b<0){
        return 0;
    }
    ll res=1;
    while(b>0){
        if(b&1){
            res*=a;
        }
        a*=a;
        res%=m9, a%=m9;
        b>>=1;
    }
    return res;
}



///target expert

int main(){
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x; cin>>x;
    if(x){
        cout<<0;
    }else{cout<<1;}
}



Measured memory_bytes: 3648
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n,a,b;
    cin>>n>>a>>b;
    vector<int> p(n);
    for(auto & a : p) cin>>a;
    sort(p.begin(),p.end());
    int w1 = upper_bound(p.begin(),p.end(),a) - p.begin();
    int w2 = upper_bound(p.begin(),p.end(),b) - upper_bound(p.begin(),p.end(),a);
    int w3 = p.end() - upper_bound(p.begin(),p.end(),b);
    int w = min({w1,w2,w3});
    cout << w << endl;
}


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

int main () {
    int A, B, K;
    cin >> A >> B >> K;
    int kaage=__gcd(A, B);
   //kaageは50になりますな

    int count =0;
    for (int i=1; i<=kaage; i++) {
        if (kaage%i==0) {
            count++;
        }
        if (count==K) {
            cout << kaage/i << endl;
            break;
        }
    }
}
        
    
        
    

    

Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int read();

char s[202];
int k, len;

long long res;
int main() {
    scanf("%s%d", s + 1, &k);
    len = strlen(s + 1);
    int b = 1;
    for (int i = 2; i <= len; ++i)
        if (s[i] != s[i - 1]) b = 0;
    if (b) {
        res = 1ll * len * k / 2;
        printf("%lld\n", res);
        return 0;
    }
    int l = 0, r = len;
    if (s[1] == s[len]) {
        l = 1;
        while (s[l + 1] == s[1]) l++;
        while (s[r - 1] == s[len]) r--;
        res += l / 2 + (len - r + 1) / 2;
        res += 1ll * (l + (len - r + 1)) / 2 * (k - 1);
    }
    for (int i = l + 1; i <= r; ++i) {
        int p = i;
        while (s[p + 1] == s[p] && p < r) p++;
        res += 1ll * (p - i + 1) / 2 * k;
        i = p;
    }
    printf("%lld\n", res);
    return 0;
}

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

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

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

    vector<int> x(n);

    vector<int> cp(n);

    for(int i=0; i<n; i++)cin>>x[i];

    cp = x;

    sort(x.begin(),x.end());

    int cen1 = x[n/2];
    int cen2 = x[n/2-1];

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

        if(cp[i]  < cen1  ) cout<<cen1<<endl;

        else if(cp[i] > cen2) cout<<cen2<<endl;

        else  cout<<cen1<<endl;
    }

    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

const ll M = 305;
ll dp[M][M];

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, K;
    cin >> n >> K;
    vll h(n);
    rep(i, n){
        cin >> h[i];
    }
    rep(i, M)rep(j, M){
        dp[i][j] = INF;
    }
    rep(j, n){
        dp[0][j] = 0;
        dp[1][j] = h[j];
    }
    repr(i, 2, n+1){
        rep(j, n){
            rep(k, j){
                chmin(dp[i][j], dp[i-1][k] + max(0ll, h[j] - h[k]));
            }
        }
    }
    rep(i, n+1){
        rep(j, n){
            dump(i, j, dp[i][j]);
        }
    }
    ll ans = INF;
    rep(i, M){
        chmin(ans, dp[n-K][i]);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

typedef long long ll;


int N;
int arr[450];
ll psum[100005];
ll dp[450][450];
const ll INF=1e18+7107;

ll solve(int L,int R)
{
    ll &ret=dp[L][R];
    if(ret!=-1)return ret;
    if(L==R)return 0LL;
    ret=INF;
    for(int K=L;K<R;K++)
        ret=min(ret,solve(L,K)+solve(K+1,R));
    
    return ret=ret+psum[R]-psum[L-1];

}


int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
        cin>>arr[i];
    for(int i=1;i<=N;i++)
        psum[i]=psum[i-1]+1LL*arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<solve(1,N);
}


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

public class Main {
  int n, m;
  Pair[] e;

  class Pair {
    int a, b, c;

    Pair(int a, int b, int c) {
      this.a = a;
      this.b = b;
      this.c = c;
    }
  }

  void run() {
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    m = sc.nextInt();
    e = new Pair[m];
    for (int j = 0; j < m; j++) {
      int s = sc.nextInt() - 1;
      int t = sc.nextInt() - 1;
      int u = -sc.nextInt();
      e[j] = new Pair(s, t, u);
    }

    long[] dist = new long[n];
    Arrays.fill(dist, (long) (1E+9) * (n - 1));
    dist[0] = 0;
    boolean[] f = new boolean[n];
    Arrays.fill(f, false);

    for (int i = 0; i < n - 1; i++) {
      for (int j = 0; j < m; j++) {
        int s = e[j].a;
        int t = e[j].b;
        int u = e[j].c;
        dist[t] = Math.min(dist[t], dist[s] + u);
      }
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int s = e[j].a;
        int t = e[j].b;
        int u = e[j].c;
        if (dist[s] == (long) (1E+9) * (n - 1)) {
          continue;
        }
        if (dist[s] + u < dist[t]) {
          dist[t] = dist[s] + u;
          f[t] = true;
        }
        if (f[s]) {
          f[t] = true;
        }
      }
    }
    if (f[n - 1]) {
      System.out.println("inf");
    } else {
      System.out.println(-dist[n - 1]);
    }
  }

  public static void main(String[] args) {
    new Main().run();
  }
}


Measured memory_bytes: 28260
D=int(input())
clist=list(map(int,input().split()))
smat=[[int(x) for x in input().split()] for _ in range(D)]
#print(clist)
#print(smat)

max_index_c=-1
max_c=-1
for i in range(26):
  if max_c<clist[i]:
    max_index_c=i+1
    max_c=clist[i]

for d in range(D):
  print(max_index_c)

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

#define REP(i,k,n) for(int i=k; i<n; i++)
#define all int i=0; i<n; i++
#define pb push_back

typedef long long int ll;

int main(){
	ll n;
	cin>>n;
	cout<<((n-1)*n)/2<<endl;
}

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

int main() {
    int h,n;
    cin >> h >> n;
    vector<P> witch(n);
    rep(i,n) {
        int a,b;
        cin >> a >> b;
        witch[i] = {a,b};
    }
    vector<vector<int>> dp(n,vector<int>(h+1));
    rep(i,h+1) {
        int fia = witch[0].first;
        int fib = witch[0].second;
        dp[0][i] = fib*((i+fia-1)/fia);
    }
    rep(i,n-1) {
        rep(j,h+1) {
            if(witch[i+1].first > j) dp[i+1][j] = min(dp[i][j],witch[i+1].second);
            else dp[i+1][j] = min(dp[i][j],dp[i+1][j-witch[i+1].first]+witch[i+1].second);
        }
    }
    cout << dp[n-1][h] << endl;
}

Measured memory_bytes: 39424
import java.util.*;

class Main{

    public Main(){
        Scanner scanner = new Scanner(System.in);
        int  N = scanner.nextInt();
        long M = scanner.nextLong();

        int[] A = new int[N];

        for(int i=0;i<N;i++){
            A[i] = scanner.nextInt();
        }

        Arrays.sort(A);

        int L = -1, R = A[N-1] * 2;
        while(R-L > 1){
            int mid = L + (R - L) / 2;

            long num = 0;
            for(int i=0;i<N;i++){
                num += N - binarySearch(A, mid-A[i]);
            }

            if(num < M)
                R = mid;
            else
                L = mid;
        }

        long[] S = new long[N+1];
        for(int i=0;i<N;i++) S[i+1] = S[i] + A[i];

        long count=0, result = 0;
        for(int i=0;i<N;i++){
            int num = binarySearch(A, R-A[i]);
            count  += N - num;
            result += ((long)A[i])*((long)(N-num)) + S[N] - S[num];
        }

        if(M-count>0) result += L * (M - count);
        else if(M-count<0) result -= R * (count - M);

        System.out.println(result);
    }

    int binarySearch(int[] A, int key){
        int L = -1, R = A.length;
        while(R-L>1) {
            int mid = L + (R-L) / 2;

            if(A[mid] >= key)
                R = mid;
            else
                L = mid;
        }
        return R;
    }


    public static void main(String args[]) throws Exception{
        Main main = new Main();
    }
}


Measured memory_bytes: 52644
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#include <unordered_map>
#define INF 2147483647
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	ll A, B, C, K;
	cin >> A >> B >> C >> K;
	ll ans = A - B;
	if (K % 2 == 1) ans *= -1;
	if (abs(ans) > pow(10, 18)) cout << "Unfair" << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        if (x < a) {
            System.out.println(0);
        } else {
            System.out.println(10);
        }

		sc.close();
	}
}


Measured memory_bytes: 21844
N = int(input())
A =list(map(int, input().split()))

cnt = 0
for i in A:
    if i < 0: cnt += 1

A_abs = list(map(abs, A))
minmum = min(A_abs)

if cnt % 2 == 0:
    ans = sum(A_abs)
else:
    ans = sum(A_abs) - 2*minmum

print(ans)


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const ll MAX_N = pow(10,6);

int main()
{
    int N, M; cin >> N >> M;
    int max_l = 0;
    int min_r = pow(10,6);
    rep(i,M){
        int L, R; cin >> L >> R;
        if(max_l < L) max_l = L;
        if(min_r > R) min_r = R;
    }
    if(min_r-max_l<0) cout << 0 << endl;
    else cout << min_r-max_l+1 << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int max = 0;
		int semi = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] >= max) {
				semi = max;
				max = a[i];
			} else if (a[i] >= semi) {
				semi = a[i];
			}
		}
		for (int i = 0; i < n; i++) {
			if (a[i] == max) {
				System.out.println(semi);
			} else {
				System.out.println(max);
			}
		}
	}
}

Measured memory_bytes: 85348
#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 N;
    cin >> N;
    cout << N * N * N << "\n";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int N, M, V, P;
int A[100010];
bool isOK(int index) {
    int num = A[index];
    num += M;
    int amari = max(0LL, V - (N - index) - (P - 1));
    int sum = 0;
    REP(i, P - 1, index - 1) sum += A[i];
    sum += amari * M;
    int target = A[P - 1];
    if (amari > 0){
        int p = ((index - 1) - (P - 1) + 1);
        target = max(target, (sum + p - 1) / p);
    }
    //cout << index + 1 << " " << sum << " " << target << " " << num << " " << amari << endl;
    if (target <= num) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search() {
    int ng = N; 
    int ok = 0;

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> V >> P;
    rep(i, N) cin >> A[i];
    sort(A, A + N, greater<int>());
    //rep(i, N) cout << A[i] << " ";
    //cout << endl;
    cout << binary_search() + 1 << endl;
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1000000007;
const LL LINF = 1LL * INF * INF;
const int MAXN = 100007;
const LD EPS = 1e-7;

int T[MAXN], X[MAXN], Y[MAXN];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int n;
	bool ok = true;
	cin >> n;
	T[0] = X[0] = Y[0] = 0;
	FOR(i, 1, n + 1)
		cin >> T[i] >> X[i] >> Y[i];
	FOR(i, 1, n + 1)
	{
		if (abs(X[i] - X[i - 1]) + abs(Y[i] - Y[i - 1]) > T[i] - T[i - 1] || 
			(abs(X[i] - X[i - 1]) + abs(Y[i] - Y[i - 1]) - (T[i] - T[i - 1])) & 1)
			ok = false;
	}
	cout << (ok ? "Yes" : "No");
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
  string S;
  cin>>S;
  
  long int A=0;
  for(int i=0; i<S.size(); ++i){
    if(i%2==0){
      if(S.at(i)=='0') A++;
    }
    else{
      if(S.at(i)=='1') A++;
    }
  }
  
  if(A>S.size()-A) cout<<S.size()-A <<endl;
  else cout<<A<<endl;
}


Measured memory_bytes: 512
package main

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

func main() {
	N, _ := ReadInt(), ReadInt()
	As := ReadInts(N)
	foundMax := -1
	maxProfix := -1
	m := make(map[int]int)
	for i := N - 1; i >= 0; i-- {
		if As[i] > foundMax {
			foundMax = As[i]
			continue
		}
		profit := foundMax - As[i]
		m[profit]++
		if profit > maxProfix {
			maxProfix = profit
		}
	}
	fmt.Println(m[maxProfix])
}

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: 9980
a, b, c, x = map(int, [input() for i in range(4)])
ans = 0
for i in range(a + 1):
        for j in range(b + 1):
                for k in range(c + 1):
                        if i * 500 + j * 100 + k * 50 == x:
                                ans += 1

print(ans)

Measured memory_bytes: 3060
//#i#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

ll ans_2(string s, int n){
	ll ret = 0;
	rip(i,n,0){
		if((s[i]-'0')%2 == 0) ret += (ll) i+1;
	}
	return ret;
}

ll ans_5(string s, int n){
	ll ret = 0;
	rip(i,n,0){
		if((s[i]-'0')%5 == 0) ret += (ll) i+1;
	}
	return ret;
}

int main(){
	int n,p; cin >> n  >> p;
	string s; cin >> s;
	if(p == 2){
		cout << ans_2(s,n) << endl;
		return 0;
	}
	if(p == 5){
		cout << ans_5(s,n) << endl;
		return 0;
	}
	int gg = 1;
	vector<int> da(n);
	da[n-1] = (s[n-1]-'0')%p;
	rip(i,n,1){
		gg = gg*10%p;
		da[n-i-1] = (da[n-i]+gg*(s[n-i-1]-'0')%p)%p;
	}
	vector<ll> li(p);
	rip(i,n,0){
		li[da[i]]++;
	}
	ll ans = 0;
	rip(i,p,1){
		ans += li[i]*(li[i]-1)/2;
	}
	ans += (li[0]+1)*li[0]/2;
	cout << ans << endl;
}

Measured memory_bytes: 1412
#include <iostream>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

int main(){
    int h,n,a;
    long long sum = 0;

    cin >> h >> n;
    while(n--){
        cin >> a;
        sum+=a;
    }
    if(sum>=h) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        String[] input = sc.nextLine().split(" ");
        int co4 = 0;
        int co2 = 0;
        int co1 = 0;
        int[] num = new int[N];

        for(int i=0; i<N; i++){
            num[i] = Integer.parseInt(input[i]);
        }
        for(int i=0; i<N; i++){
            if(num[i] % 4 == 0){
                co4++;
            }
            else if(num[i] % 2 == 0){
                co2++;
            }
            else{
                co1++;
            }
        }
        if(co2 == 0){
            if(co4 + 1 >= co1){
                System.out.println("Yes");
            }
            else{
                System.out.println("No");
            }
        }
        else{
            if(co4 >= co1){
                System.out.println("Yes");
            }
            else{
                System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 46600
N = int(input())
L = list(map(int, input().split()))
L.sort()
N = len(L)
ans = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    if L[i] == L[j]:
      continue
    for k in range(j+1, N):
      if L[j] == L[k]:
        continue
      if L[i] + L[j] <= L[k]:
        break
      else:
        ans += 1
print(ans)

Measured memory_bytes: 9208
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String T = scan.next();
    int N = T.length();
    String[] split = T.split("");
    for (int i = 0;i < N; i++) {
      if (split[i].equals("?")) {
        split[i] = "D";
      }
    }
     StringJoiner str = new StringJoiner("");
    for (String s : split) {
      str.add(s);
    }
    System.out.println(str.toString());    
  }
}


Measured memory_bytes: 66164
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
#define int ll
#define INF 100000000000000
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
vector<bool>used;
vector<vector<pii>>edge;
vector<int>d;
bool judge=true;
void dfs(int v,int val){
    used[v]=true;
    rep(i,edge[v].size()){
        int next=edge[v][i].first;
        int cost=edge[v][i].second;
        if(d[next]==INF){
            d[next]=val+cost;
            if(!used[next])dfs(next,val+cost);
            continue;
        }
        else{
            if(d[next]!=INF&&d[next]!=cost+val)judge=false;
        }
    }
}
signed main(){
    int n,m; cin>>n>>m;
    edge.resize(n);
    used.resize(n);
    d.resize(n);
    rep(i,n)d[i]=INF,used[i]=false;
    rep(i,m){
        int a,b,c;cin>>a>>b>>c;
        --a,--b;
        edge[a].push_back(mp(b,c));
        edge[b].push_back(mp(a,-c));
    }
    rep(i,n)if(!used[i])dfs(i,0);
    if(judge)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 16512
def gcd(a,b):
	if b == 0:
		return a
	return gcd(b,a%b)

ans = 0

k = int(input())
for i in range(1,k+1):
	for j in range(1,k+1):
		ab = gcd(i,j)
		if ab == 1:
			ans += k
		else:
			for l in range(1,k+1):
				abc = gcd(ab,l)
				ans += abc
print(ans)


Measured memory_bytes: 9192
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int ans = 0;
        
        if (a>b){
            ans += a;
            a--;
            ans += Math.max(a,b);
        }else{
            ans += b;
            b--;
            ans += Math.max(a,b);
        }System.out.println(ans);


    }
}


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

double d, e;

double MG(int x, int y){
	double dist = sqrt(pow(x,2) + pow(y,2));
	return (double)fabs(dist - e);
}


int main(){
while(1){	
	
	cin >> d >> e;
	if(d == 0 and e == 0) break;
	double ans = 999999;
	for(int x=0; x<101; x++){
		for(int y=0; y<101; y++){
			if(d == x + y){
				ans = min(ans, MG(x, y));
			}
		}
	}
	
	cout << ans << endl;
	
}//end	
	
	return 0;
}


Measured memory_bytes: 3204
import sys
sys.setrecursionlimit(10**6)

MOD = 10**9+7
memo = {}
def steps(n):
  if not(n in memo):
    if n == 0:
      memo[n] = 1
    elif n == 1:
      memo[n] = 1
    else:
      memo[n] = (steps(n-1)+steps(n-2))%MOD
  return memo[n]

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
nowstep = 0
ans = 1
for a in A:
  if nowstep == a:
    ans = 0
    break
  ans = (ans * steps(a-1-nowstep))%MOD
  nowstep = a+1
ans = (ans * steps(N-nowstep))%MOD
print(ans)



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

const int32_t MAX_N = 300;

double dpP[MAX_N + 5][MAX_N + 5][MAX_N + 5], dpEv[MAX_N + 5][MAX_N + 5][MAX_N + 5];

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int32_t n;
	std::cin >> n;

	int32_t cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for(int32_t i = 0; i < n; i++) {
		int32_t a;
		std::cin >> a;

		if(a == 1) {
			cnt1++;
		}
		else if(a == 2) {
			cnt2++;
		}
		else {
			cnt3++;
		}
	}
	
	dpP[cnt1][cnt2][cnt3] = 1.0;
	dpEv[cnt1][cnt2][cnt3] = 0.0;
	for(int32_t c = n; c >= 0; c--) {
		for(int32_t b = n; b >= 0; b--) {
			for(int32_t a = n; a >= 0; a--) {
				if(a == 0 && b == 0 && c == 0) {
					continue;
				}
				if(a + b + c > n) {
					continue;
				}

				double aux = ((double) (n - a - b - c) / n);
				dpEv[a][b][c] += aux / (1.0 - aux) * dpP[a][b][c];
				
				if(a > 0) {
					dpP[a - 1][b][c] += dpP[a][b][c] * ((double) a / (a + b + c));
					dpEv[a - 1][b][c] += dpEv[a][b][c] * ((double) a / (a + b + c));
				}
				if(b > 0) {
					dpP[a + 1][b - 1][c] += dpP[a][b][c] * ((double) b / (a + b + c));
					dpEv[a + 1][b - 1][c] += dpEv[a][b][c] * ((double) b / (a + b + c));
				}
				if(c > 0) {
					dpP[a][b + 1][c - 1] += dpP[a][b][c] * ((double) c / (a + b + c));
					dpEv[a][b + 1][c - 1] += dpEv[a][b][c] * ((double) c / (a + b + c));
				}
			}
		}
	}

	std::cout << std::fixed << std::setprecision(9);
	std::cout << dpEv[0][0][0] + cnt1 + 2 * cnt2 + 3 * cnt3 << '\n';
}



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

int main(){
    int n; cin>>n;
    int cnt=0;
    int want=1;
    vector<int> a(n);
    bool one=false;
    
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(a[i]==1) one = true;
    }

    for(int i=0; i<n; i++){
        if(a[i] != want) cnt++;
        else if(a[i] == want){
            want++;
        }
    }
    if(!one)cout<<-1<<endl;
    else cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m , n , x;
  	cin >> m >> n;
	int sum = 0;
  	for(int i = 0 ; i < n ;i++)
    {
		cin >> x;
      	sum += x;
    }
  	if(sum >= m)
      cout << "Yes" << endl;
  	else
      cout << "No" << endl;
  	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int[] NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int res = NK[1];
        for (int i = 1; i < NK[0]; i++)
        {
            res *= NK[1] - 1;
        }
        Console.WriteLine(res);
    }
}

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

using ll = long long;

ll solve(ll a, ll b){
	if(a == b) return a;
	if(b > a) return solve(b, a);
	ll k = ((a-1) / b);
	return solve(a - k * b, b) + 2 * k * b;
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, x;
	cin >> n >> x;
	ll ans = solve(x, n-x) + n;
	cout << ans << '\n';
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
struct state { long long a, b; };
struct comparer {
	bool operator()(const state& s1, const state& s2) const { return s1.a < s2.a; }
};
int N; long long D, A[33], B[33];
state vl[7777777], vr[7777777]; // meet-in-the middle
int que[14348922]; // searching deque
int main() {
	scanf("%d%lld", &N, &D);
	for (int i = 0; i < N; i++) scanf("%lld%lld", &A[i], &B[i]);

	// Calculate sum with bitmasking
	int sep1 = (N >> 1), sep2 = N - sep1;
	vector<long long> sa1(1 << sep1), sb1(1 << sep1);
	vector<long long> sa2(1 << sep2), sb2(1 << sep2);
	for (int i = 0; i < sep1; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa1[j] = sa1[j - b1] + A[i];
			sb1[j] = sb1[j - b1] + B[i];
		}
	}
	for (int i = 0; i < sep2; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa2[j] = sa2[j - b1] + A[i + sep1];
			sb2[j] = sb2[j - b1] + B[i + sep1];
		}
	}

	// Meet-in-the-middle Algorithm
	int cnt1 = 0, cnt3 = 0;
	for (int i = 0; i < 1 << sep1; i++) {
		int r = (1 << sep1) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa1[k] - sa1[j];
			long long r2 = sb1[k] - sb1[j];
			if (r1 >= 0) vl[cnt1++] = state{ r1, r2 };
			if (r1 > 0) cnt3++;
			j = (j - 1) & r;
		} while (j != r);
	}
	int cnt2 = 0, cnt4 = 0;
	for (int i = 0; i < 1 << sep2; i++) {
		int r = (1 << sep2) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa2[k] - sa2[j];
			long long r2 = sb2[k] - sb2[j];
			if (r1 >= 0) vr[cnt2++] = state{ r1, r2 };
			if (r1 > 0) cnt4++;
			j = (j - 1) & r;
		} while (j != r);
	}

	// Sorting
	sort(vl, vl + cnt1, comparer()); cnt1 += cnt3;
	sort(vr, vr + cnt2, comparer()); cnt2 += cnt4;

	int cnt5 = cnt1 - cnt3;
	int cnt6 = cnt2 - cnt4;
	vector<state> wl(cnt1), wr(cnt2);
	for (int i = 0; i < cnt3; i++) wl[i] = state{ -vl[cnt5 - i - 1].a, -vl[cnt5 - i - 1].b };
	for (int i = 0; i < cnt4; i++) wr[i] = state{ -vr[cnt6 - i - 1].a, -vr[cnt6 - i - 1].b };
	copy(vl, vl + cnt5, wl.begin() + cnt3);
	copy(vr, vr + cnt6, wr.begin() + cnt4);

	// Searching with deque
	int cl = 0, cr = 0, dl = 0, dr = 0;
	long long ret = 0;
	for (int i = cnt2 - 1; i >= 0; i--) {
		while (cr < cnt1 && wl[cr].a + wr[i].a <= D) {
			while (dr - dl && wl[que[dr - 1]].b <= wl[cr].b) dr--;
			que[dr++] = cr++;
		}
		while (cl < cnt1 && wl[cl].a + wr[i].a < -D) {
			if (dr - dl && que[dl] == cl) dl++;
			cl++;
		}
		if (dr - dl) ret = max(ret, wr[i].b + wl[que[dl]].b);
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 681916
n, m, l = (int(x) for x in input().split())
A = [[0 for i in range (m)] for j in range (n)]
B = [[0 for i in range (l)] for j in range (m)]
C = [[0 for i in range (l)] for j in range (n)]
 
for _ in range(n):
    a = [int(x) for x in input().split()]
    for i,j in enumerate(a):
        A[_][i] = j

for _ in range(m):
    a = [int(x) for x in input().split()]
    for i,j in enumerate(a):
        B[_][i] = j

for row in range(n):
    for col in range(l):
        for k in range(m):
            C[row][col] += A[row][k]*B[k][col]
    for _ in range(l):
        if _ == l-1:
            print(C[row][_],end="")
            continue
        print(C[row][_],end="")
        print(" ", end="")
    print()


Measured memory_bytes: 7156
#include <iostream>
using namespace std;
#include <stdio.h>
int main()
{
	int a,b,n;
	char c;
	while(~scanf("%d %c %d",&a,&c,&b))
	{
		if(c=='-')
		cout<<a-b<<endl;
		else
		cout<<a+b<<endl;
	}
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int total = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    total += a[i];
  }
  
  double tmp = (double)1 / (4 * m);
  double check = total * tmp; 
  //cout << check;
  int cnt = 0;
  for (int i = 0; i < n; i++)
  {
    if (a[i] >= check)
    {
      cnt++;
    }
  }
  
  if (m <= cnt)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
std::vector<int> graph[10050];//graph頂点数のsize
const int N=200010;
const int P=1000000007;
using ll = long long;
vector<ll> prime;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/


/*
	string s;
	s.size()
*/

/*
	char s[N];
	strlen(s)
*/
/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/


int main(){
  ll n,k;
  cin>>n>>k;
  set<ll> S;
  rep(i, k){
    ll d;
    cin>>d;
    rep(j, d){
      ll kari;
      cin>>kari;
      S.insert(kari);
    }
  }
  cout<<n-sz(S)<<endl;


}


Measured memory_bytes: 3840
import java.util.Scanner;

import java.util.Arrays;
import java.util.ArrayList;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int [] A = new int[N];
		int [] B = new int[N];
		int negacnt = 0;
		long abstotal = 0;
		for (int i=0; i<N; i++) {
			A[i] = sc.nextInt();
			B[i] = Math.abs(A[i]);
			if(A[i] <= 0) {
				negacnt++;
			}
			abstotal += B[i];
		}
		
		if(negacnt % 2 == 1) {
			Arrays.sort(B);
			abstotal -= B[0] * 2;
		}
	
		System.out.println(abstotal);
		
	}
}	


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

int main() {
  int N, p;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string x;
    cin >> x;
    if (x == "Y") {
      p = 1;
      break;
    }
    else {
      p = 0;
    }
  }
  if (p == 1) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

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

Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

using namespace std;



int main(){
	int n,a,b;
  	cin>>n>>a>>b;
  	if(n*a>b)cout<<b<<endl;
  	else cout<<n*a<<endl;



    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	ll n;
	cin >> n;
	ll ans = 1e18;
	for (ll i = 1;i * i <= n;++i) {
		if (n % i != 0)continue;
		ll j = n / i;
		ans = min(ans, i + j - 2);
	}
	cout << ans << endl;
	return 0;
}

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

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

#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 RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define FS first
#define SE second

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  LL gate=1e15+1;
  LL n,a;
  cin >> n ;
  LL ans=0;
  REP(i,5){
    cin >> a ;
    if(a<gate) gate = a;
  }
  ans = ceil((double)n/gate)+4;

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256