akhauriyash/Code-Regression huggingface dataset:
let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let parent i = int_of_float ((float_of_int (i - 1)) /. 2.)

let left i = 2*i + 1

let right i = 2*i + 2

let to_pow_of_2 n =
  let rec doit i =
    if i > n then i
    else doit (i * 2) in
  doit 1

let add s n i x =
  let j = n + i - 1 in
  s.(j) <- x + s.(j);
  let rec doit j =
    if j > 0 then begin
      let j = parent j in
      s.(j) <- s.(left j) + s.(right j);
      doit j
    end in
  doit j

let sum s n a b =
  let rec doit a b k l r =
    if r < a || b < l then 0
    else if a <= l && r <= b then s.(k)
    else doit a b (left k) l ((l + r) / 2) + doit a b (right k) ((l + r) / 2 + 1) r in
  doit a b 0 0 (n - 1)

let solve n q =
  let n = to_pow_of_2 n in
  let s = Array.make (2*n) 0 in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split (read_line ()) ' ') with
      | 0 :: x :: y :: _ -> add s n x y
      | 1 :: x :: y :: _ -> Printf.printf "%d\n" (sum s n x y)
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; q] -> solve n q
  | _ -> ()

Measured memory_bytes: 6504
use std::io;


fn main() {
    let (w, a, b) = {
        let i = read::<isize>();
        (i[0], i[1], i[2])
    };

    if (a - b).abs() <= w { println!("0"); }
    else { println!("{}", (a - b).abs() - w); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let vec: Vec<usize> = (0..N).map(|_| read()).collect();
    let rems: Vec<_> = vec.iter().filter(|&x| x % 10 != 0).collect();
    let sum = vec.iter().sum::<usize>();
    let ans = if rems.is_empty() {
        0
    } else if sum % 10 != 0 {
        sum
    } else {
        let mut rems = rems;
        rems.sort();
        sum - rems[0]
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		for(int i=1;i<10001;i++){
			String val=scan.nextLine();
			String [] num=val.split(" ",0);
			int x=Integer.parseInt(num[0]);
			int y=Integer.parseInt(num[2]);
			if(num[1].equals("+")){
				System.out.println(x+y);
			}else if(num[1].equals("-")){
				System.out.println(x-y);
			}else if(num[1].equals("*")){
				System.out.println(x*y);
			}else if(num[1].equals("/")){
				System.out.println(x/y);
			}else{
				System.exit(0);
			}
		}
	}
}

Measured memory_bytes: 26304
def main():
    n,m,c = map(int,input().split())
    b = list(map(int,input().split()))
    a = [list(map(int, input().split())) for _ in range(n)]

    cnt = 0
    for i in range(n):
        tmp = 0
        for j in range(m):
            tmp += a[i][j] * b[j]
        if tmp+c > 0:
            cnt += 1
    print(cnt)
    
if __name__ == '__main__':
    main()



Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int flr(double x){
	if(x<0)	return ceil(x);
	else 	return floor(x);
}
int main(){
	double x=0,y=0;
	int arg=90;
	while(true){
		int d,a;	scanf("%d,%d",&d,&a);
		if(d==0&&a==0)	break;
		double args=(arg)/180.0*M_PI;
		x+=d*cos(args);	y+=d*sin(args);
		arg-=a;
	}
	printf("%d\n",flr(x));
	printf("%d\n",flr(y));
	return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	string s;
	cin>>s;
	string s1=s.substr(0,3);
	cout<<s1<<endl;
	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        final int N=scanner.nextInt();
        final String string=scanner.next();
        String[] strings=string.split("");
        boolean[] booleans=new boolean[N];
        for(int i=0;i<N;i++){
            if(strings[i].equals("E")) booleans[i]=true;
        }
        int temp=0;
        for(int i=0;i<N;i++){
            if(!booleans[i]) temp++;
        }
        int max=temp;
        for(int i=0;i<N;i++){
            if(booleans[N-i-1]){
                temp++;
            }else{
                temp--;
            }
            if(max>temp) max=temp;
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 53348
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define lli long long int  
#define ll  long long 
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl   vector<ll>
#define mii unordered_map<ll,ll>
#define pb push_back
double pi = 2*acos(0.0);
ll power(ll a,ll b){ ll res=1;while(b){if(b&1)res=res*a;b=b/2; a=(a*a); }return res;}
 
//bool sortinrev(const pair<int,int> &a,   const pair<int,int> &b) {  if(a.first==b.first) return a.second>b.second;  return (a.first < b.first);} 
              
     
 
 int main()
 {
       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
       ll tst;
       tst=1; 
       //cin>>tst;
       while(tst--)
       {
         
          lli n,d,cnt=0;
          cin>>n>>d;
          for(int i=0;i<n;i++)
          {
          	int p,q;
          	cin>>p>>q;
          	if(sqrt(power(p,2)+power(q,2))<=d)
          		cnt++;
          }
          cout<<cnt<<endl;


        }  
       
 }

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

int main() {

	int r, c;
	std::cin >> r >> c;

	std::vector< std::vector<int> > mat;

	mat.resize(r + 1);
	for (int i = 0; i < r + 1; i++) {
		mat[i].resize(c + 1);
	}

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			std::cin >> mat[i][j];
		}
	}

	// anticipating mat[i][c] == 0...
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			mat[i][c] += mat[i][j];
		}
	}

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c+1; j++) {
			mat[r][j] += mat[i][j];
		}
	}

	for (int i = 0; i < r + 1; i++) {
		for (int j = 0; j < c + 1; j++) {
			std::cout << mat[i][j];
			if (j != c)
				std::cout << " ";
		}
		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3140
// abc125_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int A,B,T;
    cin >> A >> B >> T;

    int ans = B * (T/A);

    print(ans);

    return 0;
}


Measured memory_bytes: 256
// Ver19.03
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll a, b, count = 0;
  scanf("%lld%lld", &a, &b);
  for (int i = a; i <= b; i++)
  {
    if (i / 10000 == i % 10)
    {
      if ((i % 10000) / 1000 == ((((i % 10000) % 1000) % 100) / 10))
      {
        count++;
      }
    }
  }
  printf("%lld\n", count);
  return 0;
}

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

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

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

  int q;
  cin >> q;

  vector<int> t(n);
  for ( int i = 0; i < q; i++ ) cin >> t[i];

  int cnt = 0;
  for ( int i = 0; i < q; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      if ( t[i] == s[j] ) {
	cnt++;
	s[j] = -1;
	break;
      }
    }
  }

  cout << cnt << endl;
  
  return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("text1.in","r",stdin);
	//freopen("text1.out","w",stdout);
	int k,a,b;
	cin>>k;
	cin>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0) {
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n, m, a, sum = 0;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a;
        sum += a;
    }
    if (sum <= n) cout << n - sum << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 302
#define ac 500
#define mod 1000000007
#define LL long long

int n, m;
int Head[AC], date[ac], Next[ac], len[ac], tot;
LL f[AC][AC][AC], ans;

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

inline void add(int f, int w, int S)
{
	date[++tot] = w, Next[tot] = Head[f], Head[f] = tot, len[tot] = S;
}

inline void pre()
{
	int a, b, c;
	n = read(), m = read();
	for(R i = 1; i <= m; i ++)
	{
		a = read(), b = read(), c = read();
		add(b, a, c);//以右端点为标准
	}
}

inline int Max(int x, int y, int z)
{
	if(y > x) x = y;
	if(z > x) x = z;
	return x;
}

inline bool check(int x, int y, int z)
{
	if(x && y && x == y) return false;
	if(x && z && x == z) return false;
	if(y && z && y == z) return false;
	int k = Max(x, y, z);
	for(R i = Head[k]; i; i = Next[i])
	{
		int now = date[i], v = len[i], tmp = 0;
		if(x >= now) ++ tmp;
		if(y >= now) ++ tmp;
		if(z >= now) ++ tmp;
		if(tmp != v) return false;
	}
	return true;
}

void work()
{
	f[0][0][0] = 1;
	for(R i = 0; i <= n; i ++)
		for(R j = 0; j <= n; j ++)
			for(R l = 0; l <= n; l ++)
			{
				int k = Max(i, j, l);
				if(!f[i][j][l]) continue;
				//printf("(%d, %d, %d) = %lld\n", i, j, l, f[i][j][l]);
				if(!check(i, j, l)) continue;
				LL t = f[i][j][l];
				f[k + 1][j][l] = (f[k + 1][j][l] + t) % mod;
				f[i][k + 1][l] = (f[i][k + 1][l] + t) % mod;
				f[i][j][k + 1] = (f[i][j][k + 1] + t) % mod;
				if(k == n) ans = (ans + f[i][j][l]) % mod;//必须到排到了n
			}
	printf("%lld\n", ans);
}

int main()
{
	pre();
	work();
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--ModInt
//-------------------------------------------------
const ::std::uint_fast64_t MOD = 1e9+7;

class mint
{
private:
    using value_type = ::std::uint_fast64_t;
    value_type n;
public:
    mint():n(0){}
    mint(::std::int_fast64_t _n):n(_n<0 ? MOD-(-_n)%MOD : _n%MOD){}
    mint(const mint &m):n(m.n){}

    friend ::std::ostream& operator<<(::std::ostream &os, const mint &a){
		return os << a.n;
	}
    friend ::std::istream& operator>>(::std::istream &is, mint &a){
        value_type temp; is>>temp;
        a = mint(temp);
        return is;
    }

    mint& operator+=(const mint &m){n+=m.n; n=(n<MOD)?n:n-MOD; return *this;}
    mint& operator-=(const mint &m){n+=MOD-m.n; n=(n<MOD)?n:n-MOD; return *this;}
    mint& operator*=(const mint &m){n=n*m.n%MOD; return *this;}
    mint& operator/=(const mint &m){return *this*=m.inv();}
    mint& operator++(){return *this+=1;}
    mint& operator--(){return *this-=1;}

    mint operator+(const mint &m) const {return mint(*this)+=m;}
    mint operator-(const mint &m) const {return mint(*this)-=m;}
    mint operator*(const mint &m) const {return mint(*this)*=m;}
    mint operator/(const mint &m) const {return mint(*this)/=m;}
    mint operator++(int){mint t(*this); *this+=1; return t;}
    mint operator--(int){mint t(*this); *this-=1; return t;}

    mint operator==(const mint &m) const {return n==m.n;}
    mint operator!=(const mint &m) const {return n!=m.n;}
    mint operator-() const {return mint(MOD-n);}

    mint pow(value_type b) const {
        mint ret(1), m(*this);
        while(b){
            if (b & 1) ret*=m;
            m*=m;
            b>>=1;
        }
        return ret;
    }

    mint inv() const {return pow(MOD-2);}
};

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n);
    map<int,int> cnt;
    rep(i,n) cin>>a[i];
    rep(i,n) cnt[a[i]]++;
    for(auto e:cnt){
        if ((e.fi==0&&e.se!=1)||(e.fi!=0&&e.se!=2)){
            cout<<"0\n";
            return 0;
        }
    }
    cout<<mint(2).pow(n/2)<<"\n";
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>

using namespace std;


int main() {
	int n;
	cin >> n;
	multimap<string, int>guide;
	vector<pair<string, int> > queries;
	vector<int>ans;
	for (int i = 0; i < n; i++) {
		string s; int score;
		cin >> s >> score;
		guide.insert(pair<string, int>(s, score));
		queries.push_back(pair<string, int>(s, score));
	}
	vector<int>choose;
	auto nnext = guide.begin();
	string next = guide.begin()->first;
	for (auto itr = guide.begin(); 1==1 ; itr++) {
		if (itr != guide.end()) {
			if (itr->first == next) {
				choose.push_back(itr->second);
			}
			else {
				sort(choose.begin(), choose.end());
				for (int i = choose.size() - 1; i >= 0; i--) {
					for (int j = 0; j < n; j++) {
						if (queries[j].first == next && queries[j].second == choose[i]) {
							ans.push_back(j);
						}
					}
				}
				nnext = itr;
				next = itr->first;
				itr--;
				choose.clear();
			}
		}
		if (itr==guide.end()) {
			sort(choose.begin(), choose.end());
			for (int i = choose.size() - 1; i >= 0; i--) {
				for (int j = 0; j < n; j++) {
					if (queries[j].first == next && queries[j].second == choose[i]) {
						ans.push_back(j);
					}
				}
			}
			
			break;
		}
	}



	for (int i = 0; i < n; i++) {
		cout << ans[i] + 1 << endl;
	}





}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 10000000000000000
int main(){
	int a,b;
	cin>>a>>b;

	if(a<=5){
		cout<<0<<endl;
	}else if(a<=12){
		cout<<b/2<<endl;
	}else{
		cout<<b<<endl;
	}

	return 0;
}

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

long long dp[1005][1005];

vector<string>vec;

int main()
{
    int n, m;
    string s;

    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        vec.push_back(s);
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i==1 and j==1)
            {
                if(vec[i-1][j-1]=='.') dp[i][j] = 1;
            }

            else if(vec[i-1][j-1]=='.'){
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
                dp[i][j] = dp[i][j] % 1000000007;
            }
        }
    }

    cout<<dp[n][m]<<endl;

    return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
struct sj{
	int a,l,r;ll x;
	inline sj(){}
	inline sj(int a,int l,int r,ll x):a(a),l(l),r(r),x(x){}
	inline bool operator<(const sj &t)const{return x>t.x;}
}d[N];
inline void cmax(ll &a,ll b){if(a<b)a=b;}
inline ll Y(int i,ll k){
	ll a=d[i].a;
	if(k<=a)return k*d[i].l;
	else    return k*d[i].r+a*(d[i].l-d[i].r);
}
int main(){
	int n,i,a,l,r,x;
	ll L=0ll,R,M,S,g=0ll,t1,t2;
	scanf("%d%d",&n,&x);R=(S=(t1=((ll)x))*n)-1ll;
	for(i=1;i<=n;++i){
		scanf("%d%d%d",&a,&l,&r);t2=a;
		d[i]=sj(a,l,r,t1*r+t2*(l-r));
		g+=l*t2;
	}
	sort(d+1,d+n+1);
	while(L<=R){
		M=(L+R)>>1;
		l=M/x;
		r=M%x;
//		printf("M=%lld l=%d r=%d",M,l,r);
//		for(i=1;i<=n;++i)printf(" (%d,%d)",d[i].x,Y(i,r));
//		printf("\n");
		t1=-1000000000000ll;t2=0ll;
		for(i=1;i<=l;++i){
			t2+=d[i].x;
			cmax(t1,Y(i,r)-d[i].x);
		}
		t1+=d[i].x;
		for(   ;i<=n;++i)cmax(t1,Y(i,r));
		if(t1+t2>=g)R=(S=M)-1ll;else L=M+1ll;
	}
	printf("%lld",S);
	return 0;
}

Measured memory_bytes: 2560
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	ms := make(map[int]int, m)
	r := 0
	for i := 0; i < n; i++ {
		var k int
		fmt.Scan(&k)
		for j := 0; j < k; j++ {
			as := make([]int, k)
			fmt.Scan(&as[j])
			ms[as[j]]++
		}
	}
	for _, v := range ms {
		if v == n {
			r++
		}
	}
	fmt.Println(r)
}


Measured memory_bytes: 768
nn,ww=map(int,input().split())
value=[0]*nn
weight=[0]*nn
for i in range(nn):
    value[i],weight[i]=map(int,input().split())    

dp=[[0]*(ww+1) for i in range(nn+1)]
for w in range(ww+1):
    dp[0][w]=0
    
for i in range(nn):
    for w in range(ww+1):
        if w-weight[i]>=0:
            dp[i+1][w]=max(dp[i][w],dp[i][w-weight[i]]+value[i],dp[i+1][w-weight[i]]+value[i])
        else:
            dp[i+1][w]=dp[i][w]

print(dp[nn][ww])


Measured memory_bytes: 15688
//AtCoder ABC048 A - AtCoder *** Contest
#include <bits/stdc++.h>
using namespace std;
using lli=int64_t;

int main() {
    string t,s;
    cin>>t>>s>>t;
    string ans="A*C";
    ans[1]=s[0];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val itemCount = readLine()!!.toInt()
    val items = (1..itemCount).map { readLine()!!.toInt() }
    val max = items.max()!!
    val maxCount = items.count { it == max }

    items.forEach {
        if(it == max && maxCount == 1) {
            println(items.filter { it != max }.max()            )
        } else {
            println(max)
        }
    }

}


Measured memory_bytes: 54804
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int,int>
#define ppb pop_back
#define orta ((bas+son)>>1)
#define st first
#define nd second
#define ll long long
#define N 505
#define inf 1000000000
#define MOD 1000000007
#define LOG 29
#define EPS 0.000000001
#define M 305
using namespace std;

int main() {

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

	string s;
	cin>>s;
	if(sz(s)%2!=0) {
		cout<<"No";
		return 0;
	}
	for(int i=0;i<sz(s);i++) {
		if(i&1 && s[i]!='i') {
			cout<<"No\n";
			return 0;
		}
		if(!(i&1) && s[i]!='h') {
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes";

}

Measured memory_bytes: 256
from sys import stdin
from itertools import repeat
def main(ab=abs):
    n = int(stdin.readline())
    a = map(int, stdin.readline().split(), repeat(10, n))
    s = sum(a)
    t = 0
    ans = s
    for i, x in enumerate(a):
        t += x
        s -= x
        c = ab(s - t)
        if ans > c:
            ans = c
    print ans
main()


Measured memory_bytes: 20096
ans' k n =
  if n < 0
  then 0
  else
    if 2 * k < n
    then 0
    else
      if k >= n
      then n+1
      else (2 * k) - n + 1

ans :: Integer -> Integer -> Integer
ans k s = 
  let xs = [0..k]
      o = sum $ map (\i -> ans' k (s-i) ) xs
  in
    o

main = do
  c <- getLine
  let (k:s:_) = map read $ words c :: [Integer]
      o = ans k s
  print o
 


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void) {
    int x;
    cin >> x;

    if(x==0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3632
require 'prime';

### constant

MAX_M = 100000

### main

primes = Prime.each(MAX_M).to_a
nprimes = primes.length

loop do
  m, a, b = gets.split.map(&:to_i)
  break if (m | a | b) == 0

  max_ar = 0
  max_pq = nil
  
  primes.each_with_index do |p0, i|
    break if p0 * p0 > m
    
    for j in (i...nprimes)
      q0 = primes[j]
      break if p0 * q0 > m || a * q0 > b * p0
      ar = p0 * q0
      if max_ar < ar
        max_ar = ar
        max_pq = [p0, q0]
      end
    end
  end

  puts max_pq.join(' ')
end

Measured memory_bytes: 6324
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
 
 
int pow1(int n, int p)
{
	if(p==0)	return 1;
	int x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}

int arr[10001][1000];
 
int32_t main()
{
	fast;

	int h;
	cin>>h;
	int n;
	cin>>n;
	vector<pair<int, int>> v;
	for(int i=0;i<n;i++)
	{
		int a, b;
		cin>>a>>b;
		v.push_back({a, b});
	}

	for(int i=0;i<n;i++)
		arr[0][i]=0;

	vector<int> mn(h+1);

	mn[0]=0;

	for(int i=1;i<=h;i++)
	{
		int mnv=1e12;
		for(int j=0;j<n;j++)
		{
			int x=i-v[j].first;
			if(x<0)
				x=0;
			arr[i][j]=mn[x]+v[j].second;
			if(j!=0)
				arr[i][j]=min(arr[i][j], arr[i][j-1]);
			mnv=min(mnv, arr[i][j]);
		}
		mn[i]=mnv;
	}

	// for(int i=0;i<=h;i++)
	// {
	// 	for(int j=0;j<n;j++)
	// 		cout<<arr[i][j]<<' ';
	// 	cout<<endl;
	// }

	cout<<mn[h]<<endl;

	return 0;
}

Measured memory_bytes: 78464
a = [0,0,0]
s = input().split()
a[0] = int(s[0])
a[1] = int(s[1])
a[2] = int(s[2])

#a_min = min(a)
#a[0] -= a_min
#a[1] -= a_min
#a[2] -= a_min

count = 0
while(True):
    if a[0] == a[1] and a[1] == a[2]:
        #print(count)
        break
    a.sort()
    if a[2] >= a[0]+2:
        a[0] += 2
        count += 1
    elif a[0] == a[1]:
        count += 1
        break
    elif a[1] == a[2]:
        count += 2
        break
print(count)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
//#include "atcoder/all"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
//using namespace atcoder;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll a, b;
	cin >> n >> a >> b;
	vector<ll> x(n);
	rep(i,n) cin >> x[i];
	ll ans = 0;
	rep(i,n-1){
		ans += min(a*(x[i+1] - x[i]), b);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3952
from collections import Counter as co
s=input()
n=len(s)
l=sorted(co(list(s)).values())
if len(l)<=2:
    print("YES") if n==len(l) else print("NO")

else:
    m=l[0]
    for v in l:
        if v-m<=1:continue
        print("NO");exit()

    print("YES")

Measured memory_bytes: 4340
#include <stdio.h>
int main(void)
{
	int n[50];
	int a = 0,i,j,k,l,m;
	int count = 0,sam = 0;

	while (scanf("%d", &n[a]) != EOF) {
		if ((1 <= n[a]) && (n[a] <= 50)) {
			a++;
		}
	}

  for(m=0; m<a;m++){
	  count = 0;
	for (i = 0; i <= 9; i++) {
		for (j = 0; j <= 9; j++) {
			for (k = 0; k <= 9; k++) {
				for (l = 0; l <= 9; l++) {
					sam = l + k + j + i;
					if (sam == n[m]) {
						count++;
					}
			   	}
		    }
		}
	}
	printf("%d\n",count);
}

	return 0;
}

Measured memory_bytes: 596
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fromIntegral . fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntListN n = map readInt <$> replicateM (fromIntegral n) BS.getLine

getItems :: [Int] -> Int -> Int
getItems as d = foldr (\ a -> (+) ((d - 1) `div` a + 1)) 0 as

main = do
  n <- getInt
  [d, x] <- getIntList
  as <- getIntListN n
  print $ getItems as d + x
  

Measured memory_bytes: 508
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	string s;
	cin >> s;
	int x,y;
	cin >> x >> y;
	vector<int> xx,yy;
	int pre=-1;
	int flag=1;
	for(int i=0;i<s.length();i++){
		if(s[i]=='T' || i==s.length()-1) {
			if(s[i]=='F') i++;
			if(flag==1) {
				xx.push_back(i-pre-1);
				pre=i;
			}else{
				yy.push_back(i-pre-1);
				pre=i;
			}
			flag*=-1;
		}
	}

	int nowx=xx[0];
	xx.erase(xx.begin());
	int nowy=0;
	sort(xx.begin(),xx.end(),greater<int>());
	sort(yy.begin(),yy.end(),greater<int>());
	for(int i=0;i<xx.size();i++){
	if(x-nowx>=0) nowx+=xx[i];
		else nowx-=xx[i];
	}
	for(int i=0;i<yy.size();i++){
		if(y-nowy>=0) nowy+=yy[i];
		else nowy-=yy[i];
	}
	if(x==nowx && y==nowy) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
    int N,D;
    scanf("%d",&N);
    scanf("%d",&D);
    int flag =0;
    for(int i=0;i<N;i++){
        long x,y;
        scanf("%ld",&x);
        scanf("%ld",&y);
        if(sqrt(x*x+y*y)<=D) flag++;
    }
    printf("%d",flag);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  if(N == 1) {
    cout << "Hello World" << endl;
  }
  if(N == 2) {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
}

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

int c[30];
int dp[50010];

signed main(){

  int n,m; cin >> n >> m;
  for(int i = 0; i < m; i++){
    cin >> c[i];
  }
  fill(dp,dp+50010,1 << 30);
  dp[0] = 0;
  for(int i = 0; i < m; i++){
    for(int j = 0; j < n; j++){
      if(j+c[i] > n) break;
      dp[j+c[i]] = min(dp[j+c[i]],dp[j]+1);
    }
  }
  cout << dp[n] << endl;

  return 0;
}



Measured memory_bytes: 3312
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn solve() {
    let (n,c,k) = get!(usize, usize, usize);
    let mut ts = get!(usize; n);
    ts.sort();
    let mut heap = BinaryHeap::<Rev<_>>::new();

    let mut count = 0;
    for t in ts {
        if !heap.is_empty() {
            if heap.len() >= c || heap.peek().unwrap().0 + k < t {
                heap.clear();
                count += 1;
            }
        }
        heap.push(Rev(t));
    }
    if !heap.is_empty() {
        count += 1;
    }
    println!("{}", count);
}


Measured memory_bytes: 8572
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using vi = vector<int>;
using ll = long long;

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

    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ans += a.at(i / 2);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3972
N = int(input())
Edge = [list(map(int,input().split())) for i in range(N-1)]
Q,K = map(int,input().split())
Query = [list(map(int,input().split())) for i in range(Q)]

Graph = [[] for i in range(N)]
for edge in Edge:
    Graph[edge[0]-1].append([edge[1]-1,edge[2]])
    Graph[edge[1]-1].append([edge[0]-1,edge[2]])

Distance = [-1 for i in range(N)]
Distance[K-1] = 0

stack = [K-1]
while stack:
    node = stack.pop()
    for adj in Graph[node]:
        if Distance[adj[0]] == -1:
            Distance[adj[0]] = Distance[node] + adj[1]
            stack.append(adj[0])

for query in Query:
    print(Distance[query[0]-1]+Distance[query[1]-1])

Measured memory_bytes: 120408
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define FLOOR(x) ((int)floor(((double)x)))
#define CEIL(x) ((int)ceil(((double)x)))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mt make_tuple
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


int N;
int A[200010];
int acc[200010];


void makeAcc(){
	repe(i, 1, N) acc[i] = acc[i-1]+A[i-1];
}


int solve(){
	int ans = INF;
	rep(y, 2, N-1){
		int x1 = lower_bound(&acc[1], &acc[y], (acc[y]-acc[0])/2)-&acc[0];
		int x2 = x1-1;
		int P1 = acc[x1]-acc[0];
		int Q1 = acc[y]-acc[x1];
		int P2 = acc[x2]-acc[0];
		int Q2 = acc[y]-acc[x2];
		int z1 = lower_bound(&acc[y+1], &acc[N], (acc[N]-acc[y])/2+acc[y])-&acc[0];
		int z2 = z1-1;
		int R1 = acc[z1]-acc[y];
		int S1 = acc[N]-acc[z1];
		int R2 = acc[z2]-acc[y];
		int S2 = acc[N]-acc[z2];
		ans = min(ans, max({ P1, Q1, R1, S1 })-min({ P1, Q1, R1, S1 }));
		ans = min(ans, max({ P1, Q1, R2, S2 })-min({ P1, Q1, R2, S2 }));
		ans = min(ans, max({ P2, Q2, R1, S1 })-min({ P2, Q2, R1, S1 }));
		ans = min(ans, max({ P2, Q2, R2, S2 })-min({ P2, Q2, R2, S2 }));
	}
	return ans;
}


signed main(){
	cin >> N;
	rep(i, 0, N) cin >> A[i];

	makeAcc();

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include <algorithm>
using namespace std;
#define FOR(xxx,begin,num) for(int xxx=(begin);xxx<((begin)+(num));xxx++)
int main(){
  int N,cnt[200010];string S[200010],sw;
  cin >> N;
  FOR(i,0,N) cin >> S[i];
  sort(S, S + N);
  int tmp = 0,max = 0;
  cnt[0] = 1;
  FOR(i,1,N-1){
    if(S[tmp]==S[i]){cnt[tmp]++;}
    else{tmp = i;cnt[tmp]++;}
  }
  FOR(i,0,N){
    if(max < cnt[i]){
      max = cnt[i];
    }
  }
  FOR(i,0,N){
    if(cnt[i]==max) cout << S[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int cnt[128];
string a[100];

int main(void) {
    int i, j, h, w;
    cin >> h >> w;
    REP (i,h) cin >> a[i];

    REP (i,h) REP (j,w) cnt[a[i][j]]++;
    if (h % 2 & w % 2) {
        int odd = 0;
        REP (i,'a','z') if (cnt[i] % 2) {
            cnt[i]--;
            odd++;
        }
        if (odd != 1) {
            puts("No");
            return 0;
        }
    }
    int sum = (h / 2 * 2) * (w / 2 * 2);
    REP (i,'a','z') while (sum > 0 && cnt[i] >= 4) {
        cnt[i] -= 4;
        sum -= 4;
    }
    if (sum != 0) {
        puts("No");
        return 0;
    }
    sum = h % 2 * (w / 2 * 2) + w % 2 * (h / 2 * 2);
    REP (i,'a','z') while (cnt[i] >= 2) {
        cnt[i] -= 2;
        sum -= 2;
    }
    if (sum != 0) {
        puts("No");
        return 0;
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
using namespace atcoder;

void _main() {
    int T;
    cin >> T;
    REP (i, T) {
        int N, M, A, B;
        cin >> N >> M >> A >> B;
        cout << floor_sum(N, M, A, B) << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 3656
h = int(input())

i = 0
now = 0
while now < h:
    now = 2 ** i
    if now >= h:
        break
    i += 1

if 2 ** i == h:
    pass
else:
    i = i -1

ans = 0
for j in range(i+1):
    ans += 2 ** j

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int n;cin>>n;
	vector<int> h(n);
	for(int i=0;i<n;i++)
	{
	    cin>>h[i];
	}
	vector<int> dp(n);
	dp[0]=0;dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
	{
	    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

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

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

bool isAllVisit(const vector<bool>& visit) {
    for (auto&& v : visit) {
        if (!v)return false;
    }
    return true;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<int>H(N);
    cin >> H;

    FORR(i, N, 1) {
        if (H[i - 1] > H[i]) {
            H[i - 1]--;
        }
        if (H[i - 1] > H[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	string s;
	cin >> s;
	int S = 0,T = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'S') S++;
		else{
			if(S > 0)S--;
			else T++;
		}
	}

	cout << S+T << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
#include <atcoder/all>
using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;
ll MOD = 998244353;


// rem, rightest, width
using mint = modint998244353;

vector<mint> pw;
void init (int n) {
    pw.resize(n + 1);
    pw[0] = 1;
    rep (i, n) pw[i + 1] = pw[i] * 10;
}


using S = pair <mint, P>;
using F = int;
const F ID = -1;
S op (S a, S b) {
    if (b.second.first < 0) return a;
    if (a.second.first < 0) return b;
    if (a.second.first < b.second.first) {
        return {
            a.first * pw[b.second.first - a.second.first] + b.first,
            P {b.second.first,
            a.second.second + b.second.second}
        };
    } else {
        return {
            b.first * pw[a.second.first - b.second.first] + a.first,
            P {a.second.first,
            a.second.second + b.second.second}
        };
    }
}
S e (void) { return {0, P{-1, 0}}; }
S mapping (F f, S x) {
    if (f != ID)
        x.first = (mint)f * (pw[x.second.second] - 1) / (mint)9;
    return x;
}
F composition (F f, F g) {
    return f == ID ? g : f;
}
F id (void) {
    return ID;
}

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

    int n, q; cin >> n >> q;

    init(n);

    vector<S> v(n);
    rep (i, n) v[i] = S{1, P{i, 1}};
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(v);
    rep (_, q) {
        auto [s, p] = seg.all_prod(); auto [rr, w] = p;
        eprintf("%8d %d %d\n", s.val(), rr, w);
        
        int l, r, d; cin >> l >> r >> d;
        seg.apply(l - 1, r, d);
        cout << get<0>(seg.all_prod()).val() << "\n";
    }
    return 0;

    /***************************************************/
    /* Use "submit code (with ACL v1)" when using ACL! */
    /***************************************************/
    return 0;
}

Measured memory_bytes: 13476
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N,A,B,C;
vector<int> l;
int ans;
map<vector<int>,int> mp;
int setMp(vector<int> &list){
  int res=100000;
  for(int i=0;i<list.size();i++){
    for(int j=0;j<list.size();j++){
      if(i==j) continue;
      for(int k=0;k<list.size();k++){
        if(j==k||i==k) continue;
        res=min(res,abs(A-list[i])+abs(B-list[j])+abs(C-list[k]));
      }
    }
  }
  mp[list]=res;
  return res;
}

void setTake(vector<int> &list,int cost){
  if(list.size()<=3||cost>=ans) return;
  for(int i=0;i<list.size();i++){
    for(int j=0;j<list.size();j++){
      if(i==j) continue;
      if(list[i]+list[j]-A>=ans) continue;
      vector<int> nextList;
      for(int k=0;k<list.size();k++){
        if(k==i||k==j) continue;
        nextList.push_back(list[k]);
      }
      nextList.push_back(list[i]+list[j]);
      if(mp[nextList]>0) continue;
      ans=min(ans,setMp(nextList)+cost+10);
      setTake(nextList,cost+10);
    }
  }
  return;
}

int main(){
  cin>>N>>A>>B>>C;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    l.push_back(x);
  }
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());
  ans=setMp(l);
  setTake(l,0);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2048
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    val strings = mutableMapOf<String, Long>()
    
    for (i in 0 until N) {
        val s = readInputLine().toCharArray()
        s.sort()
        val sorted = s.joinToString("")
        val cnt = strings.get(sorted) ?: 0L
        strings.put(sorted, cnt + 1L)
    }

    var ans = 0L
    
    for ((k, v) in strings.toList()) {
        ans += (v.toLong() - 1L) * (v.toLong()) / 2L
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 61048
n = int(input())
x = list(map(int, input().split()))
hp_min = 10000 * n
for i in range(1, 101):
    hp = sum([(x[j] - i) ** 2 for j in range(len(x))])
    if hp < hp_min:
        hp_min = hp
print(hp_min)


Measured memory_bytes: 64848
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
    else:
        nex = b[i] - a[i]
        ans += a[i]
        if a[i + 1] >= nex:
            a[i + 1] -= nex
            ans += nex
        else:
            ans += a[i + 1]
            a[i + 1] = 0
print(ans)            

Measured memory_bytes: 18396
#include <stdio.h>
#include <iostream>
#include <string.h>
#define ll long long
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 110
using namespace std;
int main()
{

    int a,b,t;
    cin>>a>>b;
    t=max(a+b,a*b);
    t=max(t,a-b);
    cout<<t<<endl;
    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 
		 int N = scan.nextInt();
		 int d[] = new int[N];
		 
		 for (int i = 0; i < N; i++) {
			 d[i] = scan.nextInt();
		 }
		 
		 Arrays.sort(d);
		 
		 int K = d[N / 2] - d[N / 2 - 1];
		 
		System.out.println(K);
		 scan.close();

	}

}


Measured memory_bytes: 50392
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int N;
	cin >> N;
	int A[3][110];
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < N; j++){
			cin >> A[i][j];
		}
	}

	int ans = 0;
	for(int i = 0; i < N; i++){
		int sum = 0;
		for(int j = 0; j <= i; j++){
			sum += A[0][j];
		}
		for(int k = i; k < N; k++){
			sum += A[1][k];
		}
		ans = max(sum, ans);
	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256