akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int count=0;
  rep(i,a+1){
    rep(j,b+1){
      rep(k,c+1){
        if(i*500+100*j+50*k==x)count++;
      }
    }
  }
  cout << count << endl;
}

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

const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x = 0): x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

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

    int n, s;
    cin >> n >> s;

    vector<int> a(n);
    REP(i, n) cin >> a[i];

    // dp テーブルは1段ごとに使い捨てる方法を採用
    vector<mint> dp(s + 1, 0);

    dp[0] = 1;

    REP(i, n) {
        // 次の dp を用意してる
        vector<mint> p(s + 1, 0); // p が dp[i] で古い方
        swap(dp, p); // dp が dp[i + 1] で更新される方
        REP(j, s + 1) {
            dp[j] += p[j] * 2; // 空集合も含む部分集合の総数
            if (j + a[i] <= s) dp[j + a[i]] += p[j];
        }
    }

    cout << dp[s] << '\n';
    return 0;
    return 0;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
char s[100007];
int get[128];
int main()
{
    get['b']=0,get['p']=1,get['d']=2,get['q']=3;
    scanf("%s",s+1);
    for(int l=strlen(s+1),i=1;i<=(l>>1)+1;i++)
    {
        if(get[s[i]]^((get[s[l-i+1]]+2)%4))
			return puts("No"),0;
    }
    return puts("Yes"),0;
}

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

int main()
{
  int N, Sum=0;
  cin >> N;
  vector<int> p(N);
  rep(i, N) cin >> p.at(i);
  sort(p.begin(), p.end());
  p.at(p.size()-1)=p.at(p.size()-1)/2;
  rep(i, N) Sum=Sum+p.at(i);
  cout << Sum << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;
using static System.Math;
using static System.Array;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;



        public static void Input()
        {
            var cin = new Scanner();
            
        }

        static void Main(string[] args)
        {
            Input();

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = input[0];
            int Q = input[1];
            List<List<int>> G = new List<List<int>>();
            for (var i = 0; i < N; i++)
            {
                G.Add(new List<int>());
            }
            var g = new Graph();
            int[] p = new int[Q];
            int[] x = new int[Q];


            long[] ans = new long[N];
            bool[] seen = new bool[N];

            for (var i = 0; i < N - 1; i++)
            {

                var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
                G[ab[0] - 1].Add(ab[1] - 1);
                G[ab[1] - 1].Add(ab[0] - 1);
            }

            for (var i = 0; i < N; i++)
            {
                ans[i] = 0;
                seen[i] = false;
            }

            for (var i = 0; i < Q; i++)
            {
                var px = Console.ReadLine().Split().Select(int.Parse).ToArray();
                p[i] = px[0];
                x[i] = px[1];

                ans[p[i] - 1] += x[i];
            }



            seen[0] = true;
            g.Dfs(G, seen, 0, ans);


            for (var i = 0; i < N; i++)
            {
                Console.Write($"{ans[i]} ");
            }



            Console.Out.Flush();

        }





    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        public void Dfs(List<List<int>> graph, bool[] seen, int v, long[] ans)
        {
            seen[v] = true;
            //初めて訪れたタイミングでここの処理

            foreach (var next in graph[v])
            {
                if (seen[next] == true) { continue; }
                ans[next] += ans[v];
                Dfs(graph, seen, next, ans);
                //探索候補に入った時点でここの処理
            }
            //行き先がない状態になったらこの部分の処理

        }
    }
}

    



Measured memory_bytes: 64936
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <list>
#include <vector>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define pf push_front
int main()
{
	int a[12], b[12];
	char buf[256];
	while (fgets(buf, 256, stdin)) {
		char* p = strtok(buf, " ");
		int L = atoi(p);
		int n = 0;
		while (p = strtok(NULL, " ")) a[n++] = atoi(p);
		std::sort(a, a + n);
		bool ok = false;

		b[n/2] = a[0];
		int i = 0, j = 1, k = 1, l = 1;
		while (i < n) {
			if (i % 4 == 0) { b[n/2+k] = a[n-l]; l++; }
			if (i % 4 == 1) { b[n/2-k] = a[n-l]; l++; k++; }
			if (i % 4 == 2) { b[n/2+k] = a[j]; j++; }
			if (i % 4 == 3) { b[n/2-k] = a[j]; j++; k++; }
			i++;
		}
		double t = b[0];
		REP(i, 1, n) t += 2 * sqrt(b[i-1] * b[i]);
		t += b[n-1];
		if (!(t > L)) ok = true;

		/*
		do {
			double t = a[0];
			REP(i, 1, n) t += 2 * sqrt(a[i-1] * a[i]);
			t += a[n-1];
			if (!(t > L)) { ok = true; break; }
		} while (std::next_permutation(a, a+n));
		*/
		puts(ok ? "OK" : "NA");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include<string>
#include<vector>

using namespace std;

int corattu(int num) {
	if (num % 2 == 0)return num / 2;
	return 3 * num + 1;
}


int main()
{
	
	int n;

	cin >> n;

	if (n == 1) {

		cout << "Hello World" << endl;


	}
	else {

		int a, b;

		cin >> a >> b;
		cout << a + b << endl;

	}

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string s;
    cin>>s;
    int ans=(s[0]=='1')+(s[1]=='1')+(s[2]=='1');
    cout<<ans<<endl;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	// writer  = bufio.NewWriterSize(os.Stdout, 1000000)
)

func main() {
	scanner.Split(bufio.ScanWords)
	// scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	// defer writer.Flush()
	n, m := scanInt(), scanInt()
	a := scanInts(m)

	for i := 0; i < m; i++ {
		n -= a[i]
	}

	if n >= 0 {
		fmt.Println(n)
	} else {
		fmt.Println(-1)
	}
}

func scanInt() int {
	i, _ := strconv.Atoi(scanString())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanString() string {
	scanner.Scan()
	return scanner.Text()
}

func scanStrings(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanString()
	}
	return s
}


Measured memory_bytes: 1896
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7
INF = 10**9

n,T = MAP()
ans = INF
for i in range(n):
    c,t = MAP()
    if t<=T:
        ans = min(c,ans)
if ans==INF:
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3444
#include <stdio.h>


int top=0;
int s[200];

void push(int x){
  top++;
  s[top]=x;
}

int pop(){
  top--;
  return s[top+1];
}
	



int main(){

  int i,j,k,s1,s2,sum;
  char a[8];

  for(i=0; i<200; i++){
    for(k=0; k<8; k++){
      scanf("%c",&a[k]);
      if(a[k]==' '||a[k]=='\n')
	break;
    }

    

    switch(a[0]){
    case '+':
      s1=pop();
      s2=pop();
      push(s1+s2);
      break;

    case '-':
      s1=pop();
      s2=pop();
      push(s2-s1);
      break;

    case '*':
      s1=pop();
      s2=pop();
      push(s1*s2);
      break;

    default:
      sum=0;
      for(j=0; j<8; j++){
	if(a[j]==' ')
	  break;
	sum=sum*10+(a[j]-48);
      }
      push(sum);
      break;
    }
    if(a[k]=='\n')
      break;

  }
  printf("%d\n",s[1])  ;    
  return 0;
}
    
    
    




Measured memory_bytes: 2100
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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; }

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};



void solve(){
    ll n;
    cin>>n;
    cout<<n/3<<endl;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    solve();

    return 0;
}


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

int main(void){
    int H,W,i;
    cin >> H>>W;
    string grid[H];
    for(i=0;i<H;i++){
        cin>>grid[i];
    }
    int j;
  	int cnt[H][W];
    memset(cnt,0,sizeof(cnt));
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            if(i==0&&j==0){
                cnt[i][j]=1;
            }
            if(grid[i][j]=='#'){
                cnt[i][j]=0;
            }
            if(grid[i][j]!='#'){
                if(0<=i-1){
                    cnt[i][j]+=cnt[i-1][j]%(1000000000+7);
                }
                if(0<=j-1){
                    cnt[i][j]+=cnt[i][j-1]%(1000000000+7);
                }
            }
          cnt[i][j] %= (1000000000+7);
        }
    }
    cout << cnt[H-1][W-1]<<endl;
    return 0;
}

Measured memory_bytes: 5248
#include<stdio.h>

int main(void)
{
	int x,i,j;
	scanf("%d",&x);
	int flg=0;
	
	for(i=1;i<=9;i++){
		for(j=1;j<=9;j++){
			if(i*j==x){
				flg=1;
			}
			}
		}
	if(flg==0)
		printf("No");
	else
		printf("Yes");
	return 0;
}
		

Measured memory_bytes: 128
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

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

    size_t N, K; cin >> N >> K;

    vector<bool> hate(10, false);
    for (size_t i = 0; i < K; ++i) {
        size_t d; cin >> d;
        hate[d] = true;
    }

    const auto ok = [&](size_t n) {
        string s = to_string(n);
        for (auto si: s) {
            if (hate[si - '0']) {
                return false;
            }
        }
        return true;
    };

    while (true) {
        if (ok(N)) {
            return cout << N << "\n", 0;
        }
        N++;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int solve(int*data,int n,bool check,const int max){
  if(max==n){
    if(check)return 1;
    return 0;
  }
  int a,b;
  if((data[n]%2)==0){
    a=2*solve(data,n+1,check,max);
    check=true;
    b=solve(data,n+1,check,max);
  }else{
    a=solve(data,n+1,check,max);
    check=true;
    b=2*solve(data,n+1,check,max);
  }
  return a+b;
}
int main(void){
  int n=0;
  cin>>n;
  int*data=new int[n];
  for(int i=0;i<n;i++){
    cin>>data[i];
  }
  cout<<solve(data,0,false,n)<<endl;
  return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def divisions(n):
    sq = int(math.sqrt(n)+1)
    ss = 30030
    a = [None] * (ss)
    a[0] = 1
    t = 1
    for i in range(2,ss):
        if not a[i] is None:
            continue
        if t * i > ss:
            break
        t *= i
        for j in range(i*2,ss,i):
            a[j] = 1
    a = [i for i in range(t) if a[i] is None]
    d = collections.defaultdict(int)
    for i in a[1:]:
        while n % i == 0:
            n //= i
            d[i] += 1

    for j in range(1,sq//t+2):
        if t*j > n:
            break
        for ii in a:
            i = t*j+ii
            while n % i == 0:
                n //= i
                d[i] += 1

    if n > 1:
        d[n] += 1

    return d

def inv(x):
    return pow(x, mod - 2, mod)

cms = 10**5 + 100
cm = [0] * cms

def comb_init():
    cm[0] = 1
    for i in range(1, cms):
        cm[i] = cm[i-1] * i % mod

def comb(a, b):
    return (cm[a] * inv(cm[a-b]) % mod) * inv(cm[b]) % mod

def main():
    n,m = LI()

    comb_init()
    d = divisions(m)
    r = 1
    for v in d.values():
        r *= comb(n+v-1,v)
        r %= mod

    return r


print(main())



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

vector<ll>multiple(10000005);

void prime(int v){
  multiple[0]=-1;
  multiple[1]=-1;
  for(int i=2; i<=v; i++){
    if(multiple[i]!=0)continue;
    for(int j=i*2; j<=v; j+=i){
     multiple[j]=i;
    }
  }
}

int main(){
  ll n;
  cin >> n;
  prime(10000000);
  ll nn = pow(n,0.5);
  vector<ll>dp(n+1,1);
  
  for(int i=1; i<=n; i++){
    if(multiple[i]==0) dp[i]=2;
  }
  
  
  ll ans=0;
  for(int i=1; i<=n;i++){
    if(i==1 || multiple[i]==0){
      ans+=i*dp[i];
      continue;
    }
    ll x=i;
    ll c=0;
    while(x%multiple[i]==0){
          x/=multiple[i];
          c++;
    }
    dp[i]=dp[x]*(c+1);

    if(x!=1 && dp[x]==1)dp[i]*=2;
    ans+=i*dp[i];
  }
  //for(int i=1; i<=n; i++)cout << dp[i] <<" ";
  cout << ans << endl;
  
}
       
        
      
  
    

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

double calctime(double x, double y, double r) {
	x = abs(x);
	if (x >= r) return 1e9;
	return y - sqrt(r * r - x * x) + r;
}

int main() {
	for (;;) {
		int r, n; cin >> r >> n;
		if (!r && !n) break;
		map<int, map<int, int>> filled;

		rep(i, 0, n) {
			int xl, xr, h; cin >> xl >> xr >> h;
			rep(j, xl, xr) rep(k, 0, h) filled[j][k] = 1;
		}

		double t = 1e9;
		rep(i, -20, 20) rep(j, 0, 21) if (!filled[i][j]) {
			if (i < 0) t = min(t, calctime(i + 1, j, r));
			else t = min(t, calctime(i, j, r));
		}

		cout << fixed << setprecision(9) << t << endl;
	}
}



Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int w,a,b;
    cin>>w>>a>>b;
    if(a>b){
        if(a-b<w) cout<<0<<endl;
        else cout<<a-b-w<<endl;
    }
    else {
        if(b-a<w) cout<<0<<endl;
        else cout<<b-a-w<<endl;
    }
}

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

typedef long long ll;

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    
    int ans;
    ans = x/(y+z);
    if(x%(y+z)>=z){
        cout << ans << endl;
    }
    else
        cout << ans-1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
    
    int n;
    cin >> n;
    if(n % 1000 == 0) {
    	cout << 0 << "\n";
    } else {
    	cout << 1000 - n % 1000 << "\n";
    }
	return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;

struct Bug{
	int out,in;
	bool operator <(const Bug &a)const{
		return in>a.in;
	}
};

int N;
Bug b[300000];

bool isTokyo(int k){
	priority_queue<int> latte;
	ll sum = 0;
	for(int i=0;i<N;i++){
		if(latte.size()<k-1){
			sum += b[i].out; latte.push(b[i].out); continue;
		}
		if((double)(sum+b[i].out)/(double)k<=(double)b[i].in) return true;
		if(latte.size()==0) continue;
		int max_ = latte.top();
		if(max_>b[i].out){
			sum -= max_;
			latte.pop();
			sum += b[i].out;
			latte.push(b[i].out);
		}
	}
	return false;
}

signed main(){
	cin>>N;
	for(int i=0;i<N;i++) cin>>b[i].out>>b[i].in;
	sort(b,b+N);
	int l=0, r=N+1;
	while(l+1 != r){
		int piv = (l+r)/2;
		if(isTokyo(piv)) l = piv;
		else r = piv;
	}
	printf("%d\n",l);
	return 0;
}

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

int main(){

    ll n,t;
    cin >> n  >> t;

    vector<ll> a(n);
    ll ans = 0;

    rep(i,n){
        cin >> a[i];
    }
    a.push_back(a.back()+t);

    rep(i,n){
        if(a[i+1]-a[i]<t){
            ans+=a[i+1]-a[i];
        }else{
            ans+=t;
        }
    }

    cout << ans <<endl; 

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> dp(h + 1, numeric_limits<int32_t>::max());
    dp[0] = 0;
    for (auto i : irange(0L, n)) {
        int64_t a, b;
        cin >> a >> b;

        for (auto j : irange(0L, h)) {
            dp[min(j + a, h)] = min(dp[min(j + a, h)], dp[j] + b);
        }
    }

    cout << dp[h] << endl;
}

Measured memory_bytes: 384
while 1:
	H = int(raw_input())
	if H == 0:
		break
	Board = [[0 for j in range(H+1)] for i in range(6)]
	for j in range(H):
		inputs = map(int,raw_input().split(" "))
		for i in range(5):
			Board[i][H-j] = inputs[i]
	total_score = 0
	tmp_score = -1
	while tmp_score != 0:
		tmp_score = 0
		tmpBoard = [[0] for i in range(6)]
		for j in range(1,H+1):
			con_num = 1
			for i in range(1,6):
				if Board[i][j] == Board[i-1][j]:
					con_num += 1
				else :
					if con_num >= 3:
						tmp_score += con_num * Board[i-1][j]
					else :
						for h in range(con_num):
							tmpBoard[i-1-h].append(Board[i-1-h][j])
							tmpBoard[i-1-h][0] += 1
					con_num = 1
		total_score += tmp_score
		Board = [line + [0 for j in range(H-line[0])] for line in tmpBoard]
	print total_score
	

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

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

ll gcd(ll a, ll b) {
  if (a < b) {
    swap(a, b);
  }
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vl a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll g = a[0];
  for (int i = 1; i < n; i++) {
    g = gcd(a[i], g);
  }
  cout << g << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int n, k;
vi v;
ll ans = 9999999999999;

void rec(int m, int l, ll cost, int top) {
	if (m == n) {
		if (l >= k) {
			ans = min(ans, cost);
			//cout << cost << endl;
		}
	}
	else {
		if (top >= v[m]) rec(m + 1, l, cost, top);
		rec(m + 1, l + 1, cost + max(top + 1, v[m]) - v[m], max(top + 1, v[m]));
	}
}

int main() {
	cin >> n >> k;
	int in;
	rep(i, n) {
		cin >> in;
		v.push_back(in);
	}
	rec(1, 1, 0, v[0]);
	cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
ans = sum(sum(a * b for a, b in zip(A[i], B)) + C > 0 for i in range(N))
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{ll to,cost;};
const int inf = 1<<27;
const ll INF = 1LL<<60;
const int COMBMAX = 1001001;
const ll MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n, ll mod = MOD){ll res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
void print(){cout << endl;}
template<class Head, class... Tail> void print(Head&& head, Tail&&... tail){cout << head << " "; print(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}


int main(){
    string s; cin >> s;
    ll n = s.size();
    if (n == 2){
        if (s[0] == s[1]){
            print(1, 2);
            return 0;
        }
    }else{
        rep(i, n - 2){
            if(s[i] == s[i + 1] || s[i] == s[i + 2]){
                print(i + 1, i + 3);
                return 0;
            }
        }
    }
    print(-1, -1);
    return 0;
}

Measured memory_bytes: 512
N, M = map(int, input().split())
ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(M)]
 
 
class UnionFind:
    def __init__(self,size):
        self.rank = [-1 for _ in range(size)]
        self.number = [1 for _ in range(size)]
 
    def find(self,x):
        while self.rank[x] >= 0:
            x = self.rank[x]
        return x
 
    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 == s2:
            return
        if self.rank[s1] == self.rank[s2]:
            self.rank[s1] -= 1
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        elif self.rank[s1] < self.rank[s2]:
            self.rank[s2] = s1
            self.number[s1] += self.number[s2]
        else:
            self.rank[s1] = s2
            self.number[s2] += self.number[s1]
 
 
def main():
    uf = UnionFind(N)
    p = N * (N - 1) // 2
    ans = [p]
    for x, y in reversed(ab):
        px = uf.find(x)
        py = uf.find(y)
        if px != py:
            p -= uf.number[px] * uf.number[py]
            uf.union(px, py)
        ans.append(p)
 
    for a in reversed(ans[:-1]):
        print(a)
 
 
main()


Measured memory_bytes: 24072
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";

    int H, W, N;
    int[] A;
    void Solve()
    {
        H = cin.Nextint;
        W = cin.Nextint;
        N = cin.Nextint;
        A = cin.Scanint;
        var B = Enumerable.Range(1, N).ToArray();
        Array.Sort(A, B);
        

        int y = 0;
        int x = 0;

        int dir = 1;
        var C = new int[H, W];
        for (int i = 0; i < N; i++)
        {
            int k = N - i - 1;
            while (A[k] > 0)
            {
                //WriteLine(x);
                C[y, x] = B[k];
                x += dir;
                if (x < 0 || x >= W)
                {
                    x -= dir;
                    dir *= -1;
                    y++;
                }
               
                A[k]--;
            }
        }
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (j != 0) Write(" ");
                Write(C[i, j]);
            }
            WriteLine();
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 13660
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define RETURN exit(0)
#define pow(x,y) (int)(pow(x,y))
#define ceil(x) (int)(ceil(x))
#define sqrt(x) (int)(sqrt(x))
#ifndef ONLINE_JUDGE
#define debug(x) cout<<x<<endl;
#else
#define debug(x) 42
#endif
const int MAX=1e4;
const int MOD=1e9+7;
const int MAAX=1e12;
const long double EPS=1e-6;
const int N=1e6+10;
int power(int x,int y)
{
    if (y == 0)
        return 1;
    int a=power(x,y/2);
    if (y % 2 == 0)
        return a * a % MOD;
    else
        return x * a * a % MOD;
}
bool check(int x){

}
int binary(int x,int y){
    int s=x,e=y,mid;
    while(s<e){
        mid=ceil((s+e)/2.0);
        if(check(mid))
            s=mid;
        else
            e=mid-1;
    }
    return s;
}
vector<int> primes;
bool visted[N+5];
void sieve(){
    for(int i=2;i*i<=N;i++){
        if(visted[i]==0){
            for(int j=i*i;j<=N;j+=i){
                visted[j]=1;
            }
        }
    }
    /*for(int i=sqrt(N)+1;i<=N;i++){
        if(visted[i]==0)
            primes.pb(i);
    }*/
    return;
}
vector<int> fact(int x){
    vector<int> ans;
    int idx=0;
    bool bol=0;
    while(x>=primes[idx]){
        if(x%primes[idx]==0){
            x/=primes[idx];
            if(!bol){
                bol=1;
                ans.pb(primes[idx]);
            }
        }
        else{
            bol=0;
            idx++;
        }
    }
    return ans;
}
int gcd(int a,int b){
    if(a==0)
       return b;
    if(b==0)
       return a;
    if(a==b)
        return a;
    if(a>b)
        return gcd(a-b,b);
    return gcd(a,b-a);
}
bool prime(int x){
    for(int i=2;i*i<=x;i++){
        if(x%i==0)
            return 0;
    }
    return 1;
}

in main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    int tc=1;
    //scanf("%lld",&tc);
    //sieve();
    while(tc--)
    {
        int a,b;
        cin>>a>>b;
        int z=0;
        if(a>b)
            swap(a,b);
        for(int i=1;i*i<=a;i++){
            if(a%i==0&&b%i==0&&prime(i)){
                z++;
            }
            if(a%i==0&&a/i!=i&&b%(a/i)==0&&prime(a/i))
                    z++;
        }
        cout<<z<<endl;
    }
    ///matensa4 tegarab el sample w te7ot el freopen w te3mel SCANF
    RETURN;
}


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

struct Node
{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;
void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL)
	{
		y = x;
		if (z->key < x->key)
		{
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}
	z->parent = y;
	if (y == NIL)
	{
		root = z;
		}	
		else if (z->key < y->key)
		{
		y->left = z;
		}
	else
	{
		y->right = z;
	}
}

void inorder(Node *u) {
	if (u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u) {
	if (u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, i, x;
	string com;
	scanf("%d", &n);

	for ( i = 0; i < n; i++)
	{
		cin >> com;
		if (com == "insert")
		{
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "print")
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 26704
import java.util.*;

class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    int fiveCoins = sc.nextInt();
    int n = sc.nextInt();
    
    if (500 * fiveCoins >= n) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
import math
a,b, h, m = input().split()

PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647

a = int(a)
b = int(b)
h = int(h)
m = int(m)

angleA = 0.5*h*60 + 0.5*m;
angleB = 6*m;
angle = abs(angleA-angleB);

angle = math.radians(angle)

coss = math.cos(angle)*2*a*b;

result = math.sqrt(a*a + b*b -coss);

print(result)

Measured memory_bytes: 9452
#include <iostream>
#include <cmath> 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	int n;
	scanf("%d",&n); 
	int x = pow(n,3);
	printf("%d",x);
	
	return 0;
}

Measured memory_bytes: 384
import java.io.*;
import java.io.IOException;
import java.util.*;

@SuppressWarnings({"rawtypes", "unchecked"})
class Main {
    final static int INF = 1 << 28;
    final static long LNF = 1L << 60;
    final static double EPS = 1e-9;
    final static double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

    static final long MOD = 1_000_000_007;
    static final String YES = "Yes";
    static final String NO = "No";

    public static void main(String[] args) throws Exception {
        final MyScanner sc = new MyScanner();
        String S;
        S = sc.next();
        solve(S);
    }

    static void solve(String S){
        char[] c = S.toCharArray();
        if (c[2] == c[3] && c[4] == c[5]) System.out.println("Yes");
        else System.out.println("No");
    }


    static class MyScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }
 
        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String next() {
            return nn();
        }

        String nextLine() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }
 
        char nextChar() {
            return nn().charAt(0);
        }
 
        int nextInt() {
            return Integer.parseInt(nn());
        }
 
        long nextLong() {
            return Long.parseLong(nn());
        }
 
        double nextDouble() {
            return Double.parseDouble(nn());
        }
 
        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
 
        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
    }

}


Measured memory_bytes: 22996
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main()
{
  cin.tie(0);
  int n;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << endl;
  } else {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
}

Measured memory_bytes: 256
l = [tuple(map(int, input().split())) for _ in range(3)]
used = [[False]*3 for _ in range(3)]

N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if l[i][j]==b:
                used[i][j]=True

def check():
    if used[0][0] and used[1][1] and used[2][2]:
        return True
    if used[0][2] and used[1][1] and used[2][0]:
        return True
    for i in range(3):
        if used[i][0] and used[i][1] and used[i][2]:
            return True
        if used[0][i] and used[1][i] and used[2][i]:
            return True

print("Yes" if check() else "No")

Measured memory_bytes: 3064
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    V<int> aaa = {500};
    for (int i = 0; i < n; i++) {
        if (i == 0 || a[i - 1] != a[i]) aaa.emplace_back(a[i]);  
    }

    n = aaa.size();
    ll ans = 1000;
    ll tmp = 0;
    ll kabu = 0;
    // DEBUG_VLL(aaa)
    for (int i = 1; i < n - 1; i++) {
        if (aaa[i - 1] < aaa[i] && aaa[i] < aaa[i + 1]) continue;
        if (aaa[i - 1] > aaa[i] && aaa[i] > aaa[i + 1]) continue;
        if (aaa[i - 1] > aaa[i] && aaa[i] < aaa[i + 1]) {
            kabu = ans / aaa[i];
            tmp = ans - kabu * aaa[i];
        } else if (aaa[i - 1] < aaa[i] && aaa[i] > aaa[i + 1]) {
            ans = tmp + kabu * aaa[i];
        }
    }
    if (aaa[n - 2] < aaa[n - 1]) ans = tmp + kabu * aaa.back();
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3616
#include"bits/stdc++.h"
using namespace std;

void Main() {
	int n = 0;
	cin >> n;
	int A[100];
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
cout << A[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		cout << " " << A[i];
	}
	cout << endl;
}

int main() {
	std::cout << std::fixed << std::setprecision(15);
	Main();
}




Measured memory_bytes: 3096
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	char a[22];
	while(scanf("%c",&a[0])!=-1)
	{
		for(int i=1;i<=19;i++)
			scanf("%c",&a[i]);
		for(int n=0;n<=4;n++)
			printf("%c",a[n]);
		printf(" ");
		for(int m=6;m<=12;m++)
			printf("%c",a[m]);
		printf(" ");
		for(int b=14;b<=18;b++)
			printf("%c",a[b]);
		printf("\n");
	}
	return 0;
}

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

#define int long long
#define double long double

const int INF=2147483647;
const int MOD=1000000007;
const int mod=998244353;
const double eps=1e-18;

using namespace std;

int h,w;
int l[200001],r[200001];

struct ST{

    int sl,sr;
    int Max,Min;
    int ans;

};

ST st[800001];

void build(int cidx,int cl,int cr){

    st[cidx].sl=cl;
    st[cidx].sr=cr;

    if( cl==cr ){
        st[cidx].Max=cl;
        st[cidx].Min=cr;
        st[cidx].ans=st[cidx].Max-cr;
        return;
    }

    int mid=(cl+cr)/2;
    build(cidx*2,cl,mid);
    build(cidx*2+1,mid+1,cr);

    st[cidx].Max=max( st[cidx*2].Max , st[cidx*2+1].Max );
    st[cidx].Min=min( st[cidx*2].Min , st[cidx*2+1].Min );
    st[cidx].ans=min( st[cidx*2].ans , st[cidx*2+1].ans );

}

void modify(int cidx,int target,int data){

    int cl=st[cidx].sl;
    int cr=st[cidx].sr;

    if(cl==cr){

        if( st[cidx].Max>=target ){
            st[cidx].Max=max( st[cidx].Max , data );
            st[cidx].Min=max( st[cidx].Min , data );
        }
        st[cidx].ans=st[cidx].Max-cr;
        if(st[cidx].Min==w){
            st[cidx].ans=INF;
        }
        return;
    }

    if( st[cidx].Min >= data or st[cidx].Max < target ){  /// does not need to be modified
        return;
    }

    if( st[cidx].Min >= target and st[cidx].Max < data ){ /// the whole segment needs to be modified

        st[cidx].Max=data;
        st[cidx].Min=data;
        st[cidx].ans=data-cr;
        if(st[cidx].Min==w){
            st[cidx].ans=INF;
        }
        return;

    }

    modify( cidx*2 , target , data ); /// otherwise
    modify( cidx*2+1 , target , data );

    st[cidx].Max=max( st[cidx*2].Max , st[cidx*2+1].Max ); /// update data
    st[cidx].Min=min( st[cidx*2].Min , st[cidx*2+1].Min );
    st[cidx].ans=min( st[cidx*2].ans , st[cidx*2+1].ans );
    if(st[cidx].Min==w){
        st[cidx].ans=INF;
    }

}

int query(){ /// query : min{ ans[i] }

    return st[1].ans;

}

signed main(){

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

    int res;

    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>l[i]>>r[i];
        l[i]--;
        r[i]--;
    }

    build(1,0,w-1);

    for(int i=0;i<h;i++){
        modify(1,l[i],r[i]+1);
        res=query();
        if(res==INF){
            cout<<-1<<endl;
        }
        else{
            cout<<res+i+1<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 27272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n)  for(ll i = 0; i < (n); ++i)
#define rep1(i,n)  for(ll i = 1;i <= (n); ++i)
#define pb push_back
#define M 1000000007
unordered_map<ll,ll>mp;

int main()
{
    fastIO
	ll n,x,t;
  cin>>n>>x>>t;
  ll q=n/x;
  if(n%x>0)
    q++;
  cout<<q*t;
	return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	if(n%2)
		printf("%d",(n/2)*(n/2+1));
	else
		printf("%d",(n/2)*(n/2));
	return 0;	
}

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

int n, m;
vector<int> d;

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

    for (int i = 1; i * i <= m; i++) {
        if (m % i == 0) {
            d.push_back(i);
            if (i * i == m) break;
            d.push_back(m / i);
        }
    }

    sort(d.begin(), d.end());
    vector<int>::iterator it = lower_bound(d.begin(), d.end(), m / n);
    if (m % n != 0 && m / n != *it) it--;
    int ans = *it;
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

int main(){
  int n,k;
  long int h[100002];
  long int ans=1000000001;
  cin >> n >> k;
  for(int i=0;i!=n;i++){
    cin >> h[i];
  }
  sort(h,h+n);
  for(int i=0;i!=n-k+1;i++){
    ans=min(ans,h[i+k-1]-h[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main() {
	int n, m; scanf("%d %d", &n, &m);
	vector<vector<int>> graph(n), rev(n);
	for (int i = 0; i < m; ++i) {
		int x, y; scanf("%d %d", &x, &y);
		graph[--x].push_back(--y);
		rev[y].push_back(x);
	}
	vector<int> indeg(n);
	queue<int> q;
	for (int i = 0; i < n; ++i) {
		indeg[i] = rev[i].size();
		if (indeg[i] == 0) q.push(i);
	}
	vector<int> topo;
	topo.reserve(n);
	while (!q.empty()) {
		int c = q.front(); q.pop();
		topo.push_back(c);
		for (int next : graph[c]) {
			--indeg[next];
			if (indeg[next] == 0) q.push(next);
		}
	}
	vector<int> longest(n);
	for (int x : topo) for (int pd : rev[x]) longest[x] = max(longest[x], longest[pd] + 1);
	printf("%d\n", *max_element(longest.begin(), longest.end()));
	return 0;
}

Measured memory_bytes: 12288
import java.util.*

fun <T> permutationList(sortedList: List<T>): List<List<T>> {
    val queue = ArrayDeque<List<T>>()
    queue.addLast(arrayListOf())
    val permutations = mutableListOf<List<T>>()
    while (queue.isNotEmpty()) {
        val p = queue.removeLast()

        if (p.size == sortedList.size) {
            permutations.add(p)
            continue
        }

        for (item in (sortedList - p)) {
            queue.addLast(p + item)
        }
    }

    return permutations
}

fun main(args: Array<String>) {
    val n = readInteger()
    val p = readIntegerList()
    val q = readIntegerList()

    val per = permutationList((1..n).toList())
    Math.abs(per.indexOf(p) - per.indexOf(q)).let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


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

int main(){
   int n,a[105],sum=0;
   cin>>n;
   int mi=105,mx=-1;
   for(int i=0;i<n;i++){
    cin>>a[i];
    mx=max(mx,a[i]);
    mi=min(mi,a[i]);}
   //sort(a,a+n);
  // int mid;
   //if(n%2==1) mid=a[n/2];
  // else mid=(a[n/2-1]+a[n/2])/2;
  int ans=1e9;
  for(int j=mi;j<=mx;j++){
        int sum=0;
   for(int i=0;i<n;i++)
    sum+=(a[i]-j)*(a[i]-j);
  ans=min(ans,sum);
  }
   cout<<ans;
    return 0;
}


Measured memory_bytes: 256