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


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

    int N = s.size();
    long long ans = 0;
    for( int i = 0; i < N-2; ++i ){
        if( s.substr(i,3) == "ABC" )
        {
            int idx_A = i-1;
            long long count_A = 0;
            // AAAAABC... のようなケース
            while( idx_A >= 0 and s[idx_A] == 'A' ){
                ++count_A;
                --idx_A;
            }

            int idx_ABC = i+3;
            long long count_ABC = 1, sum = 1;
            // ABCABCABC... のようなケース
            while( idx_ABC < N-2 and s.substr(idx_ABC,3) == "ABC" ){
                ++count_ABC;
                idx_ABC += 3;
                sum += count_ABC;
            }
            
            int idx_BC = idx_ABC;
            long long count_BC = 0;
            // ...ABCBCBC のようなケース
            while( idx_BC < N-1 and s.substr(idx_BC,2) == "BC" ){
                ++count_BC;
                idx_BC += 2;
            }

            ans += sum + count_A*(count_ABC+count_BC) + count_ABC*count_BC;
            for( int j = 1; j <= count_ABC+count_A; ++j ) s[idx_BC-j] = 'A';
            s[idx_BC-count_ABC-count_A-1] = 'C';
            i = idx_BC-1;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<vector<int> > G(n);
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  
  vector<int> mx(n,0);
  function<void(int, int, int)> dfs1=
    [&](int v,int p,int d){
      chmax(mx[v],d);
      for(int u:G[v]){
        if(u==p) continue;
        dfs1(u,v,max(v,mx[v]));
      }      
    };
  dfs1(0,-1,0);
  
  vector<map<int, int> > dp(n);
  function<int(int, int, int)> dfs4=
    [&](int v,int p,int d){
      if(dp[v].count(d)) return dp[v][d];
      int &res=dp[v][d];
      res=0;
      for(int u:G[v]){
        if(u==p||u>d) continue;
        res+=1+dfs4(u,v,d);
      }
      return res;
    };
  
  vector<int> ans(n,0);
  function<void(int, int)> dfs2=
    [&](int v,int p){      
      for(int u:G[v]){
        if(u==p) continue;
        dfs2(u,v);
      }
      if(p<0) return;
      ans[v]=1+dfs4(v,p,mx[v]);
      if(v<mx[p]) ans[v]-=1+dfs4(v,p,mx[p]);
    };
  dfs2(0,-1);
  
  function<void(int, int)> dfs3=
    [&](int v,int p){
      for(int u:G[v]){
        if(u==p) continue;
        ans[u]+=ans[v];
        dfs3(u,v);
      }
    };
  dfs3(0,-1);

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


Measured memory_bytes: 51584
def flatten_2d(data):
    for block in data:
        for elem in block:
            yield elem
            
h,w = map(int,input().split())

List=[input() for i in range(h)]

#print(List)

a = list(flatten_2d(List))

#print(list(flatten_2d(List)))


if a.count("#")==(h+w-1):
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if(N<10) cout << N << endl;
  else if(N<100) cout << 9 << endl;
  else if(N<1000) cout << N-90 << endl;
  else if(N<10000) cout << 909 << endl;
  else if(N<100000) cout << N-9090 << endl;
  else if(N==100000) cout << 90909 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i];
    int l=0, r=n-1;
    for(int i=0; i<n; ++i){
        if(!(i%2)){
            b[l] = a[n-i-1];
            l++;
        }
        else{
            b[r] = a[n-i-1];
            r--;
        }
    }
    for(auto aaa: b){
        cout << aaa << " ";
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 6388
N = int(input().strip())
arrayH = list(map(int, input().strip().split(' ')))
ans = 1
for i in range(N - 1):
        yn = True
        for j in range(i+1):
                if arrayH[j] > arrayH[i+1]:
                        yn = False
        if yn:
                ans = ans + 1
print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a[301], dp[301][300*300+1000], dpbuf[301][300*300+1000];
ll mod = 998244353;

ll kumi2(ll n){
	if(n <= 1){return 0;}
	ll r = 1;
	for(ll i = 1; i <= n; i++){r *= 2; r %= mod;}
	return (r-2)%mod;
}

ll kumi3(ll n){
	ll r = 1;
	for(ll i = 1; i <= n; i++){r *= 3; r %= mod;}
	return r;//(r-(3*kumi2(n))%mod-3)%mod;
}

int main(){
	cin >> n;
	ll suma = 0;
	for(ll i = 1; i <= n; i++){cin >> a[i]; suma += a[i];}
	
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for(ll i = 1; i <= n; i++){
		for(ll j = 300*i; j >= 0; j--){
			dp[i][j+a[i]] += dp[i-1][j];
			dp[i][j+a[i]] %= mod;
			dp[i][j] += 2*dp[i-1][j];
			dp[i][j] %= mod;
		}
	}
	
	//for(ll i = 0; i <= 20; i++){cout << i << " " << dp[n][i] << endl;}
	
	ll notans = 0;
	for(ll j = (suma+1)/2; j <= suma; j++){
		notans += dp[n][j];
		notans %= mod;
	}
	//cout << notans << endl;
	
	if(suma%2 == 0){
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;
		for(ll i = 1; i <= n; i++){
			for(ll j = 300*i; j >= 0; j--){
				dp[i][j+a[i]] += dp[i-1][j];
				dp[i][j+a[i]] %= mod;
				dp[i][j] += dp[i-1][j];
				dp[i][j] %= mod;
			}
		}
		//cout << dp[n][suma/2] << endl;
		notans -= dp[n][suma/2];
	}

	//cout << kumi3(n) << endl;
	//cout << notans << endl;
	cout << (mod+kumi3(n)-(3*notans)%mod)%mod << endl;
	return 0;
}


Measured memory_bytes: 215296
#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
using namespace std;
char a[maxn];

int main()
{
    cin >> a;
    for (int i = 0; i < strlen(a); i++)
        if (i % 2 == 0)
            cout << a[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main()
{
	int month, day, dotw;
    int v[13] = {0, 4, 7, 1, 4, 6, 2, 4, 7, 3, 5, 1, 3};
    while(1){
        scanf("%d %d", &month, &day);
        if (month == 0) break;
        dotw = v[month] - 1 + (day % 7);
        if (dotw > 7) dotw -= 7;
        if (dotw == 1) printf("Monday\n");
        if (dotw == 2) printf("Tuesday\n");
        if (dotw == 3) printf("Wednesday\n");
        if (dotw == 4) printf("Thursday\n");
        if (dotw == 5) printf("Friday\n");
        if (dotw == 6) printf("Saturday\n");
        if (dotw == 7) printf("Sunday\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 0;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, m;
int a[200000];
int b[200000];
vector<int>c[200000];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int u = read();
		a[u]++;
		b[u % m]++;
	}
	for (int i = 1; i <= 100000; i++) {
		if (a[i] > 0) c[i % m].push_back(a[i]);
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		if (i == (m - i) % m) {
			ans += b[i] / 2;
			b[i] = 0;
			continue;
		}
		if ((m - i) - i > 0) {
			ans += min(b[i], b[m - i]);
			//余りのWAがMの時に成立
			//小さいほうは全部使う
			int t = min(b[i], b[m - i]);
			b[i] = t; b[m - i] = t;
		}
	}
	b[0] = 0;
	for (int i = 0; i < m; i++) {
		if (i == (m - i) % m) continue;
		int res = 0;
		for (int j = 0; j < c[i].size(); j++) {
			if (b[i] > 0 && c[i][j] % 2 == 1) {
				b[i]--;
				c[i][j]--;
			}
			res += c[i][j] / 2;
		}
		res -= ceil(b[i] / 2.0);
		ans += res;
	}
	cout << ans << endl;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

static const ll INF = 1e15;

static const ll mod = 1e9 + 7;

int main() {
	ll h,w,k;
    cin >> h >> w >> k;
    ll x1, y1, x2, y2;
    cin >> y1>>  x1 >> y2 >> x2;
    x1--; y1--;
    x2--; y2--;
    vector<vector<bool>> grid(h, vector<bool>(w, true));
    rep(y, h) {
        string s;
        cin >> s;
        rep(x, w) {
            if (s[x] == '@') {
                grid[y][x] = false;
            }
        }
    }
    vector<vector<vector<ll>>> costs(h, vector<vector<ll>>(w, vector<ll>(4, INF)));
    priority_queue<t4, vector<t4>, greater<t4>> qs;
    for (int i = 0; i < 4; i++) {
        qs.emplace(0, x1, y1, i);
        costs[y1][x1][i] = 0;
    }
    constexpr P shifts[4] = { {1,0},{-1,0},{0,1},{0,-1} };
    while (!qs.empty()) {
        ll x, y, d, c;
        tie(c, x, y, d) = qs.top(); qs.pop();
        for (int i = 0; i < 4; i++) {
            if (d == i) continue;
            auto ncost = c % k ? (c / k + 1) * k : c;
            if (costs[y][x][i] <= ncost) continue;
            costs[y][x][i] = ncost;
            qs.emplace(ncost, x, y, i);
        }
        {
            auto nx = x + shifts[d].first;
            auto ny = y + shifts[d].second;
            if (nx < 0 || nx >= w) continue;
            if (ny < 0 || ny >= h) continue;
            if (!grid[ny][nx]) continue;
            ll ncost = c + 1;
            if (costs[ny][nx][d] <= ncost) continue;
            costs[ny][nx][d] = ncost;
            qs.emplace(ncost, nx, ny, d);
        }
    }
    ll low = INF;
    for (int i = 0; i < 4; i++) {
        auto c = costs[y2][x2][i];
        if (c != INF) {
            auto ncost = c % k ? (c / k + 1) : c / k;
            low = min(low, ncost);
        }
    }
    if (low == INF) {
        cout << -1 << endl;
    }
    else {
        cout << low << endl;
    }
	return 0;
}
	

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

typedef pair <int, int> ii;

const int Maxn = 2005;

int n, m;
bool E[Maxn][Maxn];
int col[Maxn];
bool dp[Maxn];
vector <int> seq;
int res = Maxn * Maxn;

bool Solve(int v, int c)
{
	if (col[v]) return col[v] == c;
	col[v] = c; seq.push_back(v);
	for (int i = 1; i <= n; i++) if (!E[v][i])
		if (!Solve(i, -c)) return false;
	return true;
}

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int a, b; scanf("%d %d", &a, &b);
		E[a][b] = E[b][a] = true;
	}
	for (int i = 1; i <= n; i++)
		E[i][i] = true;
	dp[0] = true;
	for (int i = 1; i <= n; i++) if (col[i] == 0) {
		seq.clear();
		if (!Solve(i, -1)) { printf("-1\n"); return 0; }
		int a = 0, b = 0;
		for (int j = 0; j < seq.size(); j++)
			if (col[seq[j]] == -1) a++;
			else b++;
		for (int i = Maxn - 1; i >= 0; i--) if (dp[i]) {
			dp[i] = false;
			if (i + a < Maxn) dp[i + a] = true;
			if (i + b < Maxn) dp[i + b] = true;
		}
	} 
	for (int i = 0; i <= n; i++) if (dp[i]) {
		int a = i, b = n - i;
		res = min(res, a * (a - 1) / 2 + b * (b - 1) / 2);
	}
	printf("%d\n", res);
	return 0;
}

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

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var S = Console.ReadLine();

            if (S[S.Length - 1] == 's')
                Console.WriteLine($"{S}es");
            else
                Console.WriteLine($"{S}s");
        }
    }
}


Measured memory_bytes: 25864
#include<iostream>
#include<algorithm>
#define MONTH 12
using namespace std;
int main() {
	long l;
	while (cin >> l){
		if (l == 0)break;
		int n = 13;
		long sum = 0;
		for (int i = 0; i < MONTH; i++){
			long long a, b; cin >> a >> b;
			sum += a - b;
			if (sum >= l){
				n = min(n, i + 1);
			}
		}
		if (n == 13){
			cout << "NA";
		}
		else cout << n;
		cout << endl;
	}
	return 0;
}

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

int main(){
        ll n;
        scanf("%lld", &n);

        ll open[n][10];
        for(ll i=0; i<n; i++) for(ll j=0; j<10; j++) scanf("%lld", &open[i][j]);

        ll earn[n][11];
        for(ll i=0; i<n; i++) for(ll j=0; j<11; j++) scanf("%lld", &earn[i][j]);

        ll mx = -1e9;
        for(ll i=1; i<1024; i++){
                ll sm = 0;
                for(ll j=0; j<n; j++){
                        ll cnt = 0;
                        for(ll k=0; k<10; k++) cnt += ((i>>k)&open[j][k]);
                        sm += earn[j][cnt];
                }
                mx = sm>mx? sm:mx;
        }
        printf("%lld\n", mx);
        return 0;
}

Measured memory_bytes: 256
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, 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;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = 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 < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = 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 < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
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();
    }
}
fn solve() {
    let (n, t) = get!(usize, u64);
    let ct = get!(u64, u64; n);

    let ans = ct
        .iter()
        .filter(|&&(_, t1)| t1 <= t)
        .map(|t| t.0)
        .min()
        .map(|c| c.to_string())
        .unwrap_or("TLE".into());

    println!("{}", ans);
}


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

typedef long long ll;
#define gc getchar()
inline int read(){
	int x=0,f=1;char c=gc;
	for(;c<48||c>57;c=gc)
		if(c=='-')f=-1;
	for(;c>47&&c<58;c=gc)
		x=x*10+c-48;
	return x*f;
}
#define io read()

#define maxn 2005
int n,m,q,a[maxn];

inline void init(){
	n=io;m=io;q=io;
	for(int i=1;i<=n;++i)a[i]=io;
}

inline int check(int d){
	for(int i=1;i<=n;++i){
		int s0=0,s1=0,cnt=0;
		for(int j=1;j<=n;++j){
			if(a[j]>a[i]+d)++s0;
			else if(a[j]>=a[i])++s1;
			else{
				cnt+=max(0,min(s1+s0-m+1,s1));
				s1=s0=0;				
			}
		}
		cnt+=max(0,min(s1+s0-m+1,s1));
		if(cnt>=q)return 1;
	}
	return 0;
}

inline void solve(){
	int l=0,r=1e9,mid,ans;
	while(l<=r){
		mid=l+r>>1;
		if(check(mid)){
			ans=mid;
			r=mid-1;
		}else{
			l=mid+1;
		}
	}
	printf("%d\n",ans);
}

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

Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
ans=0
i=0
while i+1<=N-1:
  if a[i]!=a[i+1]:
    i+=1
  else:
    tmp=1
    while i+1<=N-1 and a[i]==a[i+1]:
      tmp+=1
      i+=1
    i+=1
    ans+=(tmp//2)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
int math[5][4][11]={0},b,f,r,v,n;
   cin>>n;
   for(int i=0;i<n;i++){
       cin>>b>>f>>r>>v;
       math[b][f][r]+=v;
   }for(int j=1;j<=4;j++){//棟
       for(int s=1;s<=3;s++){//階
           for(int g=1;g<=10;g++){//部屋
			   cout<<" "<<math[j][s][g];

           }
		   cout<<endl;
       }
	   if(j!=4){
	   cout<<"####################"<<endl;
	   }
   }



	return 0;
}


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

#define MAX 100000

typedef long long ll;

ll T[MAX];
int n, k;

int check(ll p)
{
    int v = 0;
    for (int i = 0; i < k; i++)
    {
        ll s = 0;
        while (s + T[v] <= p)
        {
            s += T[v];
            v++;
            if (v == n)
                return n;
        }
    }
    return v;
}

int solve()
{
    ll left = 0;
    ll right = 100000 * 10000;
    ll mid;
    while (right - left > 1)
    {
        mid = (left + right) / 2;
        int v = check(mid);
        if (v >= n)
            right = mid;
        else
            left = mid;
    }
    return right;
}

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> T[i];
    ll ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
const Int MAX = 2020;
const Int MOD = 1e6;

Int co[MAX][MAX]={};
signed main(){
  Int n;
  cin>>n;
  vector< vector<Int> > G(n);
  vector<Int> indeg(n,0);
  for(Int i=1;i<n;i++){
    Int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    indeg[b]++;
  }
  co[0][0]=1;
  for(Int i=1;i<MAX;i++){
    co[i][0]=1;
    for(Int j=1;j<MAX;j++){
      co[i][j]=co[i-1][j-1]+co[i-1][j];
      if(co[i][j]>=MOD) co[i][j]-=MOD;
    }
  }

  Int rt=min_element(indeg.begin(),indeg.end())-indeg.begin();
  vector<Int> dp(n),sz(n);
  MFP([&](auto dfs,Int v)->Int{
        sz[v]=0;
        dp[v]=1;
        for(Int u:G[v]){
          Int num=dfs(u);
          dp[v]=dp[v]*dp[u]%MOD*co[sz[v]+num][num]%MOD;
          sz[v]+=num;
        }
        return sz[v]+=1;
      })(rt);

  cout<<dp[rt]<<endl;
  return 0;
}



Measured memory_bytes: 35072
import sys
sys.setrecursionlimit(10 ** 9)

from bisect import bisect_left

N = int(input())
A = list(map(int, input().split()))

G = [[] for _ in range(N)]

for _ in range(N - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)

root = 0
stack = [root]
visited = set()
visited.add(root)
done = set()
vs = []

ans = [0] * N
memo = [None] * N
memo[root] = (0, A[root])

INF = 10 ** 10
dp = [INF] * N

while stack:
    now_ = stack[-1]
    if now_ in done:
        j, a = memo[now_]
        dp[j] = a
        stack.pop()
        vs.append(now_)
    else:
        for next_ in G[now_][::-1]:
            if next_ in visited:
                continue
            visited.add(next_)
            stack.append(next_)
        done.add(now_)

        tmp = bisect_left(dp, A[now_])
        memo[now_] = (tmp, dp[tmp])
        dp[tmp] = A[now_]
        ans[now_] = bisect_left(dp, INF)

# print (vs)
print (*ans, sep = '\n')

Measured memory_bytes: 99084
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

N, M, Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    ai, bi, ci, di = map(int, input().split())
    a[i], b[i], c[i], d[i] = ai, bi, ci, di

dump(N, M, Q)
dump(a)
dump(b)
dump(c)
dump(d)

ans = 0


for A in it.combinations_with_replacement(range(1, M+1), N):
    A = list(A)
    x = [0]

    for i in range(Q):
        if A[b[i] - 1] - A[a[i] - 1] == c[i]:
            x.append(d[i])
    ans = max(ans, sum(x))
print(ans)


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

struct  DICE {
    int Top;
    int Bottom;
    int Front;
    int Back;
    int Left;
    int Right;
    void roll(char S) {
        if ('N'==S) {
            swap(Back, Top);
            swap(Top, Front);
            swap(Front, Bottom);
        } else if('S'==S) {
            swap(Back, Bottom);
            swap(Bottom, Front);
            swap(Front, Top);
        } else if('W'==S) {
            swap(Right, Bottom);
            swap(Bottom, Left);
            swap(Left, Top);
        } else if('E'==S) {
            swap(Left, Bottom);
            swap(Bottom, Right);
            swap(Right, Top);
        }
        return;
    }
};

int main() {
    DICE D1, D2;
    cin >>D1.Top >>D1.Front >>D1.Right >>D1.Left >>D1.Back >>D1.Bottom;
    cin >>D2.Top >>D2.Front >>D2.Right >>D2.Left >>D2.Back >>D2.Bottom;
    for (int i=0; i<2; i++) {
        if (D1.Front==D2.Front)
            break;
        D2.roll('E');
        for (int i=0; i<4; i++) {
            if (D1.Front==D2.Front)
                break;
            D2.roll('S');
        }
    }
    if (D1.Front!=D2.Front) {
        cout <<"No" <<endl;
        return 0;
    }
    for (int i=0; i<4; i++) {
        if (D1.Top==D2.Top)
            break;
        D2.roll('E');
    }
    if (D1.Top!=D2.Top) {
        cout <<"No" <<endl;
        return 0;
    }
    if ((D1.Back==D2.Back)&&(D1.Bottom==D2.Bottom)&&(D1.Left==D2.Left)&&(D1.Right==D2.Right))
        cout <<"Yes" <<endl;
    else
        cout <<"No" <<endl;
    return 0;
}


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

int main() {
  	int X;
  	cin >> X;
  	int count500 = 0;
  	int count5 = 0;
  	while (X > 499){
      	count500++;
      	X -= 500;
    }
  	while (X > 4){
      	count5++;
      	X -= 5;
    }
  	cout << count500 * 1000 + count5 * 5 << endl;
}  

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
signed main(){
    int H, N;
    cin >> H >> N;
    int sum = 0;
    int A[N];
    for(int i = 0;i < N;i++){
        cin >> A[i];
        sum += A[i];
    }
    if(sum < H)cout << "No";
    else cout << "Yes";
}

Measured memory_bytes: 1024
#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>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main(void)
{
	ll a, b;
	cin >> a >> b;
	map<ll, int> prime;
	for(ll i = 2; i * i <= a; i++) {
		int count = 0;
		while(a % i == 0) {
			a /= i;
			count++;
		}
		if(count)prime[i] = 1;
	}
	if(a != 1) {
		prime[a] = 1;
	}
	
	for(ll i = 2; i * i <= b; i++) {
		int count = 0;
		while(b % i == 0) {
			b /= i;
			count++;
		}
		if(count){
			if(prime[i] == 0) prime[i] = 1;
			else prime[i]++;
		}
	}
	if(b != 1) {
		if(prime[b] == 0) prime[b] = 1;
		else prime[b]++;
	}
	ll ans = 	1;
	auto itr = prime.begin();
	for(itr = prime.begin(); itr != prime.end(); itr++) {
		if(itr->second == 2) {
			// cout << itr->first << " ";
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    V = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]

    ans = 0
    for i in range(N):
        if V[i] > C[i]:
            ans += V[i] - C[i]
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main (){
  int a,b;
  cin>>a>>b;
  int flag = 0;
  int i;
  while(b>0&&a%500!=0){
    a--;
    b--;
  }
 // cout<<a;
  if(a%500==0)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorders
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = nk[0];
			int k = nk[1];
			var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

			var dp = new bool[k + 1];
			for (int i = 0; i < k; i++) {
				if (dp[i]) {
					continue;
				}

				for (int j = 0; j < n; j++) {
					if (i + a[j] <= k) {
						dp[i + a[j]] = true;
					}
				}
			}

			if (dp[k]) {
				Console.WriteLine("First");
			} else {
				Console.WriteLine("Second");
			}
		}
	}
}

Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int max = 0;
    int min = 123;
    for(int i = 0; i < 5; i++ ){
      int a = sc.nextInt();
      if(a > max){ max = a; }
      if(a < min){ min = a; }
    }
    int k = sc.nextInt();
    if(max - min > k) {
      System.out.println(":(");
    } else {
      System.out.println("Yay!");
    }
  }
}


Measured memory_bytes: 22868
L=list()
R=list()
N,M=map(int,input().split())
for i in range(N):
  a,b=map(int,input().split())
  L.append([a,b])
for i in range(M):
  a,b=map(int,input().split())
  R.append([a,b])
ans=[0]*M
for i in range(N):
  K=[0]*M
  a,b=L[i]
  for j in range(M):
    K[j]=abs(a-R[j][0])+abs(b-R[j][1])
  s=min(K)
  q=K.index(s)
  print(q+1)

Measured memory_bytes: 9224
import itertools
N,M,R=map(int,input().split())
r=[int(i)-1 for i in input().split()]
P=[set() for i in range(N)]
for i in range(M):
    A,B,C=map(int,input().split())
    P[A-1].add((B-1,C))
    P[B-1].add((A-1,C))
p=[[0 for i in range(R)] for i in range(R)]
def dijkstra(s):
    d=[10**9 for i in range(N)]
    d[s]=0
    Q=set(range(N))
    while(len(Q)>0):
        u=list(Q)[0]
        for v in Q:
            if d[v]<d[u]:
                u=v
        Q-=set([u])
        for v in P[u]:
            if d[v[0]]>d[u]+v[1]:
                d[v[0]]=d[u]+v[1]
    return d
for i in range(R):
    L=dijkstra(r[i])
    for j in range(R):
        p[i][j]=L[r[j]]
S=list(itertools.permutations(range(R),R))
ans=10**9
for sg in S:
    tmp=0
    for i in range(R-1):
        tmp+=p[sg[i]][sg[i+1]]
    if tmp<ans:
        ans=tmp
print(ans)


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


mint mpow(int x, int n){
  if(n==0)return 1;

  mint y = mpow(x, n/2);
  y *= y;

  if(n%2==1) y *=x;
  return y;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

map<int,mint> mem;


int n;

mint dfs(int x){
  if(x==0)return 1;
  if(x<3)return 0;

  if(mem.find(x) != mem.end()){
    return mem[x];
  }

  mint ret=0;
  FOR(i,3,n+1){
    ret += dfs(x-i);
  }
  mem[x]=ret;
  return mem[x];
}

int main(){
  cin >> n;
  cout << dfs(n).x << endl;

  // for(auto v: mem){
  //   cout << v.first << " " << v.second.x << endl;
  // }
}



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

int main()
{
	int n, m;
	std::cin >> n >> m;
	
	std::vector<bool> vc(n - 1);
	int a = m;
	for (int i = m; i >= 1; i--) {
		do {
			a++;
		} while (vc[a - i] || vc[n - a + i] || a - i == n - a + i);
		vc[a - i] = true;
		vc[n - a + i] = true;
		std::cout << i << ' ' << a << '\n';
	}
	std::cout << std::flush;
	
	return 0;
}


Measured memory_bytes: 3236
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define sc(x) scanf("%d", &x)
#define sc2(x, y) scanf("%d%d", &x, &y)
#define sc3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define sc4(x, y, z, t) scanf("%d%d%d%d", &x, &y, &z, &t)
#define print(x) printf("%d ", x)
#define println(x) printf("%d\n", x)
#define println2(x, y) printf("%d %d\n", x, y)
#define println3(x, y, z) printf("%d %d %d\n", x, y, z)
#define println4(x, y, z, t) printf("%d %d %d %d\n", x, y, z, t)
#define mp make_pair
#define pb push_back
#define ft first
#define sd second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define endl '\n'                           // CommentInInteractive
#define DB(x) cerr << #x << " = " << x << endl

const ld eps = 1e-6;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;

void solve() {
    string s;
    cin >> s;
    if (sz(s) & 1) {
        cout << "No" << endl;
        return;
    }
    for (int i = 0; i < sz(s) - 1; i += 2) {
        if (s[i] == 'h' && s[i + 1] == 'i') continue;
        else {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

//#define FILES
//#define TIME

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

#ifdef FILES
    freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    auto start = chrono::high_resolution_clock::now();
    solve();
    auto stop = chrono::high_resolution_clock::now();

#ifdef TIME
    cerr << chrono::duration_cast <chrono::milliseconds> (stop - start).count() << " ms\n";
#endif
    return 0;
}

Measured memory_bytes: 256
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
narr = lambda d, f: narr(d[:-1], lambda: [f() for _ in range(d[-1])]) if d else f() # narr((2,3), int)
mod = 1000000007
sys.setrecursionlimit(1000000)

H, W = rl()
C = rl()
D = rl()
M = []
for i in range(H):
	s = rs()
	M.append(s)

start = tuple([C[0]-1, C[1]-1])
end = tuple([D[0]-1, D[1]-1])

queue = deque()
queue.append((start, 0))
visited = narr((H, W), lambda: float('inf'))
visited[start[0]][start[1]] = 0

ds = [(1,0),(-1,0),(0,1),(0,-1)]
while queue:
	n, d = queue.popleft()
	if n == end:
		print(d)
		exit()
	i, j = n
	if visited[i][j] != d:
		continue
	nd = d
	for di, dj in ds:
		ni, nj = i+di, j+dj
		if not (0 <= ni < H and 0 <= nj < W): continue
		if M[ni][nj] == '#': continue
		if nd < visited[ni][nj]:
			queue.appendleft(((ni,nj), nd))
			visited[ni][nj] = nd
	nd = d+1
	for di in range(-2, 3):
		for dj in range(-2, 3):
			if (di, dj) == (0,0): continue
			ni, nj = i+di, j+dj
			if not (0 <= ni < H and 0 <= nj < W): continue
			if M[ni][nj] == '#': continue
			if nd < visited[ni][nj]:
				queue.append(((ni,nj), nd))
				visited[ni][nj] = nd
print(-1)


Measured memory_bytes: 103084
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 300010, LOG=20;

ll n, X, Y, Z, x, y, t, a, b, ans, sum, to_add;
pll A[MAXN];
ll B[MAXN], C[MAXN];
multiset<ll> st;

void add(ll x, bool rem){
	sum+=x;
	st.insert(x);
	if (!rem) return ;
	sum-=*st.begin();
	st.erase(st.begin());
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>X>>Y>>Z;
	n=X+Y+Z;
	for (int i=1; i<=n; i++) cin>>a>>b>>x, to_add+=x, A[i]={a-x, b-x};
	sort(A+1, A+n+1, [](pll i, pll j){
		return i.first+j.second>i.second+j.first;
	});
	
	for (int i=1; i<=n; i++) add(A[i].first, i>X), B[i]=sum;
	sum=0;
	st.clear();
	for (int i=n; i; i--) C[i]=sum, add(A[i].second, i<=n-Y);
		
	for (int i=X; i+Y<=n; i++) ans=max(ans, B[i]+C[i]+to_add);
	cout<<ans<<'\n';
	
	
	return 0;
}


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

const int INF = 19191919;

using vi = vector<int>;

struct SegTree {
    int n;
    vector<vi> dat;
    // 初期化
    SegTree(int _n) {
        n = 1;
        while (n < _n) n *= 2;
        dat = vector<vi>(2 * n - 1);
    }

    vi merge(const vi& a, const vi& b) {
        int A = a.size(), B = b.size();
        int ai = 0, bi = 0;
        vi ret;
        while (ai < A || bi < B) {
            bool isA = true;
            if (ai == A)
                isA = false;
            else if (bi == B)
                isA = true;
            else {
                if (a[ai] > b[bi]) isA = false;
            }

            if (isA)
                ret.pb(a[ai++]);
            else
                ret.pb(b[bi++]);
        }
        return ret;
    }

    void init(const vi& v) {
        int V = v.size();
        rep(i, V) dat[i + n - 1] = {v[i]};
        for (int i = V + n - 1; i < 2 * n - 1; ++i) dat[i] = {0};

        for (int i = n - 2; i >= 0; --i)
            dat[i] = merge(dat[2 * i + 1], dat[2 * i + 2]);
    }

    int _query(int a, int b, int val, int k, int l, int r) {
        if (r <= a || b <= l) return 0;

        if (a <= l && r <= b) {
            int sz = dat[k].size();
            int idx = upper_bound(all(dat[k]), val) - dat[k].begin();
            return sz - idx;
        }
        int vl = _query(a, b, val, 2 * k + 1, l, (l + r) / 2);
        int vr = _query(a, b, val, 2 * k + 2, (l + r) / 2, r);
        return vl + vr;
    }
    // [a,b)
    int query(int a, int b, int val) { return _query(a, b, val, 0, 0, n); }
};

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

    vector<vector<int>> pos(n);
    rep(i, n) {
        int c;
        scanf(" %d", &c);
        pos[c - 1].pb(i);
    }

    vector<int> nx(n, INF);
    rep(i, n) {
        int sz = pos[i].size();
        rep(j, sz - 1) {
            int u = pos[i][j], v = pos[i][j + 1];
            nx[u] = v;
        }
    }

    SegTree st(n);
    st.init(nx);

    while (q--) {
        int l, r;
        scanf(" %d %d", &l, &r);
        --l;
        --r;
        printf("%d\n", st.query(l, r + 1, r));
    }

    return 0;
}


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

int main(){
    long double x[25],y[25],a,b,c,s,S = 0.0;
    int n = 0;
    while(scanf("%Lf,%Lf",&x[n],&y[n]) != EOF) n++;
    for(int i=1;i<n-1;i++){
        a = sqrt(((x[i]-x[0])*(x[i]-x[0])) + ((y[i]-y[0])*(y[i]-y[0])));
        b = sqrt(((x[i+1]-x[i])*(x[i+1]-x[i])) + ((y[i+1]-y[i])*(y[i+1]-y[i])));
        c = sqrt(((x[0]-x[i+1])*(x[0]-x[i+1])) + ((y[0]-y[i+1])*(y[0]-y[i+1])));
        s = (a + b + c) / 2;
        S += sqrt(s*((s-a)*(s-b)*(s-c)));
    }
    printf("%Lf\n",S);
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;
int main() {
  ll h, n;
  cin >> h >> n;
  vector<vector<ll>> dp(n + 1, vector<ll>(h + 1, INF));
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >>b[i];
  dp[0][0] = 0;
  rep(i, n)rep(j, h + 1) {
    int nj = min(j + a[i], h);
    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    dp[i + 1][nj] = min(dp[i + 1][j] + b[i], dp[i + 1][nj]);
  }
  
  cout << dp[n][h] << endl;
}

Measured memory_bytes: 78592
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;



int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll ans = (n / 500) * 1000;
	n %= 500;
	ans += (n / 5) * 5;
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){

    int N,ans,l,r;

    cin >> N;

    for(int i=1;i<=N;i++){
        cin >> l>>r;
        ans+= r-(l-1);
    }

    cout << ans <<endl;

    return 0;
}


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

int main(){
  int n, m, d;
  int total = 0;
  std::vector<int> days;
  cin >> n >> m;
  for(int i=0; i < m; i++){
      cin >> d;
      total += d;
  }
  if(total > n) cout << -1;
  else cout << n - total;
}

Measured memory_bytes: 3596
import sys
from collections import defaultdict


def reverse_search(n, parents):
    q = [n - 1]
    visited = set()
    while q:
        v = q.pop()
        if v in visited:
            continue
        visited.add(v)
        q.extend(u for u in parents[v] if u not in visited)
    return visited


n, m, p = list(map(int, input().split()))
INF = 10 ** 12
links = [set() for _ in range(n)]
parents = [set() for _ in range(n)]
costs = [[INF] * n for _ in range(n)]
for line in sys.stdin:
    a, b, c = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    parents[b].add(a)
    costs[a][b] = min(costs[a][b], p - c)
reachable = reverse_search(n, parents)

dist = [INF] * n
dist[0] = 0
for _ in range(len(reachable)):
    updated = False
    for v in reachable:
        d = dist[v]
        if d == INF:
            continue
        cv = costs[v]
        for u in links[v]:
            if dist[u] > d + cv[u]:
                dist[u] = d + cv[u]
                updated = True
    if not updated:
        break
else:
    print(-1)
    exit()

print(max(0, -dist[n - 1]))


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

int main() {
  int K, T;
  cin >> K >> T;
  vector<int> c(T);
  for (int &e : c) cin >> e;
  sort(c.begin(), c.end(), greater<int>());
  
  int M = c[0];
  cout << max(2*M-K-1,0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s == "SAT"){
    cout << 1 << endl;
  }
  if(s == "SUN"){
    cout << 7 << endl;
  }
  if(s == "MON"){
    cout << 6 << endl;
  }
  if(s == "TUE"){
    cout << 5 << endl;
  }
  if(s == "WED"){
    cout << 4 << endl;
  }
  if(s == "THU"){
    cout << 3 << endl;
  }
  if(s == "FRI"){
    cout << 2 << endl;
  }
}

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

int main()
{
    int K,N;
    int dis1,dis2;
    cin >> K >> N;
    int min = 0;

    cin >> dis1;
    int first = dis1;
    for(int i=1;i<N;i++){
        cin >> dis2;
        if(dis2-dis1 > min){
            min = dis2-dis1;
        }
        dis1 = dis2;
    }
    if((first + K) - dis1 > min)  min = (first + K) - dis1;


    cout << K - min << endl;
}

Measured memory_bytes: 256
from math import ceil
N = int(input())
X = []
for d in range(1, ceil(N ** 0.5) + 1):
    if N % d == 0:
        X.append([d, N // d])

ans = float('inf')
for d1, d2 in X:
    ans = min(ans, d1 + d2 - 2)

print(ans)


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, z, n) for(int64_t i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
//const int INF = 1 << 29;
//const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
using namespace std;
typedef pair<int64_t, int64_t> P;

int main(){
    int N;
    cin >> N;
    set<int> S;
    rep(i, 0, N){
        int A;
        cin >> A;
        if (S.count(A)){
            cout << "NO" << endl;
            return 0;
        }
        else{
            S.insert(A);
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 9600
#include<stdio.h>
#include<math.h>

typedef struct Point{
  double x, y;
}Point;


  void koch(int n, Point a, Point b){
    if(n == 0) return;

    Point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);

    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);

    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);

    koch(n - 1, t, b);
  }

int main(){
  Point a, b;
  int n;

  scanf("%d", &n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}


Measured memory_bytes: 2048
def gcm(i, j):
	k = lcm(i, j)
	return min(i, j) * max(i, j) / k
def lcm(i, j):
	if j > i:
		return lcm(j, i)
	if i % j == 0:
		return j
	k = i % j
	return lcm(j, k)

N = input()
print gcm(2, N)



Measured memory_bytes: 2568