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

char getGrade(int m,int f, int r){
    int sum=m+f;
    char grade;
    
    if (m==-1 || f==-1){
        grade='F';
        
    } else if (80 <= sum){
        grade='A';
    } else if (65 <= sum && sum <80){
        grade='B';
    } else if (50 <= sum && sum <65){
        grade='C';
    } else if (30 <= sum && sum <50){
        if (50<=r) grade='C';
        else grade='D';
    } else if (sum <30){
        grade='F';
    }
    return grade;
}

int main(){
    int m,f,r;
    while(true){
        cin >> m >> f >> r;
        if (m==-1 && f==-1 && r==-1) break;
        cout << getGrade(m,f,r) << endl;
    }
    return 0;
}


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

int main() {
    int n, m, q, d[502][502];
    cin>>n>>m>>q;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            d[i][j]=0;
        }
    }
    for(int i=0;i<m;i++){
        int l, r;
        cin>>l>>r;
        d[l][r]++;
    }
    for(int i=0;i<=n;i++){
        for(int j=1;j<=n;j++){
            d[i][j]+=d[i][j-1];
        }
    }
    for(int i=0;i<=n;i++){
        for(int j=1;j<=n;j++){
            d[j][i]+=d[j-1][i];
        }
    }
    for(int i=0;i<q;i++){
        int p, q, a;
        cin>>p>>q;
        a=d[q][q]-d[q][p-1]-d[p-1][q]+d[p-1][p-1];
        cout<<a<<endl;
    }
    
	return 0;
}

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

int main() {
  int A, B, C, K;
  int count = 0;
  cin >> A >> B >> C >> K;
  if (K - A <= 0)
  {
    cout << K << endl;
  }
  else if (K - A > 0)
  {
    count = A;
    K -= A;
    if (K <= B)
    {
      cout << A << endl;
    }
    else if (K > B)
    {
      K -= B;
      if (K <= C)
      {
        count -= K;
        cout << count << endl;
      }
      else if (K > C)
      {
        count -= C;
        cout << count << endl;
      }
    }
  }
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

vector<vector<pair<int, long long int> > > E;
vector<int> C;

void dfs(int x, int zo) {
    if(zo==0) {
        C[x] = 1;
    } else {
        C[x] = 0;
    }
    
    for(int ei=0; ei<E[x].size(); ei++) {
        if(C[E[x][ei].first]==-1) {
            if(E[x][ei].second%2==0) {
                dfs(E[x][ei].first, !C[x]);
            } else {
                dfs(E[x][ei].first, C[x]);
            }
        }
    }
}

int main() {
    int N;
    cin >> N;
    E.resize(N);
    C.assign(N, -1);
    for(int n=0; n<N-1; n++) {
        int u, v;
        long long int w;
        cin >> u >> v >> w;
        
        E[u-1].push_back(make_pair(v-1, w));
        E[v-1].push_back(make_pair(u-1, w));
    }
    
    dfs(0, -1);

    for(int n=0; n<N; n++) {
        cout << C[n] << endl;
    }

    return 0;
    
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    long Q;
    cin >> S >> Q;
    long t, f, len;
    char c, tmp;
    bool rev = false;
    REP(i,Q){
        cin >> t;
        if(t==1){ // 前後を反転,　フラグで管理
            if(rev){
                rev = false;
            }
            else{
                rev = true;
            }
        }
        else if(t==2){
            cin >> f >> c;
            if((f==1 && rev==false)||(f==2 && rev==true)){ // 先頭に追加
                S.insert(S.begin(), c);
            }
            else{ // 末尾に追加
                S += c;
            }
        }
    }
    if(rev){
        reverse(S.begin(),S.end());
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 912
/// In The Name Of God
/// I wish, that I could leave it all behind me / Go to my own world where no one can find me
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define pii pair <int , int>
#define ld long double
#define for2(a,b,c) for(int (a) = (b); (a) < (c); (a)++)
#define for3(a,b,c) for(    (a) = (b); (a) < (c); (a)++)
#define setp cout << fixed << setprecision(15)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define all(x) (x).begin() , (x).end()

int dp[200][2];

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    int last = -1;
    for2(i,1,1+n){
        int x; cin >> x;
        dp[i][1] = min(dp[i-1][0],dp[i-1][1])+1;
        if(x != last) dp[i][0] = min(dp[i-1][0],dp[i-1][1]);
        else          dp[i][0] = dp[i-1][1];
        last = x;
    }
    cout << min(dp[n][0],dp[n][1]) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define dfor(i,a,b) for(ll i=(a);i>=(b);i--)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second


int main() {
	int n;
	cin>>n;
	double v = 1.0*n/3;
	printf("%.6f",v*v*v);
	
}

Measured memory_bytes: 256
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int N;
  cin >> N;
  vl A(N);
  cin >> A;

  rep(i, N) {
    if (A[i] == 0) {
      out(0);
      return 0;
    }
  }

  ll ans = 1;
  rep(i, N) {
    if (ans > (ll)1E18 / A[i]) {
      out(-1);
      return 0;
    }
    ans *= A[i];
    if (ans > (ll)1E18) {
      out(-1);
      return 0;
    }
  }

  out(ans);
}


Measured memory_bytes: 3996
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
    int a,b,c;
  cin>>a>>b>>c;
    if(b-a==c-b){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}   


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll D;
    cin >> n >> D;
    vector<ll> d(n);
    rep(i,n)cin >> d[i];
    vector<ll> now(n + 1);
    now[0] = D;
    rep(i,n){
        now[i + 1] = min(now[i], abs(d[i] - now[i]));
    }
    show(now);
    ll a = 1;
    vector<bool> ans(n);
    for(int i = n; i >= 0; i--){
        if(a > d[i] / 2){
            a += d[i];
        }
        if(i and a <= now[i - 1]){
            ans[i - 1] = 1;
        }
    }
    int q;
    cin >> q;
    while(q--){
        int x;
        cin >> x;
        if(ans[x - 1]){
            puts("YES");
        }else{
            puts("NO");
        }
    }
}


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


    if(x[5] == '0' && x[6] <= '4' && x[8] <= '3' && x[9] >= '0')
        cout << "Heisei" ;
    else
        cout << "TBD" ;


    return 0 ;
}


Measured memory_bytes: 256
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, a, b; cin >> n >> a >> b;
	println(min(b, a*n));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll v[100010];
    cin >> N;
    rep(i,0,N){
        cin >> v[i];
    }
    map<ll, ll> mp_even, mp_odd;
    rep(i,0,N){
        if(i % 2 == 0){
            mp_even[v[i]]++;
        }else{
            mp_odd[v[i]]++;
        }
    }

    vector< pair<ll, ll> > p_even, p_odd;
    rep(i,1,100001){
        p_even.push_back(make_pair(mp_even[i], i));
        p_odd.push_back(make_pair(mp_odd[i], i));
    }
    sort(p_even.begin(), p_even.end(), greater< pair<ll,ll> >());
    sort(p_odd.begin(), p_odd.end(), greater< pair<ll,ll> >());
    ll ans = 0;
    if(p_even[0].second != p_odd[0].second){
        ans = N - p_even[0].first - p_odd[0].first;
    }else{
        ans = N - p_even[0].first - p_odd[1].first;
        ans = min(ans, N - p_even[1].first - p_odd[0].first);
    }
    print(ans);


}


Measured memory_bytes: 16736
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

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

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

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

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

use std::cmp;

fn main() {
    input! {
        n: i32, t: i32,
        ct: [(i32, i32); n],
    }
    let mut ans = i32::max_value();
    for i in ct {
        if i.1 <= t {
            ans = cmp::min(ans, i.0);
        }
    }

    if ans == i32::max_value() {
        println!("TLE");
    } else {
        println!("{}", ans);
    }
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int sz = 1e6+5;
ll int arr[sz], arr1[sz];
//ll int arr[100][100]= {0};
bool prime[sz]= {0};
vector <ll int> pr,vec1,vec2;
//vector <pair <int,int>> vec;

int main()
{
    int a;
    cin>>a;

    cout<<a+(a*a)+(a*a*a)<<endl;
}


Measured memory_bytes: 3636
/*
    ThunderClap and Flash
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod) + (b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod) * (b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod) - (b%mod) + mod)%mod;}

void Flash(){
    ll n;
    cin>>n;
    if (n >= 30) {
        cout<<"Yes\n";
    } else {
        cout<<"No\n";
    }
}

int main(int argc, char const *argv[]){ 
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    ThunderClap;
    ll t = 1;
    //cin>>t;
    for(ll i = 1; i <= t; i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <climits>

using namespace std;

bool a(vector < int > book, int mid, int m) {
	vector < int > total(m);
	int count = 0;

	for(int i = 0; i < m; i++) {
		for(int j = count; j < book.size(); j++) {
			total[i] += book[j];
			count++;
			if(total[i] > mid) {
				total[i] -= book[j];
				count--;
				break;
			}
		}
	}

	if(count == book.size()) {
		return true;
	} else {
		return false;
	}
}

int main() {
	int n, m;

	

	while ( true ) {
		cin >> m >> n;

		if(!m && !n) {
			break;
		}
		vector < int > book(n);

		for(int i = 0; i < n; i++) {
			cin >> book[i];
		}

		int bottom = 0, top = 1500000;

		for(int i = 1; i <= 100; i++) {
			int mid = (bottom + top) / 2;
			if( a(book, mid, m) ) {
				top = mid;
			} else {
				bottom = mid + 1;
			}
		}

		cout << (bottom + top) / 2 << endl;
	}
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

// ====================================================================

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  list<ll> l;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0)
      l.push_back(v[i]);
    else
      l.push_front(v[i]);
  }

  if (n % 2 != 0) reverse(l.begin(), l.end());

  for (auto itr = l.begin(); itr != --l.end(); itr++) {
    cout << *itr << " ";
  }
  cout << *l.rbegin() << endl;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
const int MOD = 1000000007;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

int main() {
    int n; cin >> n;
    multimap<int,int> m;
    for(int i = 1;i <= n;i++){
        int x; cin >> x;
        m.insert(make_pair(x,i));
    }
    for(auto x:m) cout << x.second << " ";
    
}


Measured memory_bytes: 8232
from sys import stdin


def main():
    N = stdin.readline().rstrip()
    N_num = int(N)

    if len(N) == 1:
        print(N_num)

    elif len(N) == 2:
        print(9)

    elif len(N) == 3:
        print((N_num % 100) + (N_num//100-1)*100 + 10)

    elif len(N) == 4:
        print(909)

    elif len(N) == 5:
        print((N_num % 10000) + (N_num//10000-1)*10000 + 910)

    elif len(N) == 6:
        print(90909)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    };
    let s = std::iter::once(0)
        .chain(a.iter().scan(0, |acc, &a_i| {
            *acc += a_i;
            Some(*acc)
        }))
        .collect::<Vec<i64>>();
    let mut m = std::collections::BTreeMap::new();
    for &s_i in s.iter() {
        let entry = m.entry(s_i).or_insert(0);
        *entry += 1;
    }
    let ans = m
        .values()
        .filter(|&&v| v >= 2)
        .map(|&v| v * (v - 1) / 2)
        .sum::<i64>();
    println!("{}", ans);
}


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

const int MAX = 20;
int data[MAX][MAX];
int H,W;
/*
void display(){
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      cout << data[i][j];
    }
    cout << endl;
  }
  cout << endl;
}
*/
bool isCanSpread(int x,int y){
  if(x-1 < 0 || y-1 < 0)return true;
  if(data[y-1][x] == 2 && data[y-1][x-1] == 1)return true;
  if(data[y-1][x-1] == 1 && data[y][x-1] == 2)return true;
  return false;
}

void dfs(int x,int y,int& res){

  if(x == W){
    if(y == H-1){
      res++;
      //display();
    }
    else {
      dfs(0,y+1,res);
    }
    return;
  }
  if(data[y][x] != -1)dfs(x+1,y,res);
  else {
    if(!isCanSpread(x,y))return;

    data[y][x] = 1;

    // tate
    if(y+1 < H){
      data[y+1][x] = 2;
      dfs(x+1,y,res);
      data[y+1][x] = -1;    
    }

    // yoko
    if(x+1 < W){
      if(data[y][x+1] == -1){
        data[y][x+1] = 2;
        dfs(x+1,y,res);
        data[y][x+1] = -1;
      }
    }
    
    data[y][x] = -1;
  }
}

void solve(){
  for(int i = 0 ; i < MAX ; i++){
    for(int j = 0 ; j < MAX ; j++){
      data[i][j] = -1;
    }                                 
  }
  int res = 0;
  dfs(0,0,res);
  cout << res << endl;
}

int main(){
  while(cin >> H >> W,H || W)solve();
  return 0;
}

Measured memory_bytes: 1172
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	class Group {
		int id;
		int p;
		int time;
		int tq;
		int j;

		Group(int id) {
			this.id = id;
			if (id % 5 == 1) {
				p = 5;
			} else {
				p = 2;
			}
			time = 17 * (id % 2) + 3 * (id % 3) + 19;
		}

	}

	void run() {
		boolean[] used = new boolean[17];
		LinkedList<Group> q = new LinkedList<Group>();
		LinkedList<Group> f = new LinkedList<Group>();
		int[] ans = new int[100];
		for (int i = 0; i < 100; i++) {
			q.add(new Group(i));
		}
		int timer = 0;
		for (;; timer++) {
//			System.out.println(timer - 1 + " " + Arrays.toString(used));
			if (q.isEmpty()) {
				break;
			}
			for (Group g : f) {
				g.time--;
				if (g.time == 0) {
					for (int i = g.j; i < g.j + g.p; i++) {
						used[i] = false;
					}
				}
			}
			for (;;) {
				if(q.isEmpty()){
					break;
				}
				Group g = q.peekFirst();
				if (timer < g.id * 5) {
					break;
				}
				int j = 0;
				int k = 0;
				for (int i = 0; i < 17; i++) {
					if (used[i]) {
						j = i + 1;
						k = 0;
					} else {
						k++;
						if (k == g.p) {
							break;
						}
					}
				}
				if (k != g.p) {
					break;
				}

				f.add(q.poll());
				g.tq = timer;
				g.j = j;
				ans[g.id] = g.tq - g.id * 5;
				for (int i = j; i < g.j + g.p; i++) {
					used[i] = true;
				}
			}
		}
		for (;;) {
			if (!sc.hasNextInt()) {
				break;
			}
			int n = sc.nextInt();
			System.out.println(ans[n]);
		}
	}

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

Measured memory_bytes: 0
import scala.math.{min,max}

object Main {
    def main(args: Array[String]) {
        var input = io.Source.stdin.getLines().mkString("\n");
        // val xs = input.split('\n').map(_.toInt).toArray;
        var ss = input.split('\n').toList;
        val xs = to_array_int(ss(0));
        val hh = xs(0);
        val ww = xs(1);
        val ys = to_array_int(ss(1));
        val h = ys(0);
        val w = ys(1);
        val res = (hh - h) * (ww - w);
        println(res);
    }
    def to_array_int(s: String): Array[Int] = {
        return s.split(' ').map(_.toInt).toArray;
    }
}


Measured memory_bytes: 25532
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}
int comb(int n, int k) {
	k = min(k, n - k);
	int x = 1, y = 1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

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

	int x, y, a, b, c;
	int p[114514], q[114514], r[114514];
	priority_queue<P>que;

	cin >> x >> y >> a >> b >> c;
	rep(i, a) {
		cin >> p[i];
		que.push({ p[i],0 });
	}
	rep(i, b) {
		cin >> q[i];
		que.push({ q[i],1 });
	}
	rep(i, c) {
		cin >> r[i];
		que.push({ r[i], 2 });
	}

	int cnt = 0, ans = 0;
	int rcnt = 0, gcnt = 0;
	while (cnt < x + y) {
		P now = que.top(); que.pop();
		if (now.second == 0) {
			if (rcnt >= x) goto bou;
			else {
				ans += now.first;
				rcnt++;
			}
		}
		else if (now.second == 1) {
			if (gcnt >= y) goto bou;
			else {
				ans += now.first;
				gcnt++;
			}
		}
		else {
			ans += now.first;
		}
		cnt++;
	bou:;
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    for(int i=1;i<=n;i++) cin >> a[i];
    int now=0;
    ll res=0;
    for(int i=1;i<=n;i++)
    {
        res+=max(0,now-a[i]);
        now=max(now,a[i]);
    }
    cout << res << "\n";
    return 0;
}


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

long long modpow(long long a, long long n, long long mod) {
  long long res =1;
  while (n > 0) {
    if(n & 1) res = res * a  % mod;
    a = a * a % mod;
    n >>= 1;
  }
  
  return res;
}

int main() {
  
  long long N;
  cin >> N;
  
  long long x1, x2, x3;

  x1 = modpow(10, N,1000000007);
  x2 = modpow(9, N,1000000007);
  x3 = modpow(8, N,1000000007);
/*
  cout << "x1: " << x1 << endl;
  cout << "x2: " << x2 << endl;
  cout << "X3: " << x3 << endl;
*/
  long long ans;
  
  ans = x1 - x2 *2 + x3;
  while(ans < 0) ans += 1000000007;
  
  ans %= 1000000007;
  cout << ans << endl;
  
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  double sum = 0;
  for(int i = 0; i < N; i++) {
    cin >> p.at(i);
    if(i < K) {
      sum += p.at(i);
    }
  }
  double Max = sum;
  for(int i = K; i < N; i++) {
    sum = sum - p.at(i - K) + p.at(i);
    if(sum > Max) {
      Max = sum;
    }
  }
  cout << fixed << setprecision(7) << (Max + K) / 2 << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int n;
    while(cin>>n && n){
    int cost = 1000 - n;
    int cnt=0;
    cnt += cost/500;
    cost = cost%500;
    cnt += cost/100;
    cost = cost%100;
    cnt += cost/50;
    cost = cost%50;
    cnt += cost/10;
    cost = cost%10;
    cnt += cost/5;
    cost = cost%5;
    cnt += cost/1;
    cost = cost%1;
    cout<<cnt<<endl;
  }
}


Measured memory_bytes: 3004
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// 別の書き方を使ってみる

// constexpr inline ll mod = 1'000'000'007;
constexpr int max_n = 200'000 + 5;

int n, q;
vector<int> cnts(max_n);

vector<int> hd(max_n); // n : 頂点数
vector<int> nxt(2*max_n), to(2*max_n); // 2*(n-1)+1 : 辺の個数+1
int edge_cnt;
void add_edge(int u, int v) { // u to v
    edge_cnt++; // 辺が1つ増える
    to[edge_cnt] = v; // edge_cnt本目の辺の行き先はv
    nxt[edge_cnt] = hd[u]; // edge_cnt本目の辺の次に見る(uから出る)辺は、はじめに見ていた(uから出る)辺であるhd[u]本目の辺
    hd[u] = edge_cnt; // 新しくはじめに見る(uから出る)辺はedge_cnt本目の辺
}

void dfs(int cur = 0, int parent = -1)
{
    for (int e = hd[cur]; e > 0; e = nxt[e]) {
       int child = to[e];
       if (child == parent) { continue; }
       cnts[child] += cnts[cur];
       dfs(child, cur);
   }
}

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout << setprecision(10); // 浮動小数の表示の精度

    cin >> n >> q;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        add_edge(a,b);
        add_edge(b,a);
    }
    rep(j, q)
    {
        int p,x;
        cin >> p >> x;
        p--;
        cnts[p] += x;
    }

    // 集計
    dfs();

    rep(i, n)
    {
        cout << cnts[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 20340
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if((b-a)==(c-b)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int dp[1005][1005];
const int mod = 1000000007;
int main() {
  int h,w;
  cin >> h >> w;
  vvi maze(h+1,vi(w+1,0));
  rep(i,h) rep(j,w) {
    char a;
    cin >> a;
    if(a=='.') maze[i][j] = 1;
    else maze[i][j] = 0;
  }

  dp[0][0] = 1;
  rep(i,h) rep(j,w) {
    if(maze[i][j+1]) {
      dp[i][j+1] += dp[i][j];
      dp[i][j+1] = dp[i][j+1] % mod;
    }
    if(maze[i+1][j]) {
      dp[i+1][j] += dp[i][j];
      dp[i+1][j] = dp[i+1][j] % mod;
    }
  }

  cout << dp[h-1][w-1] << endl;



  return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define sz(s) (ll)s.size()
#define print(d) cout << fixed << setprecision(15) << d
#define pii pair<ll,ll>
#define ppii pair<ll,pii>
#define ff first
#define ss second
const ll MOD = 1000000007;
const ll MAXN = 1e6 + 5;
const ll inf = 2e18;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
tree_order_statistics_node_update> ord_set;
#define debug(x) cerr << #x << " = " << x << endl


ll power(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
}


int main()
{
    fast
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    ll n;
    cin >> n;
    ll arr[n];
    fr(i,0,n)cin >> arr[i];
    ll ans=0;
    ll mn = inf;
    fr(i,0,n)
    {
        if(arr[i]<=mn)ans++;
        mn=min(mn,arr[i]);
    }
    cout << ans;
    



    return 0;

}










Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
 int n;
 double d1,d2,d3,dinf;
 cin >> n;
 int x[n]={};
 int y[n]={};

 for(int i=0;i<n;++i){
  cin >> x[i];
 }
 for(int i=0;i<n;++i){
  cin >> y[i];
 }

 dinf=0.0;
 for(int i=0;i<n;++i){
  d1+=fabs(x[i]-y[i]);
  d2+=pow(x[i]-y[i],2);
  d3+=pow(fabs(x[i]-y[i]),3);
  
  if(fabs(x[i]-y[i])>dinf){
   dinf=fabs(x[i]-y[i]);
  }
 }

 d2=sqrt(d2);
 d3=pow(d3,1.0/3.0);

 cout << fixed << setprecision(8) << d1 << endl << d2 << endl << d3 << endl << dinf << endl;
 return 0;
}

Measured memory_bytes: 3460
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define double long double
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    int n;
    cin>>n;VI re,re2;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        re.pb(x-y);
        re2.pb(x+y);
    }
    sort(all(re));
    sort(all(re2));
    int ans=max(abs(re[n-1]-re[0]),abs(re2[n-1]-re2[0]));
    cout<<ans<<endl;
    
}


return 0;
}





Measured memory_bytes: 6680
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define MP make_pair
#define MEM(i,j) memset(i,j,sizeof i)
#define Tie ios::sync_with_stdio(0),cin.tie(0)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

long long n,X,a[200001],ans,tmp,tmp2;
priority_queue<int> q;

long long solve(int x)
{
	long long re=x*X;
	int l=1,cnt=0;
	for(int i=n-1;i>-1;i--)
	{
		if(l==1)
			re+=a[i]*5;
		else
			re+=((l+1)*(l+1)-l*l)*a[i];
		cnt++;
		if(cnt==x)
			l++,cnt=0;
	}
	return re;
}

int f(int l,int r)
{
	if(l==r)return l;
	int m=l+r>>1;
	if(solve(m)<solve(m+1))
		return f(l,m);
	else return f(m+1,r);
}

int main()
{
	cin>>n>>X;
	for(int i=0;i<n;i++)
		cin>>a[i];
	tmp=f(1,n);
	cout << solve(tmp)+X*n<<'\n';
}

Measured memory_bytes: 1792
require "set"
n,m = gets.chomp.split(" ").map(&:to_i)
ab_arr = m.times.map{gets.chomp.split(" ").map(&:to_i)}

hash = {}
edge = []

ab_arr.each do |(a, b)|
  hash[a] ||= []
  hash[a] << b
  hash[b] ||= []
  hash[b] << a
  if a < b
    edge << [a, b]
  else
    edge << [b, a]
  end
end

count = 0
edge.each do |(e_a, e_b)|
  count_set = Set.new
  passed_set = Set.new
  bfs = [1]
  count_set << 1
  while bfs.length > 0 do
    a = bfs.shift
    hash[a].each do |b|
      in_a, in_b = a, b if a < b
      in_a, in_b = b, a if b < a
      next if (e_a == in_a && e_b == in_b)
      next if passed_set.include?([in_a, in_b])
      passed_set << [in_a, in_b]
      count_set << b
      bfs << b
    end
  end
  count += 1 if count_set.length != n
end

puts count


Measured memory_bytes: 14544
n = int(input())
card_list = list(map(int, input().split()))

alice_point = 0
bob_point = 0

def pick_card(card_list):
    # print(card_list)
    max = 0
    max_index = 0
    for i in range(card_list.__len__()):
        # print('-------', i)
        if card_list[i] > max:
            # print('@', i, ':', max, '<', card_list[i])
            max = card_list[i]
            max_index = i
    
    del card_list[max_index]

    # print('----', card_list)

    return max, card_list

turn = 0
while turn < n:
    # print('--', turn)
    remain_list = []
    if turn % 2 == 0:
        alice_get, remain_list = pick_card(card_list)
        alice_point += alice_get
    else:
        bob_get, remain_list = pick_card(card_list)
        bob_point += bob_get

    card_list = remain_list
    # print(alice_point, bob_point, card_list)

    turn += 1

print(alice_point - bob_point)

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

const int MAX_V = 100010;
typedef int Capacity;
typedef int Cost;
const int inf = 1 << 28;

struct Edge {
	int dst;
	Capacity cap, cap_orig;
	Cost cost;
	int revEdge; bool isRev;
	Edge(int dst, Capacity cap, Cost cost, int revEdge, bool isRev)
		:dst(dst), cap(cap), cap_orig(cap), cost(cost), revEdge(revEdge), isRev(isRev) {
	}
};


struct PrimalDual {
	int n;
	vector<vector<Edge> > g;
	vector<int> top;
	PrimalDual(int n_) : n(n_), g(vector<vector<Edge> >(n_)) {}
	void add_edge(int src, int dst, Capacity cap, Cost cost) { // ?????????
		g[src].push_back(Edge{ dst, cap, cost, (int)g[dst].size(), false });
		g[dst].push_back(Edge{ src, 0, -cost, (int)g[src].size() - 1, true });
	}
	Cost solve(int s, int t, int f) {
		Cost res = 0;
		static Cost h[MAX_V], dist[MAX_V];
		static int prevv[MAX_V], preve[MAX_V];

		fill(h, h + n, 0);
		if(top.size()) {
			assert(top.size() == n);
			for(int i = 0; i < n; i++) {
				int v = top[i];
				for(int i = 0; i < g[v].size(); i++) {
					Edge& e = g[v][i];
					if(e.cap == 0) continue;
					int u = e.dst;
					h[u] = min(h[u], h[v] + e.cost);
				}
			}
		}

		while(f > 0) {
			typedef pair<Cost, int> pcv;
			priority_queue<pcv, vector<pcv>, greater<pcv> > q;
			for(int i = 0; i < n; i++) {
				dist[i] = inf;
			}
			dist[s] = 0;
			q.push(pcv(0, s));
			while(q.size()) {
				pcv p = q.top(); q.pop();
				int v = p.second;
				if(dist[v] < p.first) continue;
				for(int i = 0; i < g[v].size(); i++) {
					Edge &e = g[v][i];
					if(e.cap > 0 && dist[e.dst] > dist[v] + e.cost + h[v] - h[e.dst]) {
						dist[e.dst] = dist[v] + e.cost + h[v] - h[e.dst];
						prevv[e.dst] = v;
						preve[e.dst] = i;
						q.push(pcv(dist[e.dst], e.dst));
					}
				}
			}
			if(dist[t] == inf) {
				return -1;
			}
			for(int v = 0; v < n; v++) {
				h[v] += dist[v];
			}
			// s-t ????????????????????£??????????????????
			int d = f;
			for(int v = t; v != s; v = prevv[v]) {
				d = min(d, g[prevv[v]][preve[v]].cap);
			}
			f -= d;
			res += d * h[t];
			for(int v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.revEdge].cap += d;
			}
		}
		return res;
	}
	// ??????????????????=???????????????-?????¨??????????????¨???
	void view() {
		for(int i = 0; i < g.size(); i++) {
			for(int j = 0; j < g[i].size(); j++) {
				if(!g[i][j].isRev) {
					Edge& e = g[i][j];
					printf("%3d->%3d (flow:%d)\n", i, e.dst, e.cap_orig - e.cap);
				}
			}
		}
	}
};

int p[100];

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

	int N;
	cin >> N;
	for(int i = 0; i < N; i++) {
		cin >> p[i];
	}

	PrimalDual pd(2 * N + 2);
	int S = 2 * N, T = S + 1;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			if(p[i] == j + 1) continue;
			pd.add_edge(i, j + N, 1, p[i] * abs(i - j));
		}
		pd.add_edge(S, i, 1, 0);
		pd.add_edge(i + N, T, 1, 0);
	}

	cout << pd.solve(S, T, N) << endl;
}

Measured memory_bytes: 3700
use std::io;

fn main() {
    let mut contents =  String::new();
    io::stdin().read_line(&mut contents).expect("failed to read stdio.");

    for i in contents.lines() {
        // println!("contents = {:?}", i);
        println!("{:?}", resolve(i));
    }
}

fn resolve(input: &str) -> i32 {
    let mut answer = 0;
    let mut pencils = 0;
    let mut price = 0;

    let str: Vec<i32> = input.split(' ').map(|v| v.parse().unwrap()).collect();
    // println!("{:?}", str);
    loop {
        pencils += str[1];
        price += str[2];
        if pencils >= str[0] {
            break;
        }
    }
    answer = price;
    pencils = 0;
    price = 0;
    loop {
        pencils += str[3];
        price += str[4];
        if pencils >= str[0] {
            break;
        }
    }

    if price <= answer {
        answer = price;
    }

    answer
}



Measured memory_bytes: 5028
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n,k = iim()
h = []
for _ in range(n):
    h.append(ii())
h.sort()

ans = float('INF')
for i in range(n-k+1):
#    print(i,i+k-1,h[i],h[i+k-1])
    ans = min(ans,h[i+k-1]-h[i])
print(ans)

Measured memory_bytes: 7384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define lli long long int
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define prs(x,y) x.find(y)!=x.end()
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
inline int level(int n){int ans=0;while(n%2==0){n/=2;ans++;}return ans;}
int main()
{
	string a,b;
	cin>>a>>b;
	if(sz(b)==sz(a)+1)
	{
		a+=b[sz(a)];
		if(a==b)
			cout<<"Yes";
		else
			cout<<"No";
	}
	else
		cout<<"No";
}



Measured memory_bytes: 3628
from bisect import bisect_left, bisect_right

n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))

negative_end = bisect_left(a, 0)
positive_begin = bisect_right(a, 0)

negative_cnt = negative_end
positive_cnt = n - positive_begin
zero_cnt = n - negative_cnt - positive_cnt

prod_negative = negative_cnt * positive_cnt
# prod_positive = negative_cnt * (negative_cnt - 1) // 2 + positive_cnt * (positive_cnt - 1) // 2
prod_zero = zero_cnt * (negative_cnt + positive_cnt) + zero_cnt * (zero_cnt - 1) // 2
# print(prod_negative, prod_zero, prod_positive)

if k <= prod_negative:
    high, low = 0, -10**18
    while high > low + 1:
        mid = (high + low) // 2
        or_higher = 0
        r = positive_begin
        for l in range(negative_end):
            while r < n and a[l] * a[r] > mid:
                r += 1
            or_higher += positive_cnt - (r - positive_begin)

        if or_higher >= k:
            high = mid
        else:
            low = mid

    res = high

elif k <= prod_negative + prod_zero:
    res = 0

else:
    k -= prod_negative + prod_zero
    high, low = 10**18, 0
    while high > low + 1:
        mid = (high + low) // 2
        or_higher = 0
        r = n - 1
        for l in range(positive_begin, n):
            while r < n and a[l] * a[r] > mid and l < r:
                r -= 1
            or_higher += r - l if l < r else 0
        l = 0
        for r in range(negative_end - 1, -1, -1):
            while l < n and a[l] * a[r] > mid and l < r:
                l += 1
            or_higher += r - l if l < r else 0

        if or_higher >= k:
            high = mid
        else:
            low = mid

    res = high

print(res)


Measured memory_bytes: 92676
def a_biscuits(N, P, A):
    is_include_odd = False  # 数列Aの要素に奇数のものはあるか
    for k in A:
        if k % 2 == 1:
            is_include_odd = True
    # 枚数が奇数の袋kに注目し、残りN-1個の袋からいくつか袋を選ぶとする。
    # それらの袋の中の枚数の合計が奇数にせよ偶数にせよ、kを選ぶ選ばないで
    # 枚数の合計を奇数にも偶数にもできる。よって 2^(N-1) 通り。
    # 枚数が奇数の袋がない場合は、どのように袋を選んでも偶数にしかできない。
    if is_include_odd:
        ans = pow(2, N - 1)
    else:
        ans = pow(2, N) if P == 0 else 0
    return ans

N, P = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(a_biscuits(N, P, A))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n;
  cin>>n;
  vector<int> H;
  int sum=0;
  rep(i,n){
    int h;
    cin>>h;
    H.push_back(h);
    sum+=h;
  }
  
  int count=0;
  while(sum>0){
    int min=1000;
    rep(i,n){
      if(H[i]>0 && H[i]<min) min=H[i];
      if(min!=1000 && H[i]==0) break;
    }
    //rep(i,n) cout<<H[i]<<" ";
    //cout<<":"<<min<<endl;
    bool done=false;
    rep(j,n){
      if(H[j]==0){
        if(done) break;
        else continue;
      }
      H[j]-=min;
      sum-=min;
      done=true;
    }
    count+=min;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main()
{
  long N, M;
  cin >> N >> M;
  vector<int> A(M);
  REP(i,M){
    cin >> A.at(i);
  }
  ll n=N;
  REP(i,M){
    N -= A.at(i);
  }
  if(N<0){
    cout << -1 << endl;
  }else{
    cout << N << endl;
  }
}

Measured memory_bytes: 3632
n = int(input())
a = list(map(int,input().split()))
x = [0,0,0]
c = 1
for i in range(n):
  cc = 0
  k = 0
  for j in range(3):
    if a[i] == x[j]:
      cc += 1
      k = j
  c = (c*cc)%1000000007
  x[k] += 1
print(c)

Measured memory_bytes: 14396
import Control.Applicative
import Data.String
toInt :: (String -> Int)
toInt x = read x :: Int

getIntegers = do 
    x <-  getLine
    let y = (map$toInt)$words x
    return y
main = do
    [a,b] <- words <$> getLine
    putStrLn (show　((read b `div` 2) + read(a)))



Measured memory_bytes: 508
IDENTIFICATION DIVISION.
PROGRAM-ID. 163C.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(1400000).
*>
WORKING-STORAGE SECTION.
01 N          PIC 9(7) COMP.
01 I          PIC 9(6) COMP.
01 W          PIC 9(6) COMP.
01 P1         PIC 9(7) COMP.
01 P2         PIC 9(7) COMP.
01 TBL.
   03 A       PIC 9(6) OCCURS 200000.
01 OUT        PIC Z(5)9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  OPEN INPUT STDIO.
  READ STDIO.         
  CLOSE STDIO.
*>
  MOVE ZERO TO TBL.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I >= N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO W
    ADD 1 TO A(W)
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    MOVE A(I) TO OUT
    DISPLAY FUNCTION TRIM(OUT)
  END-PERFORM.
*>
  STOP RUN.


Measured memory_bytes: 6476
#include<stdio.h>

int main(){
	
	//準備部分
	int n,m,l,i,j,k,a[100][100]={},b[100][100]={};
	long c[100][100]={};
	
	//入力部分
	scanf("%d %d %d",&n,&m,&l);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			scanf("%d",&b[i][j]);
		}
	}
	
	//計算部分
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			for(k=0;k<m;k++){
				c[i][j]+=a[i][k]*b[k][j];
			}
		}
	}
	
	//出力部分
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			if(j>0)printf(" ");
			printf("%ld",c[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}



Measured memory_bytes: 2108