akhauriyash/Code-Regression huggingface dataset:
from itertools import product 
n,a,b,c = map(int,input().split())
l = [int(input()) for _ in range(n)]
tar = [a,b,c]
ans = float("inf")
for p in product(range(4),repeat=n):
    mp = 0
    length = [0]*3
    for i,j in enumerate(p):
        if j == 3: continue
        if length[j] > 0: mp += 10
        length[j] += l[i]
    for j in range(3):
        if length[j] == 0: break
        mp += abs(length[j]-tar[j])
    else:
        ans = min(ans, mp)
print(ans)

Measured memory_bytes: 3064
use std::cmp;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let k: usize = sc.read();
    let p: Vec<usize> = sc.vec(n);

    let mut sum = 0;
    for i in 0..k {
        sum += p[i];
    }

    let mut max = sum;
    for i in k..n {
        sum -= p[i - k];
        sum += p[i];
        max = cmp::max(max, sum);
    }

    println!("{}", (max + k) as f64 / 2.0);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    ll n, m; cin >> n >> m;
    vll a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));

    vec<pair<ll,ll>> bc(m); 
    rep(i,m) cin >> bc[i].second >> bc[i].first;
    sort(all(bc));
    reverse(all(bc));

    vll new_card(n);
    ll idx = -1;
    for(int i = 0; i < m; ++i) {
        idx += bc[i].second;
        if(idx >= n-1) {
            idx = n-1;
            chmax(new_card[idx], bc[i].first);
            break;
        }
        else chmax(new_card[idx], bc[i].first);
    }
    //for(auto d : new_card) debug(d);

    ll cnt = 0;
    ll new_card_max = 0;
    for(int i = n-1; i >= 0; --i) {
        chmax(new_card_max, new_card[i]);
        //debug(new_card_max);
        if(new_card_max < a[i]) cnt += a[i];
        else cnt += new_card_max;
    }
    cout << cnt << '\n';
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int n,m;
    std::cin >> n >> m;
    std::vector<int> x(m), d(m-1);
    rep(i,m) std::cin >> x[i];

    if(n>=m){
        std::cout << 0 << "\n";
        return 0;
    }

    std::sort(x.begin(), x.end());
    rep(i,m-1) d[i] = x[i+1] - x[i];
    std::sort(d.begin(),d.end());

    int ans = x.back() - x.front();
    rep(i,n-1){
        ans -= d[d.size()-1-i];
    }
    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}


const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+17; //(+1までok)
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

inline int in(){int x; cin>>x; return x;}

int main(void){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	int N,D,X,A,result=0;
	cin>>N>>D>>X;
	REP(i,N){
		cin>>A;
		result+=((D-1)/A+1);
	}
	print(result+X);
	return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll maks1=max(a*c,a*d);
	ll maks2=max(b*c,b*d);
	ll maks=max(maks1,maks2);
	if(maks<0){
		if(a<=0 and b>=0){
			maks=0;
		}
		if(c<=0 and d>=0){
			maks=0;
		}
	}
	cout<<maks;
}

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

int main() {
  int N ;
  cin >> N ;
  vector<int> A(N) ;
  int ans = 0 ;
  rep(i,N){
    cin >> A.at(i) ;
    ans += A.at(i) - 1 ;
  }
  cout << ans <<endl ;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

  ll n;cin >> n;
  cout << (n + 1) / 2 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int a, b;
    cin >> a >> b;
    if (b % a == 0) cout << a + b << endl;
    else cout << b - a << endl;
}


Measured memory_bytes: 3612
J(y,m,d){if(m<3)y--,m+=12;return 1461*y/4+y/400-y/100+3059*(m-2)/100+d-678912;}M,D,y,m,d;main(Y){for(;~scanf("%d%d%d%d%d%d",&Y,&M,&D,&y,&m,&d);)Y<0||printf("%d\n",J(y,m,d)-J(Y,M,D));}

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

int main() {

    string s, t;
    cin >> s >> t;
    vector< string > v;
    int f = false;
    for(int i = 0; i < s.size() - t.size() + 1; i++) {
        bool dame = false;
        for(int j = 0; j < t.size(); j++) {
            if(s[i + j] != '?' && s[i + j] != t[j]) {
                dame = true;
                break;
            }
        }
        if(!dame) {
            string temp = s;
            for(int j = 0; j < t.size(); j++) {
                temp[i + j] = t[j];
            }
            f = true;
            v.push_back(temp);
        }
    }
    for(int i = 0; i < v.size(); i++){
        for(int j = 0; j < v[i].size(); j++) {
            if(v[i][j] == '?') v[i][j] = 'a';
        }
    }

    sort(v.begin(), v.end());
    cout << (f ? v[0] : "UNRESTORABLE") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int a, b, k;
	cin >> a >> b >> k;
	if(a >= k){
		a -= k;
	}else{
		k -= a;
		a = 0;
		long long int null = 0;
		b = max(b-k,null);
	}
	cout << a << " "<< b << endl;
	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    double x[n];
    string u[n];
    for(int i = 0; i < n; i++){
        cin >> x[i] >> u[i];
    }
    double ans = 0;
    for(int i = 0; i < n; i++){
        if (u[i] == "JPY") {
            ans += x[i];
        }else{
            ans += x[i] * 380000;
        }
        
    }
    cout << ans << '\n';

}

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

using namespace std;

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

    bool chk['z'+1] = {false};
    for(auto c : s) {
        chk[c] = true;
    }

    char min = '!';
    for(char i = 'a'; i <= 'z'; i++) {
        if(chk[i] == false) {
            min = i;
            break;
        }
    }

    if (min == '!') {
        cout << "None" << endl;
    } else {
        cout << min << endl;
    }

}


Measured memory_bytes: 512
import java.util.*;

public class Main{
    static final int last_month=4280;

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

        while((w=sc.nextInt())!=-1){
            this_month=0;

            this_month+=1150;               //phase1
            
            if(10<w && w<=20){              //phase2
                this_month+=(w-10)*125;
            }
            
            if(20<w && w<=30){              //phase3
                this_month+=10*125;                
                this_month+=(w-20)*140;
            }
            
            if(30<w){                       //phase4
                this_month+=10*125;                
                this_month+=10*140;
                this_month+=(w-30)*160;
            }

            System.out.println(last_month-this_month);
        }
    }
}


Measured memory_bytes: 26292
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int N, M, dp[1000][1 << 12];
int a[1000], b[1000], c[1000];

int go(int idx, int f) {
	if (f + 1 == 1 << N) return 0;
	if (idx >= M) return 0x3f3f3f3f;

	int &ret = dp[idx][f];
	if (ret != -1) return ret;

	ret = 0x3f3f3f3f;
	ret = min(ret, go(idx + 1, f | c[idx]) + a[idx]);
	ret = min(ret, go(idx + 1, f));

	return ret;
}
int main() {
	fastio; ini(dp, -1);
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		cin >> a[i] >> b[i];
		for (int v, j = 0; j < b[i]; ++j) {
			cin >> v;
			c[i] |= 1 << v - 1;
		}
	}

	int ans = go(0, 0);
	cout << (ans == 0x3f3f3f3f ? -1 : ans);

	return 0;
}

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

int min(int a,int b){
	if(a<b) return a;
	else return b;
}

int abs(int n){
	if(n>0) return n;
	else return -n;
}

int main(){
	int N,K;
	cin >> N >> K;
	int x[N];
	for(int i=0;i<N;i++){
		cin >> x[i];
	}
	
	int ans=0;
	for(int i=0;i<N;i++){
		ans+=2*min(abs(x[i]),abs(x[i]-K));
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int x;
    int i = 1;

    scanf("%d", &x);

    while (x != 0) {
        printf("Case %d: %d\n", i, x);
        i = i + 1;
        scanf("%d", &x);
    }
    return 0;
}

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

int main()
{
    unsigned long X;
    unsigned long sum, count;

    cin >> X;
    sum = 100;
    count = 0;

    while (sum < X)
    {
        sum += sum * 0.01;
        count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

class mod {
public:
    mod() {m_n = 0;}
    mod(ll n) {if (n >= 0) m_n = n % MOD; else m_n = n % MOD + MOD;}
    friend bool operator== (const mod& a, const mod& b) {return a.m_n == b.m_n;}
    friend bool operator!= (const mod& a, const mod& b) {return !(a == b);}
    friend mod operator+ (const mod& a, const mod& b) {return (a.m_n + b.m_n) % MOD;}
    friend mod& operator+= (mod& a, const mod& b) {return a = a + b;}
    friend mod operator- (const mod& a) {return -a.m_n;}
    friend mod operator- (const mod& a, const mod& b) {return (a.m_n + (-b.m_n)) % MOD;}
    friend mod& operator-= (mod& a, const mod& b) {return a = a - b;}
    friend mod operator* (const mod& a, const mod& b) {return (a.m_n * b.m_n) % MOD;}
    friend mod& operator*= (mod& a, const mod& b) {return a = a * b;}
    friend mod mod_pow(const mod& n, ll r) {
        if (r == 0) {
            return 1;
        } else if (r < 0) {
            return mod_pow(n, (MOD - 2) * (-r));
        } else if (r % 2 == 0) {
            mod tmp = mod_pow(n, r / 2);
            return tmp * tmp;
        } else {
            return n * mod_pow(n, r - 1);
        }
    }
    friend mod operator/ (const mod& a, const mod& b) {return a * mod_pow(b, -1);}
    friend mod& operator/= (mod& a, const mod& b) {return a = a / b;}
    friend ostream& operator<< (ostream& os, const mod& n) {os << n.m_n; return os;}
    friend istream& operator>> (istream& is, mod& n) {ll tmp; is >> tmp; n = mod(tmp); return is;}
private:
    ll m_n;
};

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int n = 0; n < N; ++n) cin >> A[n];
    
    mod Ret(0LL);
    for (int i = 0; i < 60; ++i) {
        ll num0 = 0;
        ll num1 = 0;
        for (int n = 0; n < N; ++n) {
            if (A[n] & (1LL << i)) {
                ++num1;
            } else {
                ++num0;
            }
        }
        mod Temp(num0 * num1);
        Temp *= mod_pow(mod(2), i);
        Ret += Temp;
    }
    cout << Ret << endl;

    return 0;
}


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

#define POS(i,j) ((i)*w+(j))

void toIndex(int n,int h,int w,int *x,int *y){
  *x=*y=0;
  while(w>1 && h>1 && n>=2*(w+h)-4){
    n-=2*(w+h)-4;
    w-=2;
    h-=2;
    *x+=1;
    *y+=1;
  }
  if(h==1){
    *y+=n;
    return;
  }
  if(w==1){
    *x+=n;
    return;
  }
  int q=w-1;
  while(n>0 && q>0){
    *y+=1;
    n--;
    q--;
  }
  q=h-1;
  while(n>0 && q>0){
    *x+=1;
    n--;
    q--;
  }
  q=w-1;
  while(n>0 && q>0){
    *y-=1;
    n--;
    q--;
  }
  q=h-2;
  while(n>0 && q>0){
    *x-=1;
    n--;
    q--;
  }
  return;
}

void run(void){
  int h,w;
  scanf("%d%d",&h,&w);
  int *a=(int *)malloc(sizeof(int)*h*w);
  int i;
  for(i=0;i<h*w;i++) scanf("%d",a+i);
  int *way=(int *)malloc(sizeof(int)*4*h*w);
  int wlen=0;
  int before=0;
  int flag=0;
  for(i=0;i<h*w;i++){
    int x,y;
    toIndex(i,h,w,&x,&y);
    if(flag && a[POS(x,y)]%2==1){
      int j;
      for(j=before;j<i;j++){
	int p,q,r,s;
	toIndex(j,h,w,&p,&q);
	toIndex(j+1,h,w,&r,&s);
	way[4*wlen+0]=p+1;
	way[4*wlen+1]=q+1;
	way[4*wlen+2]=r+1;
	way[4*wlen+3]=s+1;
	wlen++;
      }
    }
    if(a[POS(x,y)]%2==1){
      flag^=1;
      before=i;
    }
  }
  printf("%d\n",wlen);
  for(i=0;i<wlen;i++){
    printf("%d %d %d %d\n",way[4*i+0],way[4*i+1],way[4*i+2],way[4*i+3]);
  }
}

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


Measured memory_bytes: 6912
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
ll dp[5010][5010] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    rrep(i,N-1,0){
        rrep(j,N-1,0){
            if(S[i] == S[j]){
                dp[i][j] = dp[i+1][j+1] + 1;
            }else{
                dp[i][j] = 0;
            }
        }
    }
    ll ans = 0;
    rep(i,0,N){
        rep(j,0,N){
            if(abs(j - i) >= dp[i][j]) ans = max(ans, dp[i][j]);
        }
    }
    print(ans);
    
}

Measured memory_bytes: 195968
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    double cnt=0,len=s.length();
    //cout<<len<<" ";
    for(int i=0; i<s.length(); i++)
        if(s[i]=='h' && s[i+1]=='i')
            cnt++,i++;
    if(cnt==len/2)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int goal = 0;
    for (int i = 0; i < N; i++) goal += pow(N + 1, scanner.nextInt() - 1);

    double[] dp = new double[goal + 1];
    for (int i = 1; i <= goal; i++) {
      int s = i % (N + 1);
      int t = i / (N + 1) % (N + 1);
      int u = i / (N + 1) / (N + 1);
      int g = s + t + u;
      dp[i] = (double) N / g;
      if (s > 0) dp[i] += dp[i - 1] * s / g;
      if (t > 0) dp[i] += dp[i - N] * t / g;
      if (u > 0) dp[i] += dp[i - N * N - N] * u / g;
    }
    System.out.println(dp[goal]);
  }

  private static int pow(int a, int b) {
    int res = 1;
    while (b > 0) {
      res *= a;
      b--;
    }
    return res;
  }
}


Measured memory_bytes: 233940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<class T> class ReRooting {
  vector<T> res;
public:
  ReRooting(int n, vector<vector<int>> &_to, T identity, function<T(T, T)> operate, function<T(T, int)> add_node) {
    res.resize(n);
    if (n == 1) {
      res[0] = add_node(identity, 0);
      return;
    }
    vector<vector<int>> to(n), idx(n);
    for (int x = 0; x < n; x++) {
      for (int i = 0; i < _to[x].size(); i++) {
        int y = _to[x][i];
        if (x >= y)
          continue;
        idx[x].push_back(to[y].size());
        idx[y].push_back(to[x].size());
        to[x].push_back(y);
        to[y].push_back(x);
      }
    }
    vector<vector<T>> dp(n);
    for (int i = 0; i < n; i++)
      dp[i].resize(to[i].size());
    vector<int> ord = {0}, par(n);
    par[0] = -1;
    stack<int> st;
    st.push(0);
    while (!st.empty()) {
      int cur = st.top();
      st.pop();
      for (auto next : to[cur]) {
        if (next == par[cur])
          continue;
        par[next] = cur;
        ord.push_back(next);
        st.push(next);
      }
    }
    for (int i = n - 1; i > 0; i--) {
      int cur = ord[i], par_idx;
      T accum = identity;
      for (int j = 0; j < to[cur].size(); j++) {
        if (to[cur][j] == par[cur])
          par_idx = j;
        else
          accum = operate(accum, dp[cur][j]);
      }
      dp[par[cur]][idx[cur][par_idx]] = add_node(accum, cur);
    }
    for (int i = 0; i < n; i++) {
      int cur = ord[i];
      vector<T> r_accum(to[cur].size());
      r_accum.back() = identity;
      for (int j = (int)r_accum.size() - 1; j > 0; j--)
        r_accum[j-1] = operate(r_accum[j], dp[cur][j]);
      T l_accum = identity;
      for (int j = 0; j < r_accum.size(); j++) {
        T accum = operate(l_accum, r_accum[j]);
        dp[to[cur][j]][idx[cur][j]] = add_node(accum, cur);
        l_accum = operate(l_accum, dp[cur][j]);
      }
      res[cur] = add_node(l_accum, cur);
    }
  }
  T query(int root) {
    return res[root];
  }
};

struct Data {
  ll num;
  int mod;
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ReRooting<Data> dp(n, to, Data({1, m}), [](auto x, auto y) {
    ll a = x.num, b = y.num;
    int mod = x.mod;
    return Data({a*b%mod, mod});
  }, [&](auto x, auto y) {
    x.num++;
    return x;
  });
  rep(i, n) {
    int res = (dp.query(i).num-1+m)%m;
    cout << res << '\n';
  }
  return 0;
}

Measured memory_bytes: 29304
import java.util.*;

public class Main{
    final long mod = 1000000007;
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long sum = 0;
        long ans = 0;
        long[] a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
            sum += a[i];
        }
        for(int i = 0; i < n - 1; i++){
            sum -= a[i];
            ans += a[i] * (sum % mod);
            ans %= mod;
        }
        System.out.println(ans);
    }

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


Measured memory_bytes: 60976
figure = ''
height, width = [int(x) for x in input().split()]
while height or width:
    pattern = '#.' * (((height+width)//2) + 1)
    for h in range(height):
            figure += pattern[h : width + h] + '\n'
    figure += '\n'
    height, width = [int(x) for x in input().split()]

print(figure[:-1])

Measured memory_bytes: 7772
#関数リスト
import sys
from copy import deepcopy
input = sys.stdin.readline


def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))

def main():
    d = [[]]*10
    keta = I()
    num = input().rstrip()
    for i in range(keta):
        temp = int(num[i])
        if len(d[temp]) == 0:
            d[temp] = [int(keta-i)]
        else:
            d[temp].append(int(keta-i))
    result = 0
    for j in range(1000):
        a = j // 100
        b = (j % 100) // 10
        c = ((j % 100) % 10)
        try:
            a_num = d[a][0]
        except:
            continue
        try:
            if a == b:
                b_num = d[b][1]
            else:
                index = 0
                while True:
                    b_num = d[b][index]
                    if b_num < a_num:
                        break
                    else:
                        index += 1
        except:
            continue
        try:
            if a == c and a == b:
                c_num = d[c][2]
            elif a == c or b == c:
                c_num = min(d[c][1:])
            else:
                c_num = min(d[c])
        except:
            continue
        if a_num > b_num and b_num > c_num:
            result += 1

    print(result)

if __name__ == "__main__":
    main()

Measured memory_bytes: 75984
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
#define input(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,h,w,t,p,q,ans=0;
vl A,B,v1,v2,v3;
 
ll solve(){
    if((a+b)%2==0){
      cout<<(a+b)/2<<endl;
      return 0;
    }
  cout<<"IMPOSSIBLE"<<endl;
  return 0;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>a>>b;
    
    solve();
}

Measured memory_bytes: 256
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	int n; cin>>n;
	VI d(n);
	REP(i, n) cin >> d[i];

	SORT_ASC(d);
	cout << d[n/2]-d[n/2-1] << endl;
	
	

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 640
let max_int = 10000000000000000

type t =
  | Leaf
  | Node of body
and body = { left : t; right : t; data : int; l : int; r : int }

let rec init l xs = function
  | 1 ->
      Node
        { left = Leaf;
          right = Leaf;
          data = max_int; l;
          r = List.hd xs }, xs
  | n ->
      let (left, m :: ys) = init l xs (n / 2) in
      let (right, (r :: _ as zs)) = init m ys ((n + 1) / 2) in
      Node { left; right; data = max_int; l; r }, zs
let init (x :: xs) = fst @@ init x xs (List.length xs)

let rec update a b x = function
  | Leaf -> Leaf
  | Node ({ left; right; data; l; r } as t) ->
      if b <= l || r <= a || t.data <= x
      then Node t
      else begin
        if a <= l && r <= b
        then Node { t with data = min x t.data }
        else Node { t with left = update a b x left; right = update a b x right }
      end

let rec query acc i = function
  | Leaf -> acc
  | Node { left; right; data; l; r } ->
      if i < l || r <= i
      then acc
      else query (query (min acc data) i left) i right
let query = query max_int

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let lrcs = Array.init m @@ fun _ -> Scanf.scanf "%d %d %d\n" @@ fun l r c -> l, r, c in
  Array.sort (fun (l, r, _) (l', r', _) -> compare (l', r) (l, r')) lrcs;
  let segtree = 
    Array.fold_right (fun (l, r, c) segtree -> update l (r + 1) (c + query l segtree) segtree) lrcs @@
    update 1 2 0 @@
    init @@
    List.sort_uniq compare @@
    Array.fold_left (fun acc (l, r, _) -> l :: r + 1 :: acc) [1; 2; n] lrcs in
  Printf.printf "%d\n" @@ if query n segtree = max_int then -1 else query n segtree


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

using namespace std;


#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search  >
#define lower(arr,n,fixed) lower_bound(arr,arr+n,fixed)-arr  //Lower value search  >=
#define FOR(i,a,n) for(int i=a; i<(int)n; i++)
#define FORI(i,a,n) for(int i=a; i>=(int)n; i--)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(a) int((a).size())
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0)
#define endl "\n"
#define all(a) a.begin(), a.end()
#define MEMSET(p,i) memset(p,i,sizeof(p))

/* a=target variable, b=bit number to act upon 0-n */
#define BIT_SET(a,b) ((a) |= (1<<(b)))
#define BIT_CLEAR(a,b) ((a) &= ~(1<<(b)))
#define BIT_FLIP(a,b) ((a) ^= (1<<(b)))
#define BIT_CHECK(a,b) ((a) & (1<<(b)))
#define BIT_COUNT(a) (__builtin_popcount(a))

 
/* x=target variable, y=mask */
#define BITMASK_SET(x,y) ((x) |= (y))
#define BITMASK_CLEAR(x,y) ((x) &= (~(y)))
#define BITMASK_FLIP(x,y) ((x) ^= (y))
#define BITMASK_CHECK(x,y) (((x) & (y)) == (y))

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef vector<pii> vpii; 

#define MAX 55
int n;
LL MOD = 1e9+7;

// Matriz identidade
void one(LL a[MAX][MAX])
{
	FOR(i,0,n)
		FOR(j,0,n)
			a[i][j] = (i == j);
}

void selfAdd(LL &a, LL b)
{
	a += b;
	if(a >= MOD)
		a -= MOD;
}

void selfMul(LL &a, LL b)
{
	a *= b;
	a %= MOD;
}

// Multiplica matriz a pela matriz b e guarda resultado em a
void mult(LL a[MAX][MAX], LL b[MAX][MAX])
{
	LL res[MAX][MAX];
	MEMSET(res,0);
	FOR(i,0,n)
		FOR(j,0,n)
			FOR(k,0,n){
				LL x = a[i][k];
				selfMul(x, b[k][j]);
				selfAdd(res[i][j], x);
				// res[i][j] += a[i][k]*b[k][j];
			}
	FOR(i,0,n)
		FOR(j,0,n)
			a[i][j] = res[i][j];
}
// calcula a^n e guarda resultado na matriz res
void POW(LL a[MAX][MAX], LL n, LL res[MAX][MAX])
{
	one(res);
	while(n > 0){
		if(n%2 == 0)
		{
			mult(a,a);
			n /= 2;
		}
		else{
			mult(res,a);
			n--;
		}
	}
}

int main(void)
{
	fastIO();
	LL k;
	cin >> n >> k;

	LL M[MAX][MAX];
	FOR(i,0,n)
		FOR(j,0,n)
			cin >> M[i][j];

	LL R[MAX][MAX];
	POW(M,k,R);

	LL ans = 0;
	FOR(i,0,n){
		FOR(j,0,n){
			selfAdd(ans, R[i][j]);
			// cout << R[i][j] << " ";
		}
		// cout << endl;
	}
	cout << ans << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
string a, b;
int n, m;
int dp[3005][3005];
int par[3005][3005];
int rec(int x, int y){
	if(x == n || y == m)return 0;
	if(dp[x][y] != -1)return dp[x][y];
	int idx = y;
	int ret = rec(x+1, idx);
	while(idx < m && b[idx] != a[x]){
		idx++;
	}
	if(idx < m){
		int temp = 1 + rec(x+1, idx+1);
		if(temp > ret){
			ret = temp;
			par[x][y] = idx;
		}
	}
	return dp[x][y] = ret;
}
int main(){
	cin >> a >> b;
	n = a.size();
	m = b.size();
	for(int i = 0; i <= 3000; i++)
		for(int j = 0; j <= 3000; j++)
			dp[i][j] = -1, par[i][j] = -1;
	
	rec(0,0) ;
	int x = 0, y = 0;
	while(x < n && y < m){
		int temp = y;
		y = par[x][y];
		x++;
		if(y == -1){
			y = temp;
			continue;
		}
		cout << b[y];
		y++;
	}
	
}

Measured memory_bytes: 71040
n = int(input())
# 素数リスト生成
def sieve(x):
    if x < 2: return []
    primes = [i for i in range(x)]
    primes[1] = 0
    for p in primes:
        if p > x ** (1/2): break
        if p == 0: continue
        for np in range(2 * p, x, p): primes[np] = 0
    return [p for p in primes if p != 0]

PS = sieve(10**6)

# 素因数分解
def factorint(x):
  d = {}
  for k in PS:
    if(x % k== 0):
      m = 1
      while(x % (k**m) == 0):
        m += 1
      d[k] = m - 1
      x = x / (k ** (m - 1))
      if x == 1:
        break
  return d

f = factorint(n)
# 10^6より大きい素因数があったときの処理
re = 1
for k, v in f.items():
  re *= k**v
if n // re != 1:
  f[n // re] = 1

# print(f)
s = 1
num = 1
for k, v in f.items():
  s *= (k ** (v + 1) - 1) // (k - 1)
  num *= (v + 1)
loss = 0
for i in range(1, int((-1 + (1 + 4 * n) ** (1/2)) / 2) + 1):
  if n % (i + 1) == 0:
    loss += i
print(s - num - loss)

Measured memory_bytes: 113904
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        s: String,
    }
    println!("{}", (0..s.len()).map(|_| 'x').collect::<String>());
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(){
    int a;
    int b;
    int c;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    if(a<b&&b<c){
     printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				sc.close();
				break;
			}

			int[] total = new int[n];
			int[] start = new int[n];
			boolean[] inside = new boolean[n];
			for (int l = 0; l < n; l++) {
				String d = sc.next();
				String[] t = sc.next().split(":");
				int h = Integer.parseInt(t[0]);
				int m = Integer.parseInt(t[1]);
				int now = h * 60 + m;
				String io = sc.next();
				int id = Integer.parseInt(sc.next());

				if (io.equals("I") && id == 0) {
					// 神がログインした時
					inside[id] = true;
					for (int i = 1; i < inside.length; i++) {
						if (inside[i]) {
							start[i] = now;
						}
					}
				} else if (io.equals("O") && id == 0) {
					// 神がログアウトした時
					inside[id] = false;
					for (int i = 1; i < inside.length; i++) {
						if (inside[i]) {
							total[i] += now - start[i];
						}
					}
				} else if (io.equals("I") && id != 0) {
					// 人がログインした時
					inside[id] = true;
					if (inside[0]) {
						start[id] = now;
					}
				} else if (io.equals("O") && id != 0) {
					// 人がログアウトした時
					inside[id] = false;
					if (inside[0]) {
						total[id] += now - start[id];
					}
				}
			}

			int max = 0;
			for (int i = 1; i < total.length; i++) {
				max = Math.max(max, total[i]);
			}
			System.out.println(max);
		}
	}
}

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

int main(){
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    s = '1' + s + '1';
    vector<unsigned long> kyokai({0});
    for(unsigned long i = 0; i <= N; ++i)if(s[i] != s[i + 1])kyokai.push_back(i);
    kyokai.push_back(N);
    auto M = kyokai.size();
    unsigned long ans{0};
    for(unsigned long i = 0; i < M; i += 2)ans = max(ans, kyokai[min(i + 2 * K + 1, M - 1)] - kyokai[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1524
import itertools
import math


LIM = 50
N,K = list(map(int,input().split(" ")))

Xs = []
Ys = []

dots = []
for _ in range(N):
    x,y = (map(int,input().split(" ")))
    Xs.append(x)
    Ys.append(y)
    dots.append((x,y))

Xs.sort()
Ys.sort()

ans = -1
for x1 in range(N):
    for x2 in range(x1 + 1,N):
        for y1 in range(N):
            for y2 in range(y1 + 1,N):
                cot = 0
                underX = Xs[x1]
                upperX = Xs[x2]
                underY = Ys[y1]
                upperY = Ys[y2]

                for k in range(N):
                    if   underX<= dots[k][0] <= upperX and underY <= dots[k][1] <= upperY:
                        cot += 1
                if cot >= K:
                    S = (upperX - underX) * (upperY - underY)
                    if ans == -1:
                        ans = S
                    ans = min( ans ,S)
print(ans)

Measured memory_bytes: 51736
n,m=map(int,input().split())
h=list(map(int,input().split()))
l1=[]
l2=[]
l=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  if a>b:
    c=a
    a=b
    b=c
  k=[a,b]
  l1.append(k)
  c=a
  a=b
  b=c
  k=[a,b]
  l2.append(k)
l1.sort()
l2.sort(reverse=True)
for i in l1:
  if h[i[0]-1]<=h[i[1]-1]:
    l[i[0]-1]+=1
for i in l2:
  if h[i[0]-1]<=h[i[1]-1]:
    l[i[0]-1]+=1
print(l.count(0))

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

#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
const ll INF = 1LL << 60;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;
ll primeFactors(long long n) {
    int sum = 0;
    map<int, int> cnt;
    while (n % 2 == 0) {
        sum++;
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            sum++;
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        sum++;
        cnt[n]++;
    }
    return sum;
}

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
signed main() {
    int n;
    cin >> n;
    vector<int> as(n);
    REP(i, n) { cin >> as[i]; }
    int q;
    cin >> q;
    vector<int> k(q);
    REP(i, q) { cin >> k[i]; }
    REP(i, q) {
        cout << lower_bound(as.begin(), as.end(), k[i]) - as.begin() << " ";
        cout << upper_bound(as.begin(), as.end(), k[i]) - as.begin() << endl;
    }
}


Measured memory_bytes: 4156
import java.util.Scanner;
class Main {
    public static void main(String[] args){ 
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a<=b && a<=c){
            if(b<=c){
                System.out.println(a+" "+b+" "+c);
            }else{
                System.out.println(a+" "+c+" "+b);
            }
        }else if(b<=a && b<=c){
            if(c<=a){
                System.out.println(b+" "+c+" "+a);
            }else{
                System.out.println(b+" "+a+" "+c);
            }
        }else if(c<=a && c<=b){
            if(a<=b){
                System.out.println(c+" "+a+" "+b);
            }else{
                System.out.println(c+" "+b+" "+a);
            }
        }
    }
}

Measured memory_bytes: 26268
#include<stdio.h>
typedef long long ll;
int main(){
    int n;
    int a[200005];
    scanf("%d",&n);
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    ll ans = 0;
    for(i=0;i<n-1;i++){
        if(a[i]-a[i+1]>0){
            ans = ans+(a[i]-a[i+1]);
            a[i+1] = a[i];
        }
    }
    printf("%lld\n",ans);
    return 0;
}

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

int main(){
  int n;string s;cin>>n>>s;
  int x=0,mx=0;
  for(int i=0;i<n;i++){
    if(s[i]=='I')x++;
    else if(s[i]=='D')x--;
    mx=max(mx,x);
  }
  cout<<mx;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define itr(macro_v,i) macro_v.begin()+i
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string X,Y;
    cin >>X;
    if (X == "Sunny"){
        Y = "Cloudy";
    }else if(X == "Cloudy"){
        Y= "Rainy";
    }else if(X == "Rainy"){
        Y = "Sunny";
    }
    cout <<Y<<endl;
    


    return 0;
}

Measured memory_bytes: 256
n=int(input())
lists=list(map(int,input().split()))
uselists=[]
for _ in range(n):
    uselists.append(lists[_]-_-1)
uselist=sorted(uselists)
if n%2==0:
    num1=int(n/2-1)
    num2=int(n/2)
    numbers=min(uselist[num1],uselist[num2])
    
if n%2!=0:
    num1=int((n-1)/2)
    numbers=uselist[num1] 
ans=0
for x in range(n):
    ans+=abs(uselist[x]-numbers)
print(ans)


Measured memory_bytes: 101204
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=3e3+5;
int n;
double ans,p[N],dp[N][N];//dp[i][j]:前i个里j个正面 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	scanf("%lf",&p[i]);
	dp[0][0]=1;
	for(int i=1;i<=n;++i)
	{
		dp[i][0]=dp[i-1][0]*(1-p[i]);
		for(int j=1;j<=i;++j)
		{
			dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
		} 
	}
	for(int j=n-n/2;j<=n;++j)
	ans+=dp[n][j];
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 68992
import numpy as np
n,k,q = map(int, input().split())
a = [int(input()) for i in range(q)]
#cnt = [0 for _ in range(n)]
win = [0 for _ in range(n)]
#p = np.array([k for _ in range(n)])
for ai in a:
  win[ai-1] += 1
#print(win)

for w in win:
  if k-q+w<=0: print('No')
  else: print('Yes')

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = int(1e9) + 7;

int n, k;
int d[2001][2001], sum[2001][2001];
int p2[2002];

inline void modAdd(int &x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
}

int main() {
    p2[0] = p2[1] = 1;
    for (int i = 2; i <= 2001; ++i) {
        p2[i] = 2 * p2[i - 1] % MOD;
    }
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= i; ++j) {
            d[i][j] = 0;
            if (n + 1 - i == k) {
                d[i][j] = p2[i - 1];
            }
            modAdd(d[i][j], sum[i - 1][j - 1]);
            if (i > j) {
                modAdd(d[i][j], d[i - 1][j]);
            }
        }
        sum[i][0] = 0;
        for (int j = 1; j <= i; ++j) {
            sum[i][j] = sum[i][j - 1];
            modAdd(sum[i][j], d[i][j]);
        }
    }
    cout << d[n][n] << endl;
    return 0;
}


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

int n, x;
int m[100];
int ans;
int min = 100000009;

int main(){
  scanf("%d%d", &n, &x);
  for(int i = 0; i < n; i++){
    int m;
    scanf("%d", &m);
    ans += m;
    min = std::min(min, m);
  }
  printf("%d\n", n + (x-ans)/min);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

// 最長増加部分列の長さを求める
int LIS(const vector<long long> &a) {
	int N = (int)a.size();
	vector<long long> dp(N, INF);
	for (int i = 0; i < N; ++i) {
		// dp[k] >= a[i] となる最小のイテレータを見つける
		auto it = upper_bound(dp.begin(), dp.end(), a[i]);

		// そこを a[i] で書き換える
		*it = a[i];
	}

	// dp[k] < INF となる最大の k に対して k+1 が答え
	// それは dp[k] >= INF となる最小の k に一致する
	return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}

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

Measured memory_bytes: 1792