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

int main() {
  char buf[20];
  int d[9];
  int j[8][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}};
  bool draw;
  while (fgets(buf, sizeof(buf), stdin)) {
    for (int i=0; i<9; i++) {
      if (buf[i]=='o') d[i]=2;
      else if (buf[i]=='x') d[i]=1;
      else d[i]=0;
    }
    draw = true;
    for (int i=0; i<8; i++) {
      if (d[j[i][0]]==d[j[i][1]] && d[j[i][0]]==d[j[i][2]]) {
        if (d[j[i][0]]==2) {
          draw = false;
          printf("o\n");
          break;
        } else if (d[j[i][0]]==1) {
          draw = false;
          printf("x\n");
          break;
        }
      }
    }
    if (draw) {
      printf("d\n");
    }
  }
  return 0;
}

Measured memory_bytes: 920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 2019;
const ll INF = INT64_MAX;


ll i,j,k;

ll ruijou(long long x, long long y){
    if(y==0) return 1;
    else if(y%2==0) return ruijou(x*x%mod,y/2);
    else return x*ruijou(x,y-1)%mod;
}


int main(){
    string S;
    cin>>S;
    ll N=S.length();
    
    ll ruiseki[N];
    map<int,int> ans;
    ll realans=0;

    rep(i,N){
        if(i==0){
            int c=S[N-1]-'0';
            ruiseki[i]=c;

        }
        else{
            int c=S[N-1-i]-'0';
            c=c*ruijou(10,i);
            c%=mod;
            ruiseki[i]=(ruiseki[i-1]+c)%mod;
        }
    }
    rep(i,N){
        if(ruiseki[i]==0)realans++;
    }
    rep(i,N){
        if(ans.count(ruiseki[i]))ans[ruiseki[i]]++;
        else ans[ruiseki[i]]=1;
    }
    for(auto itr=ans.begin();itr!=ans.end();itr++){
        itr->second=itr->second*(itr->second-1)/2;
    }
    rep(i,N-3){
        if(ruiseki[i]==ruiseki[i+3])ans[ruiseki[i]]--;
    }
    for(auto itr=ans.begin();itr!=ans.end();itr++)if(itr->second>=1)realans+=itr->second;
    cout<<realans<<endl;
    
}


Measured memory_bytes: 5240
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    A, B = map(int, input().split())

    ans = 0
    for i in range(2):
        if A > B:
            ans += A
            A -= 1
        else:
            ans += B
            B -= 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	
	string s;
	cin>>N;
	cin>>s;
	
	int con = 0, con2 = 0;
	for(int i =0; i < N; i++){
		if(s[i] == 'R') con++;
		else con2++;
	}
	
	cout<<yn(con>con2)<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    let mut line = String::new();
    stdin().read_line(&mut line).expect("Failed to read line");
    let n: u32  = line.trim().parse().expect("Failed to parse i32");
    let mut line = String::new();
    stdin().read_line(&mut line).expect("Failed to read line");
    let a: Vec<u32> = line.trim().split_whitespace()
        .map(|s| s.parse().expect("Failed to parse")).collect();
    let ans: u32 = a.iter().map(|x| x-1).sum();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <climits>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <type_traits>
#include <utility>
#include <vector>

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 n, k;
	std::cin >> n >> k;
	std::vector<uint32> a(n);
	uint32 c[200001] = {};
	uint32 co = 0;
	for (uint32 i = 0;i < n;++i) {
		std::cin >> a[i];
		if (!c[a[i]]) {
			++co;
		}
		++c[a[i]];
	}
	if (co <= k) {
		std::cout << "0\n";
		return 0;
	}
	std::sort(c, c + 200001, std::greater<uint32>());
	co = 0;
	for (uint32 i = 0;i < k;++i) {
		co += c[i];
	}
	std::cout << n - co << "\n";
	return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<math.h>
int main() {
	double x1, x2, y1, y2, dist;
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	dist = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
	printf("%.8lf\n", dist);
	return 0;
}

Measured memory_bytes: 656
def ceil(x, y):
    if x % y == 0:
        return x // y
    else:
        return x // y + 1

n = int(input())
t = a = 1
for i in range(n):
    T, A = map(int, input().split())
    n = max(ceil(t, T), ceil(a, A))
    t = n * T
    a = n * A
print(t + a)

Measured memory_bytes: 3060
n = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(1, n - 1) :
  if(P[i - 1] < P[i] and P[i] < P[i + 1]) :
    cnt += 1
  elif(P[i + 1] < P[i] and P[i] < P[i - 1]) :
    cnt += 1
  else :
    pass
print(cnt)

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

/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)

/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define MP make_pair 

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/* func */
int gcd(int a,int b){return b?gcd(b,a%b):a;}

/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

//#define int ll
//#define int long long

signed main()
{
  int n; cin >> n;
  vi v1(0);
  int a;
  
  REP(i, n){
    cin >> a;
    v1.PB(a);
  }
  
  int max = *max_element(ALL(v1));
  int min = *min_element(ALL(v1));
  
  cout << max - min; 
  
  REP(i, n)
  return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = []
    for i, v in enumerate(a):
        b.append(v - (i + 1))
    b.sort()
    t = b[len(b) // 2]
    s = 0
    for i, v in enumerate(a):
        s += abs(v - (t + (i + 1)))
    print(s)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 92368
import java.util.Scanner;

public class Main {

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

		int answer = 10 - x / 200;

		print(answer);
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}
}


Measured memory_bytes: 35684
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<unordered_map>
#include<stack>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<complex>
#include<bitset>
#include<iostream>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

class Bit {
  ll n, bit[20000];
public:
  void init(ll _n) {
    n = _n;
  }
  void add(ll a, ll w) {
    for (ll x = a; x <= n; x += x & -x) bit[x] += w;
  }
  ll sum(ll a) {
    ll ans = 0;
    for (ll x = a; x > 0; x -= x & -x) ans += bit[x];
    return ans;
  }
};

ll n, a[4000], w[2000], b[2000], dp[2001][2001];
char c[4000][2];
Bit w_s, b_s;

ll sum(ll a, ll b) { return a + b; }

ll search(ll x, ll y) {
  if (dp[x][y] != -1) return dp[x][y];
  ll ans = INF, num;
  if (x > 0) {
    num = w[x-1]+1;
    w_s.add(num, 1);
    ans = min(ans, search(x-1, y) + w_s.sum(num-1) + b_s.sum(num-1));
    w_s.add(num, -1);
  }
  if (y > 0) {
    num = b[y-1]+1;
    b_s.add(num, 1);
    ans = min(ans, search(x, y-1) + w_s.sum(num-1) + b_s.sum(num-1));
    b_s.add(num, -1);
  }
  return dp[x][y] = ans;
}

int main() {
  scanf("%lld", &n);
  for (ll i = 0; i < 2*n; i++) {
    scanf("%s%lld", c[i], &a[i]), a[i]--;
    if (c[i][0] == 'W') w[a[i]] = i;
    else b[a[i]] = i;
  }
  for (ll i = 0; i <= n; i++) for (ll j = 0; j <= n; j++) dp[i][j] = -1;
  dp[0][0] = 0;
  w_s.init(2*n); b_s.init(2*n);
  printf("%lld\n", search(n, n));
}


Measured memory_bytes: 31872
while True:
    m,f,r = map(int, raw_input().split())
    s = m + f
    if m == -1 and f == -1 and r == -1: break
    elif m == -1 or f == -1 or s < 30: g=5
    elif 30 <= s and s < 50:
        if r >= 50: g=2
        else: g=3
    elif 50 <= s and s < 65: g=2
    elif 65 <= s and s < 80: g=1
    else: g=0
    print 'ABCDEF'[g]


Measured memory_bytes: 4644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int W, H, N;
    cin >> W >> H >> N;

    int w = 0, h = 0;
    rep(i, N) {
	int x, y, a;
	cin >> x >> y >> a;

	if (a == 1) w = max(w, x);
	else if (a == 2) W = min(W, x);
	else if (a == 3) h = max(h, y);
	else if (a == 4) H = min(H, y);
    }

    cout << max(0LL, (W - w)) * max(0LL, (H - h)) << endl;

    return 0;
}


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

template <typename T>
class func_sum
{
private:
    std::vector<std::vector<T>> sum_table;
protected:
    virtual T acc_sum(int i, int j);
public:
    func_sum(std::function<T(int, int)> func, int nx, int ny) ;
    ~func_sum();

    T calc_section_sum(int il, int ir, int jl, int jr);
};

template <typename T>
T func_sum<T>::acc_sum(int i, int j) {
    return sum_table[i][j];
};

template <typename T>
func_sum<T>::func_sum(std::function<T(int, int)> func, int nx, int ny) {
    sum_table = std::vector<std::vector<T>>(ny + 1, std::vector<T>(nx + 1, T()));
    for (int i = 1; i <= nx; i++) {
        sum_table[i][0] += func(i - 1, 0);
    }
    for (int j = 1; j <= ny; j++) {
        sum_table[0][j] += func(0, j - 1);
    }
    for (int i = 1; i <= nx; i++) {
        for (int j = 1; j <= ny; j++) {
            sum_table[i][j] += func(i - 1, j - 1) +
                sum_table[i - 1][j] +
                sum_table[i][j - 1] -
                sum_table[i - 1][j - 1];

        }
    }
}

template <typename T>
func_sum<T>::~func_sum(){}

template <typename T>
T func_sum<T>::calc_section_sum(int il, int ir, int jl, int jr) {
    return acc_sum(ir, jr) - 
           acc_sum(ir, jl - 1) - 
           acc_sum(il - 1, jr) + 
           acc_sum(il - 1, jl - 1);
}



int main()
{
    int N, M, Q;
    std::cin >> N >> M >> Q;
    std::vector<std::vector<int>> table(N, std::vector<int>(N, 0));
    for (int i = 0; i < M; i++) {
        int L, R;
        std::cin >> L >> R;
        table[L - 1][R - 1]++;
    }

    auto func = [](int i, int j,
        const std::vector<std::vector<int>>& table) { return table[i][j]; };

    std::function<int(int, int)>  func_curried = std::bind(func,
        std::placeholders::_1,
        std::placeholders::_2,
        table);

    func_sum<int> ds(func_curried, N, N);

    for (int i = 0; i < Q; i++) {
        int p, q;
        std::cin >> p >> q;
        std::cout << ds.calc_section_sum(p, q, p, q) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 6784
eval'A,B,*C=#'+`tr ' ' ,`;z=x=0;C.map{x^=_1};999.times{45.downto(0){|i|x[i]!=(A^B)[i]&&(z+=t=[A[0,i]+1,2**i-B[0,i]].min;A-=t;B+=t)}};p A>0?z:-1

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  vector<int> b(n + 1);
  for (int i = 1; i <= n; i ++) {
    cin >> a.at(i);
    b.at(i) = a.at(i);
  }

  sort(a.begin(), a.end());
  int x = a.at(n / 2 + 1), y = a.at(n / 2);
  for (int i = 1; i <= n; i ++) {
    if (b.at(i) <= y) cout << x << endl;
    else cout << y << endl;
  }
}


Measured memory_bytes: 3712
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	A, B, C, K := nextInt(), nextInt(), nextInt(), nextInt()
	var ans int
	// fmt.Println(K)
	if A > K {
		fmt.Println(K)
		return
	}
	ans += A
	K -= A
	// fmt.Println(K)
	K -= B
	// fmt.Println(K)
	if K <= 0 {
		fmt.Println(ans)
		return
	}
	if K > 0 {
		if K > C {
			ans -= C
		} else {
			ans -= K
		}
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(){
	int a,b,c;
	int r=0,l=0;
	while(~scanf("%d,%d,%d",&a,&b,&c)){
		if(a*a+b*b==c*c)r++;
		if(a==b)l++;}
	printf("%d\n%d\n",r,l);
	return 0;}


Measured memory_bytes: 2596
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;
using ll=long long;

int main()
{
    int A, B, C;
    
    cin >> A >> B >> C;
    
    bool isOkay = false;
    if (C >= A && C <= B)
    {
        isOkay = true;
    }
    
    printf("%s\n", isOkay ? "Yes" : "No");
    
    return 0;
}


Measured memory_bytes: 256
A, B, K = map(int,input().split())

if (B-A+1) > 2*K:
    for i in range(K):
        print(A+i)
    for j in range(K):
        print(B-K+1+j)
else:
    for m in range(B-A+1):
        print(A+m)

Measured memory_bytes: 3060
min_x = 123
max_x = 0

for _ in range(5):
    x = int(input())
    if x <= min_x:
        min_x = x
    if x >= max_x:
        max_x = x

k = int(input())
if k < max_x-min_x:
    print(":(")
else:
    print("Yay!")

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int n;

vector<int> res;
vector<vector<pair<int, int> > > g;
void dfs(int s, int color, int p) {
    int cnt = 1;
    rep (i, g[s].size()) {
        int next, id;
        next = g[s][i].first, id = g[s][i].second;
        if (next == p) continue;
        if (color == cnt) cnt++;
        res[id] = cnt; cnt++;
        dfs(next, cnt - 1, s);
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    cin >> n;
    g.resize(n);
    res.resize(n - 1);
    rep (i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(make_pair(b, i));
        g[b].push_back(make_pair(a, i));
    }
    dfs(0, Inf, Inf);
    int cnt = 0;
    rep (i, n) cnt = max(cnt, (int)g[i].size());
    cout << cnt << endl;
    rep (i, n - 1) cout << res[i] << endl;
    
    return 0;
}



Measured memory_bytes: 8320
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

char g[505][505];
char b[505];

int main()
{
	int h, w;
	cin >> h >> w;
	rep(i,0,h) rep(j,0,w) cin >> g[i][j];
	
	rep(i,0,h) {
		rep(j,0,w) {
			if ((j==0 || i%2==0 || g[i][j]=='#') && j!=w-1) b[j] = '#';
			else b[j] = '.';
		}
		b[w] = '\0';
		cout << b << endl;
	}
	cout << endl;
	rep(i,0,h) {
		rep(j,0,w) {
			if ((j==w-1 || i%2==1 || g[i][j]=='#') && j!=0) b[j] = '#';
			else b[j] = '.';
		}
		b[w] = '\0';
		cout << b << endl;
	}

	return 0;
}

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

long int CalcCount(const long int *hp) {
  if (*hp == 1) {
    return 1;
  } else {
    long int hp_tmp = *hp/2;
    return 2*CalcCount(&hp_tmp)+1;
  }
}

int main() {
  // 入力
  long int H;
  cin >> H;

  long int count = 0;
  long int hp = H;

  count = CalcCount(&hp);
  
  // 出力
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
n,m,l=map(int,input().split())
mat = [ list(map(int,input().split())) for _ in range(0,n) ]
mat2 = [ list(map(int,input().split())) for _ in range(0,m) ]
mat3 = [ [ 0 for _ in range(0,l) ] for _ in range(0,n) ]
for i in range(0,n):
    for j in range(0,m):
        for k in range(0,l):
            mat3[i][k] += mat[i][j] * mat2[j][k];
for xs in mat3:
    print(' '.join(map(str, xs)))

Measured memory_bytes: 9036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 1234567890;

int D;
int x[100000];

const int B = 200;
const int SZ = 500;

// default,sorted
vector<int> d[B],s[B];

int f(int l, int r, int p, int q)
{
    int ret = r-l+1;
    for(int i=l; i<=r; ++i)if(p<=x[i] && x[i]<=q) --ret;
    return ret;
}

int g(int bid, int p, int q)
{
    int lidx = lower_bound(all(s[bid]), p) - s[bid].begin();
    int ridx = upper_bound(all(s[bid]), q) - s[bid].begin();
    int ct = ridx - lidx;
    return SZ - ct;
}

int query(int l, int r, int e)
{
    int a = min(x[l],x[r]), b = max(x[l],x[r]);
    int lb = l/SZ, rb = r/SZ;
    int ret = 0;
    if(lb==rb) ret += f(l,r,a-e,b+e);
    else
    {
        ret += f(l,SZ*(lb+1)-1,a-e,b+e);
        for(int i=lb+1; i<rb; ++i) ret += g(i,a-e,b+e);
        ret += f(SZ*rb,r,a-e,b+e);
    }
    return ret;
}

int main()
{
    scanf(" %d", &D);
    rep(i,D) scanf(" %d", &x[i]);

    rep(i,B)
    {
        d[i] = vector<int>(SZ,INF);
        rep(j,SZ)
        {
            int id = i*SZ+j;
            if(id<D) d[i][j] = x[id];
        }

        s[i] = d[i];
        sort(all(s[i]));
    }

    int Q;
    scanf(" %d", &Q);
    while(Q--)
    {
        int l,r,e;
        scanf(" %d %d %d", &l, &r, &e);
        --l; --r;
        printf("%d\n", query(l,r,e));
    }
    return 0;
}

Measured memory_bytes: 4212
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	string s, t;
	cin>>s>>t;
	int a, b;
	cin>>a>>b;
	string u;
	cin>>u;
	if(s==u){
		cout<<a-1<<" "<<b<<endl;
	}
	else{
		cout<<a<<" "<<b-1<<endl;
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<double> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  double sum = 0;
  for (int i = 0; i < N; i++) sum += 1/A.at(i);
  cout << 1/sum << endl;
}

Measured memory_bytes: 3704
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int m=sc.nextInt();
		int f=sc.nextInt();
		int r=sc.nextInt();
		int g=m+f;
		String out;
		while(m!=-1 || f!=-1 || r !=-1){
			if(m==-1 || f==-1){
				out="F";
			}else if(g>=80){
				out="A";
			}else if(g>=65){
				out="B";
			}else if(g>=50){
				out="C";
			}else if(g>=30){
				if(r>=50){
					out="C";
				}else out="D";
			}else{ 
				out="F";
			}//if
		System.out.println(out);
		m=sc.nextInt();
		f=sc.nextInt();
		r=sc.nextInt();
		g=m+f;
		}//while
		
	}
}

Measured memory_bytes: 19096
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		int n, m;
		int[] t, h;
		int tt, th;
		int tans, hans;
		while (true) {
			n = sc.nextInt();
			m = sc.nextInt();
			if (n == 0 && m == 0) break;
			t = new int[n];
			h = new int[m];
			tt = th = 0;
			for (int i = 0; i < n; i++) {
				t[i] = sc.nextInt();
				tt += t[i];
			}
			for (int i = 0; i < m; i++) {
				h[i] = sc.nextInt();
				th += h[i];
			}
			
			Arrays.sort(t);
			Arrays.sort(h);
			
			tans = hans = -1;
			int d = tt - th;
			if (d % 2 == 0) {
				I:for (int i = 0; i < n; i++) {
					for (int j = 0; j < m; j++) {
						if (t[i] - h[j] == d/2) {
							tans = t[i];
							hans = h[j];
							break I;
						}
					}
				}
			}
			
			if (tans < 0)
				out.println(-1);
			else 
				out.printf("%d %d\n", tans, hans);
			
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 21056
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        exit()
    mul = A[0]
    for v in A[1:]:
        mul *= v
        if mul > 10**18:
            print(-1)
            exit()
    print(mul)





if __name__ == '__main__':
    solve()


Measured memory_bytes: 21640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>
#include <math.h>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  string s, t;
  int n;
  cin >> n;
  long long ans = 0;
  vector<long long> nums(n);
  for (int i=0; i<n; ++i) {
    cin >> nums[i];
    if(nums[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ans += nums[0];
  for (int i=1; i<n; ++i) {
    long long origin = ans;
    if (ans > (1000000000000000000 / nums[i]) ) {
      cout << -1 << endl;
      return 0;
    } else {
      ans *= nums[i];
    }
  }

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

Measured memory_bytes: 4056
#include <stdio.h>
#include <iostream>

using namespace std;

void selectprint(int A[], int N, int replace)
{
	for (int i = 0; i < N; i++)
	{
		if (i > 0)
		{
			printf(" ");
		}

		printf("%d", A[i]);
	}
	printf("\r\n");
	printf("%d", replace);
	printf("\r\n");
}

void bubbleSort(int A[], int N)
{
	int min;
	int replace = 0;


	for (int i = 0; i < N; i++)
	{
		min = i;
		for (int j = i; j < N; j++)
		{
			if (A[min] > A[j]) 
			{
				min = j;

			}
		}
		if (min != i) 
		{
			swap(A[min], A[i]);
			replace++;
		}
	}
	selectprint(A,N,replace);
}

int main()
{
	int N, A[100];

	scanf("%d", &N);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
	}
	bubbleSort(A, N);

	return 0;
}



Measured memory_bytes: 3208
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        int[] arr = new int[n];
        StringTokenizer st = new StringTokenizer(in.readLine());
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }
        Arrays.sort(arr);
        if (arr[n/2] == arr[n/2-1]) {
            System.out.println("0");
        } else {
            System.out.println(arr[n/2] - arr[n/2-1]);
        }
    }

}
/*


 */

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a == b){
    cout << 2 * a << endl;
    return 0;
  }
  cout << max(a, b) + max(a, b) - 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

int main(){

    ll N; cin >> N;

    cout << N*(N-1)/2 << endl;

}

Measured memory_bytes: 3556
#include<stdio.h>
#include<stdlib.h>

#define NIL -1

void maxHeapify( int );
void buildMaxHeap(void);
 
int m[5000000];
int n;

int main(){

  int i;

  scanf("%d",&n);

  for( i = 1; i <= n; i++)scanf("%d", &m[i]);

  buildMaxHeap();


  for( i = 1; i <= n; i++)
    printf(" %d",m[i]);
  printf("\n");

  return 0;
}

void maxHeapify( int i){

  int l, r;
  int largest;
  int tmp;
  l = i * 2;
  r = i * 2 + 1;

  if( l <= n && m[l] > m[i])
    largest = l;

  else
    largest = i;

  if(r <= n && m[r] > m[largest])
    largest = r;

  if(largest != i){
    tmp = m[i];
    m[i] = m[largest];
    m[largest] = tmp ;
    maxHeapify(largest);
  }
}

void buildMaxHeap(void){
  int j;
  for( j = n/2; j >= 1; j--)
    maxHeapify(j);
}

Measured memory_bytes: 2548
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 

// using namespace __gnu_pbds; 
using namespace std;

//macros
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define watch(x) cout << "debug : " << #x << " -> " << x << endl; 

//globals
ll const mod = 1e9+7;
ll const size_1d = 1e6 + 7;
ll const size_2d = 3*(1e3 + 7);

//functions
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;} 
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);} 

// CODE STARTS HERE
int dp[size_2d][size_2d];

int main() {
  IOS;

  string s1,s2;cin >> s1 >> s2;
  for (int i = 0; i < s1.length(); ++i)
  {
    if(s1[i] == s2[0])
      dp[i][0] = 1;
    else if(i != 0)
      dp[i][0] = dp[i-1][0];
  }
  for (int i = 0; i < s2.length(); ++i)
  {
    if(s2[i] == s1[0])
      dp[0][i] = 1;
    else if(i != 0)
      dp[0][i] = dp[0][i-1];
  }
  for (int i = 1; i < s1.length(); ++i)
  {
    for (int j = 1; j < s2.length(); ++j)
    {
      if(s1[i] == s2[j]){
        dp[i][j] = dp[i-1][j-1] + 1;
      }
      else{
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
    }
  }
  // cout << dp[s1.length()-1][s2.length()-1] << endl;
  int index = dp[s1.length()-1][s2.length()-1]; 
  if(index == 0)
    return cout << "" << endl,0;
  char lcs[index+1]; 
  lcs[index] = ' ';
  int i = s1.length()-1, j = s2.length()-1; 
  while (i >= 0 && j >= 0) 
  { 
    if (s1[i] == s2[j]) 
    { 
      lcs[index-1] = s1[i]; 
      i--; j--; index--;  
    } 
    else if(i == 0 && j != 0){
      j--;
    }
    else if(i != 0 && j == 0){
      i--;
    }
    else if(i == 0 && j == 0){
      break;
    }
    else if (dp[i-1][j] > dp[i][j-1]) 
      i--; 
    else
      j--; 
   } 
   int count = 1;
   for(auto &m : lcs)
   {
    if(count > dp[s1.length()-1][s2.length()-1])
      break;
    else
      cout << m;
    count++;
   }
  cout << endl;
   // cout << lcs << endl;
  // for (int i = 0; i < s1.length(); ++i)
  // {
  //   for (int j = 0; j < s2.length(); ++j)
  //   {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  return 0;
}

Measured memory_bytes: 35712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int a = sc.nextInt(), b = sc.nextInt();
		int es = eight(a)[0], eb = eight(a)[1], ts = ten(b)[0], tb = ten(b)[1];
		if((es >= ts && tb >= eb && tb >= es) || (es >= ts && eb >= tb && tb >= es)) {
			pw.print(es);
		}else if((ts >= es && eb >= tb && eb >= ts) || (ts >= es && tb >= eb && eb >= ts)) {
			pw.print(ts);
		}else {
			pw.print(-1);
		}
		pw.close();


	}

	static int[] eight(int n) {
		int eb = (int)Math.floor((n+0.99)/0.08);
		int es = (int)Math.ceil(n/0.08);
		int[] ei = {es, eb};
		return ei;
	}
	static int[] ten(int n) {
		int tb = (int)Math.floor((n+0.9)/0.1);
		int ts = (int)Math.ceil(n/0.1);
		int[] tn = {ts, tb};
		return tn;
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    lint a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+')
        cout << a + b << endl;
    else
        cout << a - b << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 200000;
const int MAX_M = 200000;

ll N, sum = 0;
vi a, ans;

int main() {
  cin >> N;
  a.pb(0);
  for (int i = 0; i < N; i++) {
    int tmp; cin >> tmp; a.pb(tmp);
  }
  a.pb(0);
  for (int i = 0; i < N+1; i++) {
    sum += abs(a[i]-a[i+1]);
  }
  for (int i = 1; i <= N; i++) {
    ans.pb(abs(a[i]-a[i-1])+abs(a[i]-a[i+1]) - abs(a[i+1]-a[i-1]));
  }

  for (int i = 0; i < N; i++) {
    cout << sum - ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 2932
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[m];
        int[] b = new int[m];
        for (int i = 0 ; i < m ; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        Set<Integer> aSet = new HashSet<>();
        List<Integer> bList = new ArrayList<>();
        for (int i = 0 ; i < m ; i++) {
            if (a[i] == 1) {
                aSet.add(b[i]);
            }
            if (b[i] == n) {
                bList.add(a[i]);
            }
        }
        int totalLength = aSet.size() + bList.size();
        aSet.addAll(bList);

        if (aSet.size() == totalLength) {
            System.out.println("IMPOSSIBLE");
        } else {
            System.out.println("POSSIBLE");
        }

    }

}

Measured memory_bytes: 102976
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;


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

  z = malloc(sizeof(struct 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);
}


Node find(Node u,int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }

  return u;
}

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,r;
    Node p;
    char com[20];
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
      scanf("%s", com);

      if ( com[0] == 'i' ){
        scanf("%d", &x);
        insert(x);
      } else if ( com[0] == 'p' ){
        inorder(root);
        printf("\n");
        preorder(root);
        printf("\n");
      }
      else if(com[0]='f'){
        scanf("%d",&r);
        Node p=find(root,r);
        if(p!=NIL) printf("yes\n");
        else printf("no\n");
      }
    }

    return 0;
  }



Measured memory_bytes: 20448
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int x, y;
    cin >> x >> y;
    int ans = 0;
    ans += abs(abs(x)-abs(y));
    bool xa = x > 0, ya = y > 0;
    if (x == 0) {
        if (y < 0) ans++; 
    }
    else if (xa != ya) ans++;
    else if (xa & ya) {
        if (abs(y) < abs(x)) ans += 2;
    }
    else if (abs(y) > abs(x)) {
        ans += 2;
    }

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

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{
  int n; cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i];

  bool flag = false;
  flag = is_sorted(begin(p), end(p));
  
  for (int i = 0; i < n; ++i) {
    if (flag) break;
    for (int j = i + 1; j < n; ++j) {
      swap(p[i], p[j]);
      flag = is_sorted(begin(p), end(p));
      swap(p[i], p[j]);
      if (flag) break;
    }
    if (flag) break;
  }

  if (flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n + 1];
		int total = 0;
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		    total += arr[i];
		}
		boolean[][][] dp = new boolean[n + 1][900][900];
		dp[0][0][0] = true;
		for (int i = 1; i <= n; i++) {
		    for (int j = 0; j < 900; j++) {
		        for (int k = 0; k < 900; k++) {
		            if ((j >= arr[i] && dp[i - 1][j - arr[i]][k]) ||
		                (k >= arr[i] && dp[i - 1][j][k - arr[i]]) || 
		                dp[i - 1][j][k]) {
		                dp[i][j][k] = true;
		            }
		        }
		    }
		}
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < 900; i++) {
		    for (int j = 0; j < 900; j++) {
		        if (!dp[n][i][j]) {
		            continue;
		        }
		        int max = Math.max(i, Math.max(j, total - i - j));
		        min = Math.min(min, max);
		    }
		}
		System.out.println(min);
	}
}



Measured memory_bytes: 91896
import Control.Monad (replicateM)
import Data.List (minimum, scanl', sort, sortBy)
import qualified Data.Vector.Unboxed as U

main :: IO ()
main = do
  [n,x] <- map read . words <$> getLine 
  as    <- map read . words <$> getLine
  print $ f n x as

f :: Int -> Int -> [Int] -> Int
f n x as
  | x < minas = 0
  | x <= sas  = U.length $ U.takeWhile (<= x) $ U.scanl1 (+) as'
  | x < 2*sas = U.length $ U.takeWhile (<= (2*sas - x)) $ U.scanl1 (+) sa
  | otherwise = 0
  where
    minas = U.minimum $ U.fromList as
    sas = sum as
    as' = U.fromList $ sort as
    sa  = U.fromList $ sortBy (flip compare) as

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0);\
cin.tie(0);\
cout.tie(0);
#define ll long long   
#define endl '\n'  
using namespace std;
const int N = 100+ 5;
int  n, m, k,r = 0, b = 0;
int main()
{
	IO
		cin >> n >> m >> k; 
	char  arr[N][N]; 
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> arr[i][j];
		}
		
		
	}
	int  way1 = (1 << n);
	int  way2 =  (1 << m);
	int  ans = 0; 

	for(int  mask = 0 ;mask < way1 ;mask++)
	{
		for (int mask2 = 0; mask2 < way2; mask2++)
		{
			int  cur = 0;
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < m; j++)
				{
					if (!(mask & (1 << i)) && !(mask2 & (1 << j)))
					{
						if(arr[i][j]!='.')
						cur++;
					}
				}
			}
			if (cur == k)
				ans++; 

		}
		
    }
	cout << ans << "\n"; 

}

Measured memory_bytes: 3624
import math 
def S(N):
    s = 0
    n = N
    while n != 0:
        s += n % 10
        n /= 10
        n = math.floor(n)
    return s


N = int(input())
S = S(N)
# print(N)
# print(S)
if N % S == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);

    int i=1;
    while(true){
      int a = scan.nextInt();
      if(a==0) break;

      System.out.println("Case "+i+": "+a);
      i++;
    }
  }
}



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

int n;
int A[100];

int saiki(int a, int b, int k){
	if(k==n){
		return abs(a-b);
	}else{
		return min(saiki(a+A[k], b, k+1), saiki(a, b+A[k], k+1));
	}
}

int main(){
	for(;;){
		scanf("%d", &n);
		if(n==0) break;
		for(int i=0; i<n; i++) cin >> A[i];
		cout << saiki(0, 0, 0) << endl;
	}

	return 0;
}

Measured memory_bytes: 1244
#include<stdio.h>
main(){
  int N,A[100],i;
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  int min=A[0],max=min;
  for(i=1;i<N;i++){
    if(min>A[i]) min=A[i];
    else if(max<A[i]) max=A[i];
  }
  printf("%d\n",max-min);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 1024;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int step[MAX];

void solve(void){
    int N, m;
    cin >> N >> m;
    //累積和を用いることでO(N)に計算量が落とせる
    //半開区間[a, b)で持つ
    rep(m, i) {
        int a, b;
        scanf("%d %d\n", &a, &b);
        a--; b--;
        step[a]++;
        step[b]--;
    }
    rep(N, i) step[i+1] += step[i];
    int dis = 0, ans = 0;
    rep(N+1, n) {
        if (step[n] > 0) dis++;
        else {
            ans += dis;
            dis = 0;
        }
    }
    ans = ans*2+1+N;
    cout << ans << '\n';
}

int main(void){
  solve();
  return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

ll f(ll x, ll y, ll z, ll n){
    return x*x+y*y+z*z+x*y+x*z+z*y-n;
}

ll solve(ll n){
    ll res=0;
    for(ll x=1;x*x<=n;x++){
        for(ll y=1;y*y<=n;y++){
            ll l=1;
            ll r=100;
            while(r-l>1){
                ll med=(l+r)/2;
                if(f(x,y,med,n)>0){
                    r=med;
                }else{
                    l=med;
                }
            }
            if(f(x,y,l,n)==0){
                res++;
            }
        }
    }
    return res;
}

int main(){
    ll n;
    cin>>n;
    vector<ll> ans(n,0);
    for(ll i=1;i<=n;i++){
        ans[i-1]=solve(i);
    }
    for(ll i=0;i<n;i++) cout<<ans[i]<<endl;
}

Measured memory_bytes: 3628
n,m = map(int, input().split())

'''
d = dict()
for i in range(1,n+1):
    d[str(i)] = 1
from collections import deque
ans = deque('1')'''
box = [1 for i in range(n)]
ans = [0 for i in range(n)]
ans[0] = 1
for _ in range(m):
    x,y = map(int,input().split())
    box[x-1] -= 1
    box[y-1] += 1
    if ans[x-1]==1 and ans[y-1]==0:
        ans[y-1] = 1
    if box[x-1]==0 and ans[x-1]==1:
        ans[x-1] = 0
print(sum(ans))


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int A, B, K;
    cin >> A >> B >> K;

    int cnt = 0;
    for (int i = min(A, B); i >= 0; i--)
    {
        if (A % i == 0 && B % i == 0)
        {
            cnt++;
        }
        if (cnt == K)
        {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int,input().split()))
x.reverse()
ans =[]
c=1
for i in range(n):
    c=0
    for j in range(n-i):
        if x[j]==n-i-j:
            ans.append(x.pop(j))
            c=1
            break
    if c==0:
        print('-1')
        exit()    
ans.reverse()
for i in ans:
        print(i)


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

int main() {
  long k,a,b,kekka = 0;
  cin >> k >> a >> b;
  if(b - a <= 2){
    kekka = k+1;
  }
  else if(a+1 > k){
    kekka = k+1;
  }
  else{
    long nokori = k-a+1;
    kekka = (b-a)*(nokori/2) + nokori%2 + a;
  }
  cout << kekka << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define REP(i, N) for (int i = 0; i < N; i++)
#define REP1(i, N) for (int i = 1; i < N; i++)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ANS(a) cout << a << endl
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())
#define DBG(V) for (auto v : V) cout << v << " "; cout << endl

unsigned long A, B, C;

int
main()
{
  cin >> A >> B >> C;

  
  int ans;
  if (A > B && A > C) {
    ans = B * C / 2;
  } else if (B > A && B > C) {
    ans = A * C / 2;
  } else {
    ans = A * B / 2;
  }
  ANS(ans);
}



Measured memory_bytes: 3604