akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll dp[2007][2007];

int main(){
  ll N,M,A[2007],B[2007];
  cin >> N >> M;
  rep(i,N){
    cin >> A[i];
  }
  rep(i,M){
    cin >> B[i];
  }
  Rep(i,1,N+1){
    Rep(j,1,M+1){
      dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
      if(A[i-1]==B[j-1]){
        dp[i][j]+=dp[i-1][j-1]+1;
      }
      dp[i][j]+=MOD;
      dp[i][j]%=MOD;
    }
  }
  cout << (dp[N][M]+1)%MOD << endl;
}

Measured memory_bytes: 31616
(defun lower-bound (predicate &optional (ok 0) (ng (expt 10 10)))
  (if (<= (abs (- ng ok)) 1)
      ok
      (let ((mid (floor (+ ng ok) 2)))
        (if (funcall predicate mid)
            (lower-bound predicate mid ng)
            (lower-bound predicate ok mid)))))


(defun smaller-p (xs index b-size)
  (< (aref xs index) b-size))


(defun bigger-p (xs index b-size)
  (> (aref xs index) b-size))


(defun solve (a b c &optional (res 0))
  (declare (type (array fixnum) a b c))
  (declare (integer res))
  (the integer
       (dotimes (j (length b) res)
         (incf res (* (lower-bound #'(lambda (x)
                                       (smaller-p a x (aref b j)))
                                   0
                                   (length a))
                      (lower-bound #'(lambda (x)
                                       (bigger-p c x (aref b j)))
                                   0
                                   (length c)))))))


(defparameter *inf* (1+ (expt 10 9)))



(locally
  (declare (inline sort))
  (let* ((n (read))
         (a (make-array (1+ n) :element-type 'fixnum))
         (b (make-array n      :element-type 'fixnum))
         (c (make-array (1+ n) :element-type 'fixnum)))
    (declare (type fixnum n))
    (setf (aref a (1- (length a))) 0)
    (setf (aref c (1- (length c))) *inf*)
    (dotimes (i n)
      (setf (aref a i) (read)))
    (dotimes (i n)
      (setf (aref b i) (read)))
    (dotimes (i n)
      (setf (aref c i) (read)))
    (sort a #'<)
    (sort c #'>)
    (princ (solve a b c))
    (fresh-line)))



Measured memory_bytes: 78712
def RA():
    l = input().split()
    return list(map(lambda x: int(x), l))

n = int(input())
a = RA()
m = {}
for ai in a:
    if not ai in m.keys():
        m[ai] = 1
    else:
        m[ai] += 1
total = 0
for ai in m.keys():
    c = m[ai]
    total += int(c * (c - 1) / 2)
    m[ai] = int((c * (c - 1) - (c - 1) * (c - 2)) / 2)
for ai in a:
    print(total - m[ai])



Measured memory_bytes: 26268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  ll sum = 0;
  cin >> n;
  vector<pair<ll,ll>> w(n,pair<ll,ll>());
  for(int i = 0;i < n;i++){
    cin >> w[i].second >> w[i].first;
  }
  bool judge = true;
  sort(w.begin(),w.end());
  for(int i = 0;i < n;i++){
    sum += w[i].second;
    if(sum > w[i].first){
      judge = false;
      break;
    }
  }
  if(judge == true)cout << "Yes" << endl;
  else cout << "No" << endl;
  cin >> n;
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

ll gcd(ll a, ll b) {
  if (a < b) {
    swap(a, b);
  }
  if (b == 0) {
    return a;
  }
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  cout << (a * b) / gcd(a, b) << endl;
  return 0;
}


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

using namespace std;

const int inf = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);

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

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

    vector<int> dp(n + 1, inf);
    for (int i = 0; i < n; i++)
    {
        int idx = upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
        dp[idx] = a[i];
    }

    for (int i = n; i >= 0; i--)
    {
        if (dp[i] != inf)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 1152
#include<iostream>

using namespace std;

int main(){
    int k,a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin >> k;
    cout << a[k - 1];
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n;
  int k;
  cin >> n >> k;
  int count = 0;
  int q = k;
  while(1) {
    if (n >= k) {
      count ++;
      k *= q;
    } else {
      count++;
      break;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop

n, m = map(int, input().split(" "))
xys = [tuple(map(int, input().split(" "))) for i in range(n)]
xys = sorted(xys, key=lambda x: (x[0], -x[1]))

ans = 0

j = 0
h = []
for i in range(1, m + 1):
    while j < len(xys) and xys[j][0] <= i:
        heappush(h, -xys[j][1])
        j += 1
    if h:
        x = -heappop(h)
        # print("Pick", x)
        ans += x

print(ans)


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int n, d; cin >> n >> d;
    vector<vec> x(n, vec(d));
    rep(i, n)rep(j, d) cin >> x[i][j];
    int cnt = 0;
    rep(i, n){
        Rep(j, i+1, n){
            int tmp = 0;
            rep(k, d) tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            int t = sqrt(tmp);
            if(t*t == tmp) cnt++;
        }
    }
    cout << cnt << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7772
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pii pair<ll,ll>
#define forn(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mset(arr,x) memset(arr,x,sizeof(arr))
int main()
{
    boost;
            char str[3];
            int x=0,y=0,z=0;
            forn(i,3)
            {
                  cin>>str[i];
                  if(str[i]=='a')
                  {
                        x=1;
                  }
                  else if(str[i]=='b')
                  {
                        y=1;
                  }
                  else if(str[i]=='c')
                  {
                        z=1;
                  }
            }
            if( x && y && z )
            {
                  cout<<"Yes";
            }
            else
            {
                  cout<<"No";
            }
}


Measured memory_bytes: 256
n,m = map(int,input().split())
h = list(map(int,input().split()))
a = []
b = []
cnt = 0
while True:
  try:
    ta,tb = map(int,input().split())
    a.append(ta)
    b.append(tb)
  except:
    break
    
H = [0]*n

for i in range(m):

  if h[a[i]-1]>h[b[i]-1]:
    H[b[i]-1]-=1
  
  if h[a[i]-1]==h[b[i]-1]:
    H[a[i]-1]-=1
    H[b[i]-1]-=1
  if h[a[i]-1]<h[b[i]-1]:
    H[a[i]-1]-=1
n = [1 for i in H if i>=0]
print(len(n))

Measured memory_bytes: 22344
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        a:chars,
        b:chars,
        c:chars,
    }
    if &a[a.len()-1] == &b[0] && &b[b.len()-1] == &c[0]{
        println!("YES");
    }else{
        println!("NO");
    }
}


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

int main() {
  string str;
  getline(cin, str);
  vector<char> v(str.size());
  for(int i = 0; i < str.size(); ++i) {
    v.at(i) = str[i];
  }

  for(int i = 0; i < v.size(); ++i) {
    if(v.at(i) >= 65 && v.at(i) <= 90) v.at(i) =  char(v.at(i) + 32);
    else if(v.at(i) >= 97 && v.at(i) <= 122) v.at(i) = char(v.at(i) - 32);
    cout << v.at(i);
  }
  cout << endl;
}



Measured memory_bytes: 3004
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>

using namespace std;
using pii = pair<int, int>;
using ll = long long;

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

	int a, b;
	cin >> a >> b;
	b -= 1;
	a -= 1;
	cout << b / a + ((b % a != 0) ? 1 : 0);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double EPS=1e-10;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
  }
}
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
 
int ccw(P a, P b, P c) {
  b-=a;c-=a;
  if(cross(b,c)>EPS)return +1;
  if(cross(b,c)<-EPS)return -1;
  if(dot(b,c)<-EPS)return +2;
  if(norm(b)<norm(c))return -2;
  return 0;
}
 
vector<P> convex_hull(vector<P> p) {
  int n=p.size(),k=0;
  sort(p.begin(),p.end());
  vector<P> q(2*n);
  for(int i=0;i<n;q[k++]=p[i++])
    while(k>=2&&ccw(q[k-2],q[k-1],p[i])<=0) --k;
  for(int i=n-2,t=k+1;i>=0;q[k++]=p[i--])
    while(k>=t&&ccw(q[k-2],q[k-1],p[i])<=0) --k;
  q.resize(k-1);
  return q;
}
 
double area(vector<P> p) {
  double a=0;
  for(int i=0; i<(int)p.size(); i++) a+=cross(p[i],p[(i+1)%p.size()]);
  return fabs(a)/2;
}
 
int main() {
  int n;
  cin >> n;
  vector<P> v(n);
  for(int i=0; i<n; i++) {
    double x,y;
    cin >> x >> y;
    v[i]=P(x,y);
  }
  for(int t=0; t<2; t++) {
    vector<P> a;
    double d[n];
    for(int i=0; i<n; i++) {
      a.push_back(v[i]);
      d[i]=0;
      if(a.size()<3) continue;
      vector<P> b=convex_hull(a);
      d[i]=area(b);
      if(d[i]-d[i-1]<EPS) {
        cout << "Impossible" << endl;
        return 0;
      }
    }
    reverse(v.begin(),v.end());
  }
  cout << "Possible" << endl;
  return 0;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> ans;
    if(n&1){
        for(int i=0;i<(n-1)/2;i++){
            ans.emplace_back(i+2,-i+n);
        }
    }
    else{
        int k=0;
        for(int i=0;n/2-2*i-1>0;i++){
            ans.emplace_back(i+1,-i+n);
            k++;
        }
        for(;k<(n-2)/2;k++){
            ans.emplace_back(k+2,-k+n);
        }
    }

    for(int i=0;i<m;i++){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
}

Measured memory_bytes: 4264
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
#define vi vector<int>
#define lli long long int
#define fo(i,n) for(int i=1;i<=n;i++)
#define foo(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
#define vii vector<lli>

#define ok ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#define vp vector<pair<lli,lli>>
#include <map>           
lli mod=1000000007;      

int main(){
  lli n;
  cin>>n;
  vii v(n);
  
  foo(i,n) cin>>v[i];
  sort(v.begin(),v.end(),greater<lli>());
  
  lli s=v[0];
  lli t=n-2;
  int i=1;
  int c=0;
  while(t--){
    s+=v[i];
    c++;
    if(c==2){
      i++;
      c=0;
    }
  }
  cout<<s;
}

Measured memory_bytes: 4844
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	s := sc.Text()
	if s == "5" || s == "7" || s == "3" {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
use v5.18;
use warnings;
sub read_line { chomp(my $s = <>); $s }
sub splited_read_line { split / /, read_line }

use constant LAST => 100_0000;

my $s = read_line;

sub f {
  my $n = shift;
  $n % 2 == 0 ? $n / 2 : 3 * $n + 1;
}

my %memo;
my $ba;
for my $i (1 .. LAST) {
  my $A = do {
    if ( $i == 1 ) {
      $s;
    }
    else {
      f($ba);
    }
  };
  if ( exists $memo{$A} ) {
    say $i;
    exit;
  }
  $memo{$A} = $i;
  $ba = $A;
}


Measured memory_bytes: 768
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)

	max, max2 := -1, -1
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
		if a[i] >= max {
			max2 = max
			max = a[i]
		} else if a[i] >= max2 {
			max2 = a[i]
		}
	}
	for i := 0; i < n; i++ {
		if a[i] == max {
			fmt.Println(max2)
		} else {
			fmt.Println(max)
		}
	}
}

Measured memory_bytes: 6400
import sys
N,M = map(int,input().split())

#print(N,M)
bill = [10000,5000,1000]
#print(mx)
for i in range(N+1):
    for j in range(N-i+1):
            if bill[0]*i+bill[1]*j+bill[2]*(N-i-j) == M:
                print(i,j,N-i-j)
                sys.exit()
            
        
    

print(-1,-1,-1)
                
        

Measured memory_bytes: 9112
#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>

using namespace std;

int initv = pow(10, 9);
vector< pair<int, int> > segment_tree;
pair<int, int> dummy = make_pair(-1, initv);

pair<int, int> query(int a, int b, int k, int l, int r){
	if(r<=a || b<=l) return dummy;
	if(a<=l && r<=b) return segment_tree[k];
	
	pair<int, int> vl = query(a, b, k*2+1, l, int((l+r)/2));
	pair<int, int> vr = query(a, b, k*2+2, int((l+r)/2), r);
	if(vl.second < vr.second) return vl;
	else return vr;
}


int main(void){

	// input N & L
	int n, l;
	cin >> n >> l;
	cin.ignore();

	int n_ = 1;
	while(n_ < n){
		n_ *= 2;
	}

	
	segment_tree = vector< pair<int, int> >(2*n_-1, make_pair<int, int>(-1, initv)); // makesegment tree

	string s;
	getline(cin, s); // input series
	stringstream ss;
	ss << s;

	// take in input to segment tree
	for(int i=0 ; i < n ; i++){
		int a;
		ss >> a;
		segment_tree[n_-1+i].first = i;
		segment_tree[n_-1+i].second = a;
	}

	// initialize segment tree
	for(int i = n_-2 ; i >= 0 ; i--){
		if(segment_tree[i*2+1].second < segment_tree[i*2+2].second){
			segment_tree[i] = segment_tree[i*2+1];
		}
		else{
			segment_tree[i] = segment_tree[i*2+2];
		}
	}


	pair<int, int> current_min;
	current_min = dummy; // current_min[0]:id of current min, current_min[1]:value of current min
	for(int i=0 ; ; i++ ){

		// if current_min is out of range, search new current_min
		if(current_min.first < i){
			current_min = query(i, i+l, 0, 0, n_);
		}

		// else, compare current_min and new end
		else{
			if(current_min.second >= segment_tree[n_+i+l-2].second){
				current_min = segment_tree[n_+i+l-2];
			}
		}

		cout << current_min.second;

		if(i+l == n){
			cout << endl;
			break;
		}
		else cout << ' ';
	}

}


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

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

using namespace std;

int main()
{
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  rep(i, 3) {
    if (s[i] == t[i]) {
      ++cnt;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,A,B,a[N];
int cnt[3];
int main()
{
	int i;
	scanf("%d%d%d",&n,&A,&B);
	for(i=1;i<=n;++i) scanf("%d",&a[i]);
	for(i=1;i<=n;++i)
	{
		if(a[i]<=A) ++cnt[0];
		else if(a[i]<=B) ++cnt[1];
		else ++cnt[2];
	}
	printf("%d\n",min(cnt[0],min(cnt[1],cnt[2])));
	return 0;
}

Measured memory_bytes: 256
A, B, C = gets.split.map(&:to_i)

hc = C / 2
c1 = ((A * B) * hc - (A * B) * (C - hc)).abs

ha = A / 2
c2 = ((B * C) * ha - (B * C) * (A - ha)).abs

hb = B / 2
c3 = ((A * C) * hb - (A * C) * (B - hb)).abs

puts [c1, c2, c3].min


Measured memory_bytes: 1788
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

template <long long mod>
long long mod_pow(long long a, long long b) {
    if (b == 0) return 1;
    long long ret = mod_pow<mod>(a, b / 2);
    ret = ret * ret % mod;
    if (b % 2 == 1) ret = a * ret % mod;
    return ret;
}

const ll MOD = TEN(9) + 7;
const int MAX_N = 100000;
int n;
ll x[MAX_N];

int main() {
    fastio();

    cin >> n;
    forn(i, n) cin >> x[i];

    ll ans = 0;
    ll p = 0;
    forn1(i, n - 1) {
        p = (p + mod_pow<MOD>(i, MOD - 2)) % MOD;
        ans = (ans + (x[i] - x[i - 1]) * p % MOD) % MOD;
    }

    forn1(i, n - 1) {
        ans = ans * i % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

#define MAX 114514

vector<bool>isPrime(MAX,true);
void sieve(){
	for(ll i=2;i<MAX;i++){
		if(isPrime[i]){
			for(ll j=i+i;j<114514;j+=i)isPrime[j]=false;
		}
	}
	isPrime[0]=false;
	isPrime[1]=false;
}

int main(){
	sieve();
	int q;
	cin>>q;
	vector<int>l(q),r(q);
	vector<ll>count(MAX);
	for(int i=0;i<q;i++)cin>>l[i]>>r[i];	
	for(int i=3;i<114514;i+=2){
		if(isPrime[i]&&isPrime[(i+1)/2])count[i]++;
	}
	for(int i=3;i<114514;i++)count[i]+=count[i-1];
	for(int i=0;i<q;i++){
		ll ans=count[r[i]]-count[l[i]-1];
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 2304
na,nb,M=map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [[0 for i in range(3)] for j in range(M)]
#C = [[0]*3]*M
s=min(A)+min(B)
t=0

#print(A)
#print(B)

for i in range(M):
	C[i][0],C[i][1],C[i][2] = map(int, input().split())

#print(C)

for j in range(M):
	#print(j)
	t=A[C[j][0]-1]+B[C[j][1]-1]-C[j][2]
	if t<s:
		s=t

print(s)

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

int main() {
    int h, y;

    cin >> h >> y;

    while (h != 0 || y != 0) {
        if (h == 1 || h == 2) {
            for (int i = 0; i < h; i++) {
                for (int s = 0; s < y; s++) {
                    cout << "#";
                }
                cout << endl;
            }
        } else {
            for (int i = 0; i < h; i++) {
                if (i == 0 || (i + 1) == h) {
                    for (int s = 0; s < y; s++) {
                        cout << "#";
                    }
                    cout << endl;
                } else {
                    for (int s = 0; s < y; s++) {
                        if (s == 0 || (s + 1) == y) {
                            cout << "#";
                        } else {
                             cout << ".";
                        }
                    }
                    cout << endl;
                }
            }
        }
        cout << endl;
        cin >> h >> y;
    }

    return 0;
}

Measured memory_bytes: 2988
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

const int MAX_N = 10000;
const int MAX_K = 10;

int X;

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

    cin >> X;

    double l = sqrt(0.25 + 2 * X) - 0.5;

    cout << ceil(l) << "\n";

    return 0;
}

Measured memory_bytes: 3852
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
#include <cassert>
using namespace std;

int main(){
    
    pair<int, int> men[6];
    for(int i=0; i<6; i++){
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        if(tmp2 < tmp1) swap(tmp1, tmp2);
        men[i] = make_pair(tmp1, tmp2);
    }

    sort(men, men+6);

    if(men[0] != men[1] || men[2] != men[3] || men[4] != men[5]){
        cout << "no" << endl;
        return 0;
    }

    if(men[0].first == men[2].first){
        int tmp1 = men[0].second;
        int tmp2 = men[2].second;
        if(tmp2 < tmp1) swap(tmp1, tmp2);
        if(tmp1 != men[4].first || tmp2 != men[2].second){
            cout << "no" << endl;
            return 0;
        }
    }
    else if(men[0].first == men[4].first){
        int tmp1 = men[0].second;
        int tmp2 = men[4].second;
        if(tmp2 < tmp1) swap(tmp1, tmp2);
        if(tmp1 != men[2].first || tmp2 != men[2].second){
            cout << "no" << endl;
            return 0;
        }
    }
    else{
        cout << "no" << endl;
        return 0;
    }

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


Measured memory_bytes: 3128
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {

        static void Main(string[] args)
        {
            string s = ReadLine();
            WriteLine(
                s[0].ToString() + (s.Length-2) + s[s.Length-1].ToString()
                );
        }
    }
}


Measured memory_bytes: 11092
n,m=map(int,input().split())
li=[]
if n==1:
    score="0"
else:
    score="1"+"0"*(n-1)
for i in range(m):
    s,c=map(int,input().split())
    if n!=1 and (s,c)==(1,0):
        print("-1")
        quit()
    li.append([s,c])
    for j in range(len(li)):
        if li[j][0]==s and li[j][1]!=c:
            print("-1")
            quit()
    score=score[:s-1]+str(c)+score[s:]
print(int(score))


Measured memory_bytes: 9180
import sys

N_MAX = 200000 + 5
INF = 10**9 + 7
sys.setrecursionlimit(N_MAX)
MOD = 10**9 + 7

N = int(sys.stdin.readline())

alp = "zabcdefghijklmnopqrstuvwxy"


def name(A, s=""):
    i = A % 26
    z = alp[i]
    s = z + s

    A = A // 26
    if i == 0:
        A -= 1
    if A > 0:
        s = name(A, s)
    return s


print(name(N))


Measured memory_bytes: 9156
// D - Binomial Coefficients
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	int N; cin>>N;
	vector<int> A(N); rep(i, N) cin>>A[i];
	int r = 0, n = *max_element(A.begin(), A.end());
	int half = (n+2-1)/2;
	int mindiff = INT_MAX;
	rep(i, N){
		if(A[i] == n) continue;
		int diff = abs(half - A[i]);// |n/2 - ai|
		if(mindiff > diff){ mindiff = diff; r = A[i]; }
	}
	cout<< n <<" "<< r <<endl;
}

Measured memory_bytes: 640
#include <iostream>

int main() {
  int h, n;
  std::cin >> h >> n;
  int sum;
  for (int i = 0; i < n; ++i) {
    int t;
    std::cin >> t;
    sum += t;
  }
  
  std::cout << (sum >= h ? "Yes" : "No") << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll h, a;
    cin >> h >> a;
    ll ans = 0;
    while (h > 0)
    {
        ans++;
        h -= a;
    }
    cout << ans << endl;
}

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

int main()
{
  int h, w, k;
  cin >> h >> w >> k;
  char c[h][w];
  int a[h],b[w], o[h], p[w];
  rep(i, h) {
    a[i] = 0;
    o[i] = 0;
  }
  rep(i, w) {
    b[i] = 0;
    p[i] = 0;
  }
  int sum = 0;
  rep(i, h){
    rep(j, w){
      cin >> c[i][j];
      if(c[i][j] == '#'){
        a[i]++;
        b[j]++;
        sum++;
      }
    }
  }
  int ans = 0;
  int s = sum, t;
  int cnt;
  for(int i = 0; i < (1 << h); i++){
    rep(q, h) o[q] = 0;
    s = sum;
    cnt = 0;
    int x = i;
    while(x > 0){
      if(x & 1) {
        s -= a[cnt];
        o[cnt]++;
      }
      x = (x >> 1);
      cnt++;
    }        
    //cout << i << ":" << s << endl;
    for(int j = 0; j < (1 << w); j++){
      t = s;
      cnt = 0;
      int y = j;
      while(y > 0){
        if(y & 1) {
          t -= b[cnt];
          rep(m, h){
            if(o[m] == 1 && c[m][cnt] == '#') t++;
          }
        }
        y = (y >> 1);
        cnt++;
      }
      if(t == k) {
        ans++;
      }
    }
  }
  
  cout << ans << endl;
        

  return 0;
}

Measured memory_bytes: 3576
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007
#define BOX 200000

typedef long long ll;

#define rep(i, s, e) for(unsigned int i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)
#define so(a) sort(begin(a), end(a))
#define soR(a) sort(begin(a), end(a), greater<ll>())
#define uni(a) a.erase(unique(begin(a), end(a)), end(a))
#define sum(a) accumulate(begin(a), end(a), 0)


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

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll 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 main() {
	ll N;
	cin >> N;
	set<string> S;
	rep(i, 0, N) {
		string temp;
		cin >> temp;
		S.insert(temp);
	}

	cout << S.size() << endl;

	return 0;
}

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	int n, x[200001];
	int a[200001];
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x[i];
		a[i] = x[i];
	}

	sort(a+1, a+n+1);
	int middles[4];
	for(int i = 0; i < 4; i++) middles[i] = a[n/2-1+i];

	for(int i = 1; i <= n; i++){
		if(x[i] <= middles[1]){
			cout << middles[2] << endl;
		}else if(x[i] >= middles[2]){
			cout << middles[1] << endl;
		}
	}

	return 0;
}

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

int main(){
    int n;
    string s;

    cin >> n >> s;

    int red = 0, answ=0;
    for(int i=0;i<n;i++){
        red += (s[i]=='R');
    }
    for(int i=0;i<red;i++){
        answ += (s[i]=='W');
    }
    cout << answ <<'\n';
    return 0;
}

Measured memory_bytes: 3700
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 111) {
            System.out.println(999);
        }else if (n == 119) {
            System.out.println(991);
        }else if (n == 191) {
            System.out.println(919);
        }else if (n == 199) {
            System.out.println(911);
        }else if (n == 911) {
            System.out.println(199);
        }else if (n == 919) {
            System.out.println(191);
        }else if (n == 991) {
            System.out.println(119);
        }else{
            System.out.println(111);
        }
    }
}

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

int main() {
int N;
  cin >> N;
int nac = 0, nwa = 0, ntl = 0, nre = 0;
  for(int i = 0; i < N; i++){
  string a;
  cin >> a;
  if(a == "AC") {
  	nac++;
  }
  if(a == "WA"){
  	nwa++;
  }
  if(a == "TLE"){
  	ntl++;
  }
  if(a == "RE"){
  	nre++;
  }	
  }

  cout << "AC x " << nac << endl;
  cout << "WA x " << nwa << endl;
  cout << "TLE x " << ntl << endl;
  cout << "RE x " << nre << endl;
  
}

Measured memory_bytes: 3628
import sys
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = in_nl()
    count = Counter(A)

    mod = 10**9 + 7

    if N % 2 == 0:
        f = True
        for i in range(1, N, 2):
            if count[i] != 2:
                f = False
                break

        if f:
            ans = pow(2, N // 2, mod)
        else:
            ans = 0
    else:
        f = (count[0] == 1)
        for i in range(2, N, 2):
            if count[i] != 2:
                f = False
                break

        if f:
            ans = pow(2, N // 2, mod)
        else:
            ans = 0

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 19832
import numpy as np

N, D = map(int,input().split())
cnt = 0

X = np.array([[int(x) for x in input().split()] for i in range(N)])

for j in range(N):
    for k in range(j+1, N):
        cnt += (1 if np.linalg.norm(X[j] - X[k]).is_integer() else 0)        

print(cnt)

Measured memory_bytes: 12432
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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


void Main(){
    int n, q; cin >> n >> q;
    string s; cin >> s;
    vi ruiseki(n+1);
    ruiseki[0] = 0;
    
    rep(i, n){
        if(s[i] == 'A' && s[i+1] == 'C'){
            ruiseki[i+1] = ruiseki[i] + 1;
        }
        else ruiseki[i+1] = ruiseki[i];
    }
    
    /*
    rep(i, n+1){
        cout << ruiseki[i] << " ";
    }
    cout << endl;
    */
    
    while(q--){
        int l, r; cin >> l >> r;
        int ans = ruiseki[r] - ruiseki[l] + 1;
        if(ruiseki[l] == ruiseki[l-1]) ans--;
        if(ruiseki[r] != ruiseki[r-1]) ans--;
        cout << ans << endl;
    }

    return;
}

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

Measured memory_bytes: 3828
x, y, a, b, c = [int(x) for x in input().split()]
red = [int(x) for x in input().split()]
green = [int(x) for x in input().split()]
nocolor = [int(x) for x in input().split()]
red.sort(reverse=True)
green.sort(reverse=True)
nocolor.sort(reverse=True)

eating = red[:x] + green[:y]
eating.sort()
delicious = sum(eating)

# まずは赤と緑で美味しい順に取得し，それをまずい順に並べ直し，
# 美味しい順の無色で置き換えたほうが得なら置き換える。
for e, n in zip(eating, nocolor):
    if e < n:
        delicious = delicious - e + n

print(delicious)


Measured memory_bytes: 23340
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
MOD = 10**9 + 7

def solve(f):
    n = f.read_int()

    fact = [1] * (n+1)
    ifact = [1] * (n+1)
    for i in range(1, n+1):
        fact[i] = (fact[i-1] * i) % MOD
        ifact[i] = pow(fact[i], MOD-2, MOD)

    def nCk(n, k):
        if k < 0 or k > n: return 0
        return (fact[n] * ifact[n-k] * ifact[k]) % MOD

    ans = 0
    c0 = 0
    for i in xrange(n/2,n):
        c1 = (nCk(i-1, n-1-i)*fact[i]*fact[n-i-1] - c0 + MOD) % MOD
        ans = (ans + c1*i) % MOD
        c0 = (c0 + c1) % MOD

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


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

int main(){	
  	int N;
  	string S;
  	cin >> N >> S;
  	for(int i=0; i<S.length(); i++){
      	if(S[i]+N>90){
        	S[i]-=26;
        }
    	S[i] = S[i]+N;
    }
  	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n; cin >> n >> W;
    vector<int>w(n),v(n);
    rep(i,n){
        cin >> w[i] >> v[i];
    }
    vector<int>dp(1000*100*4,INF);
    dp[0] = 0LL;
    rep(i,n){
        for(int j = (int)dp.size() - v[i] ; j >= 0 ; j--){
            if(dp[j] != -INF){
                cmin(dp[j + v[i]],dp[j] + w[i]);
            }
        }
    }
    int ans = -INF;
    rep(i,dp.size())if(dp[i] <= W)cmax(ans,i);
    cout << ans << endl;
}



Measured memory_bytes: 3328
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC051_B solver = new ABC051_B();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC051_B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int k = in.nextInt();
            int s = in.nextInt();

            int counter = 0;
            for (int i = 0; i <= k; ++i) {
                for (int j = 0; j <= k; ++j) {
                    int l = s - (i + j);
                    if (l >= 0 && l <= k) ++counter;
                    else continue;
                    ;
                }
            }

            out.println(counter);
        }

    }
}



Measured memory_bytes: 22996
module Main where

import Data.Functor
import Data.List

main :: IO()
main = do
  { xs <- getInts
  ; let ys = sort xs
  ; putInts (sort xs)
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll n, k; cin >> n >> k;
  vector<ll> v(n); cin >> v;
  sort(v.rbegin(), v.rend());
  ll sum = 0;
  for(ll i = k; i < n; ++i){
    sum += v[i];
  }
  cout << sum << endl;
  return 0;
}


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

int main() {
  ll N;
  vector<ll> a;
  //firstに数字,secondに数字の個数
  vector< pair<ll,ll> > data;
  cin >> N;
  a.resize(N);
  for(int i=0;i<N;i++) {
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  int num=0;
  data.push_back(make_pair(a[0],1));
  for(int i=1;i<N;i++) {
    if(a[i-1]!=a[i]) {
      data.push_back(make_pair(a[i],1));
      num++;
    }else {
      data[num].second++;
    }
  }
  ll ans=0;
  for(int i=0;i<data.size();i++) {
    if(data[i].first<data[i].second) {
      ans += (data[i].second-data[i].first);
    }
    if(data[i].first>data[i].second) {
      ans += data[i].second;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3188
N , M = (int(a) for a in input().split())
stair = [1]*(N+1)
for i in range(1 , M+1) :
    a = int(input())
    stair[a] = 0
 
for i in range(2, N+1) :
    stair[i] *= (stair[i-1] + stair[i-2]) % (10**9+7)
         
print(stair[N])

Measured memory_bytes: 6964
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    a, b = i_map()
    print('Yay!' if a <=8 and b <= 8 else ':(')

if __name__ == '__main__':
    main()


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

/*
1~Nの部分集合のうち、その和がSになるものの個数をかぞえあげる
ただし、部分集合の部分集合みたいになるので、ある集合が複数回数えられる
ただ、数えられる回数は要素数に依存するだろう
例えば1だったら、+他の要素の選び方2^(n - 1)回

つまり持っている要素数とその和の情報さえわかればいい
ただし、和の情報を更新するのがネックになる
要素を追加するたびにS * K回の更新が必要？
O(N * S * K)だと間に合わない

Aが1以上であることに注目する？
冪乗で持っておけばO(N * S * log(K))?

全体から引く？
dp[S][K]???

要素数の情報を減らす
最初は全部使うと考える -> * 1
減らしていく
dp[S][A_all] = 1
dp[S - 1][A_all - Ak] -> 1 * 2みたいにすればよいのでは？

むしろ割るか
*/

int mod = 998244353;
long long dp[3001][3001];

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

int	main(void)
{
	int n, s;
	cin >> n >> s;
	vector<bool> is_visit(s + 1, false);
	dp[0][0] = modpow(2, n);
	is_visit[0] = true;
	long long div_two = modpow(2, mod - 2);
	long long a;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		for (int j = 0; j <= s; j++)
		{
			dp[i + 1][j] += dp[i][j];
			dp[i + 1][j] %= mod;
			if (!is_visit[j]) continue ;
			if (j + a > s) continue ;
			is_visit[j + a] = true;
			dp[i + 1][j + a] += (dp[i][j] * div_two) % mod;
			dp[i + 1][j + a] %= mod;
		}
	}
	cout << dp[n][s] % mod << endl;
	return (0);
}


Measured memory_bytes: 73956
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
    {
        long long int n,d,x,y,c=0;
        double s;

        cin>>n>>d;

        for(int i = 0;i<n;i++){

            cin>>x>>y;

              s = sqrt(x*x+y*y);

              if(s<=d){c++;}

}
cout<<c;
return 0;
    }


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int n,a[N];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for (int i=1;i<=n;i++)
		if (a[i+1]<i+1){
			int j=i;
			while (j<n&&a[j+1]==i)
				j++;
			int f1=(j-i)&1,f2=(a[i]-i)&1;
			puts(f1||f2?"First":"Second");
			return 0;
		}
	return 0;
}

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

int main() {
  ll a,b; cin>>a>>b;
  if((a+b)%2==0)cout<<(a+b)/2;
  else{cout<<"IMPOSSIBLE";}
}



Measured memory_bytes: 256