akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main()
{
    string s; cin >> s;
    int n = s.size();
    for(auto &i: s)i -= (i != '?' ? 'A' : 0);
    vector<vector<ll>> dp(n + 1, vector<ll>(4)); //dp[i] := i文字目まで見てj = 0が未A, j = 3がABC
    dp[0][0] = 1;

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

        //一致のやつ
        for(int j = 0; j < 3; j++) {
            if(s[i] == '?' || s[i] == j) {
                dp[i + 1][j + 1] += dp[i][j];
                dp[i + 1][j + 1] %= mod;
            }
        }
        for(int j = 0; j < 4; j++){dp[i + 1][j] += dp[i][j] * (s[i] == '?' ? 3 : 1);dp[i + 1][j] %= mod;}
    }
    cout << dp[n][3] << endl;
}

Measured memory_bytes: 7424
N, x = map( int, input().split())
A = list( map( int, input().split()))
ans = 0
if A[0] > x:
    ans += A[0] - x
    A[0] = x
for i in range(N-1):
    if A[i] + A[i+1] > x:
        ans += A[i]+A[i+1]-x
        A[i+1] = x - A[i]
print(ans)

Measured memory_bytes: 14132
'use strict'

const Main = (input) => {
  const tmp = input.trim().split('\n')
  const S = tmp[0]
  const T = tmp[1]

  let result = 'Yes'

  const tmpStr = T.replace(S, '')

  if (T.slice(-1) === tmpStr && tmpStr.length === 1) {
    result = 'Yes'
  } else {
    result = 'No'
  }

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29644
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
  int N,i;
  scanf("%d", &N);
  double v[N];
  for(i=0;i<N;i++){
    scanf("%le", &v[i]);
  }
  sort(v,v+N);
  for(i=0;i<N;i++){
    v[i+1] = (v[i] + v[i+1])/2;
  }  
  printf("%le\n",v[N-1]);
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

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

struct Main {
    l: i32,
}
impl Main {
    fn invoke(&mut self) {
        let a = self.l as f64 / 3.0;
        println!("{}", a * a * a);
    }
}



fn main() {
    let l: i32 = read();
    Main {
        l: l,
    }.invoke()
}


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

int main(){
  int N, K;
  cin >> N >> K;

  list<int> A;
  list<bool> ans;
  int n;
  for (n = 1; n <= K; n++){
    int t;
    cin >> t;
    A.push_back(t);
  }

  for (; n <= N; n++){
    int shift_out;
    int shift_in;
    shift_out = A.front();
    cin >> shift_in;
    if (shift_in > shift_out){
      ans.push_back(true);
    }else{
      ans.push_back(false);
    }
    A.pop_front();
    A.push_back(shift_in);
  }

  for_each(ans.cbegin(), ans.cend(), [](int x){
      cout << (x ? "Yes" : "No") << endl;
    });
  
  return 0;
}


Measured memory_bytes: 9876
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(long long i=(n)-1;i>=0;--i)
#define iFr(i,n) for(long long i=(n);i>0;--i)

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,m,h;
  cin>>n>>h>>m;
  cout<<(n-h+1)*(n-m+1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int h,w,a,b,i,j;
  cin>>h>>w>>a>>b;
  int ans[h][w];
  rep(i,h){
      rep(j,w){
       ans[i][j]=0;
      }
  }
  rep(i,b){
      rep(j,a){
          ans[i][j]=1;
      }
  }
  for(i=b;i<h;i++){
      for(j=a;j<w;j++){
          ans[i][j]=1;
      }
  }
  rep(i,h){
      rep(j,w){
       cout<<ans[i][j];
      }
    cout<<endl;
  }
}


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

using namespace std;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define bas(x) #x << ": " << x << " "
#define prarr(x, n) cout << #x << ": "; for (int qsd = 0; qsd < n; qsd++) cout << x[qsd] << " "; cout << endl;
#define prarrv(x) cout << #x << ": "; for (int qsd = 0; qsd < (int)x.size(); qsd++) cout << x[qsd] << " "; cout << endl;
#define ppair(x) "(" << x.first << ", " << x.second << ")"
#define inside sl<=l&&r<=sr
#define outside sr<l||r<sl

typedef long long ll;

int main(){
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);

	int n, x;
	cin >> n >> x;
	if (x == 1 || x == 2*n-1) cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		vector<int> ans(2*n);
		ans[n] = x;
		int cur = x;
		for (int i = n-1; i > 0; i--){
			cur -= 1;
			if (cur < 1) cur += 2*n-1;
			ans[i] = cur;
		}
		cur = x;
		for (int i = n+1; i < 2*n; i++){
			cur++;
			if (cur >= 2*n) cur -= 2*n-1;
			ans[i] = cur;
		}

		for (int i = 1; i < ans.size(); i++) cout << ans[i] << " "; cout << endl;
	}
	
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define N 110
#define INF 0x3f3f3f3f
using namespace std;
typedef struct {
    int w;
    int s;
    int e;
}Edge;
Edge edge[N*N];
int m[N][N];
int father[N];
int n;
int k = 0;  //edge的下标
int result = 0;
int findfather(int x){
    return x == father[x] ? x : findfather(father[x]);
}
int cmp(Edge a, Edge b){
    return a.w < b.w;
}
void Kruscal(){
    for(int u = 0; u < k; u++){
        int s = edge[u].s;
        int e = edge[u].e;
        if(findfather(s) != findfather(e)){
            father[findfather(e)] = s;
            result += edge[u].w;
        }
    }
    printf("%d\n", result);
}
int main(){

    scanf("%d", &n);
    for(int i = 1; i <= n; i++) father[i] = i;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            int b;
            scanf("%d", &b);
            m[i][j] = b;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n ;j++){
            if(m[i][j] != -1) {
                edge[k].w = m[i][j];
                edge[k].s = i;
                edge[k].e = j;
                k++;
            }
        }
    }
    sort(edge, edge+k, cmp);
    Kruscal();
    return 0;
}



Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL V<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define MAX 1e18
#define MIN -1e18
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v;
map<LL,LL>u;
void Y()
{
    cout<<"Yes"<<endl;
}
void N()
{
    cout<<"No"<<endl;
}
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z=0,r;
    string a,b,c;
    DL x,y;
   cin>>n>>m;
   k=0;
   for(i=0;i<m;i++)
   {
       cin>>o;
       k+=o;
   }
   cout<<max((LL)-1,n-k)<<endl;

    return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<math.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define rpt(n) for(register int ttxyc=0;ttxyc<(n);++ttxyc)//宏定义
long long n,a;
int len(long long x)
{
	register int ans=0;
	for(;x;x/=10,++ans);
	return ans;
}
main()
{
	scanf("%lld",&n);
	for(a=sqrt(n);n%a;--a);
	printf("%d\n",max(len(a),len(n/a)));
}/**/

Measured memory_bytes: 128
n = gets.chomp.to_i
h = gets.chomp.split.map(&:to_i)
result = []
result[0] = 0
result[1] = (h[0] - h[1]).abs

2.upto(n-1) do |i|
  result[i] = [result[i-2] + (h[i-2] - h[i]).abs, result[i-1] + (h[i-1] - h[i]).abs].min
end
p result[n-1]


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

int main() {
    string s;
    cin >> s;
    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    }
    if(s == "Cloudy"){
        cout << "Rainy" << endl;
    }
    if(s == "Rainy"){
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
  int N, K;
  scanf("%d %d", &N, &K);
  int A[N];
  int x[N];
  for (int i=0 ; i<N ; i++) x[i] = 0;
  for (int i=0 ; i<N ; i++) {
    int num;
    scanf("%d", &num);
    x[num-1]++;
  }
  sort(x, x+N);
  int* tmp = lower_bound(x, x+N, 1);
  int pos = (int)(tmp-x);
  int res = 0;
  for (int i=pos ; i<N-K ; i++) {
    res += x[i];
  }
  printf("%d\n", res);
}

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

main()
{
    int a,b,c,d,e,f;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
    int ans[4];
    double mx=0.0;
    for(int m=0;;m++)
    {
        for(int n=0;;n++)
        {
            if(m==0 && n==0)continue;
            if(100*(m*a+n*b)>f)break;
            for(int t=0;;t++)
            {
                for(int s=0;;s++)
                {
                    if(100*(m*a+n*b)+t*c+s*d>f)break;
                    if(t*c+s*d>(m*a+n*b)*e)break;
                    if(t*c+s*d>mx*(m*a+n*b))
                    {
                        ans[0]=m,ans[1]=n,ans[2]=t,ans[3]=s;
                        mx=(double)(t*c+s*d)/(double)(m*a+n*b);
                        //cout<<mx<<' '<<m<<' '<<n<<' '<<t<<' '<<s<<'\n';
                    }
                }
                if(100*(m*a+n*b)+t*c>f)break;
            }
        }
        if(100*m*a>f)break;
    }
    if(mx==0.0)printf("%d %d\n",100*a,0);
    //printf("%d %d %d %d\n",ans[0],ans[1],ans[2],ans[3]);
     else printf("%d %d\n",100*(a*ans[0]+b*ans[1])+c*ans[2]+d*ans[3],c*ans[2]+d*ans[3]);
    return 0;
}



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

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#define pb push_back
#define mp make_pair
#define sz(a) (ll)(a).size()
#define all(a) a.begin(), a.end()
#define ff first
#define ss second
#define endl "\n"

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
//K-th smallest
//cout << k << "rd smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;


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

ll mod=1000000007;

ll power(ll x, ll y) 
{
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2);
	if (y%2 == 0)
		return (temp*temp)%mod;
	else
		return (((x*temp)%mod)*temp)%mod; 
}

vector<ll> dp(100005, INT_MAX);

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,W;
	cin>>n>>W;
	vector<ll> w,v;
	ll i;
	dp[0]=0;
	for(i=0;i<n;i++)
	{
		ll w1,v1;
		cin>>w1>>v1;
		w.pb(w1);
		v.pb(v1);
	}
	ll j;
	ll ans=0;
	for(i=0;i<n;i++)
	{
		ll we=w[i];
		ll val=v[i];
		for(j=100000;j>=val;j--)
		{
			if(dp[j-val]==INT_MAX)
				continue;
			dp[j]=min(dp[j], dp[j-val]+we);
			if(dp[j]<=W)
				ans=max(ans,j);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
N = gets.to_i
No = 1.upto(N).to_a
A = gets.split(/ /).map{|s| s.to_i}
A.unshift(nil)

pool = Array.new(N)
1.upto(N) do |i|
    v = i - A[i]
    (pool[v] ||= []) << i if v > 0
end

count = 0
1.upto(N-1) do |i|
    po = pool[i + A[i]]
    count += po.size if po
end
puts count


Measured memory_bytes: 36192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

const int MAX = 200010;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//main関数にCOMinit();を忘れない

ll pat(ll n,ll m){
    return ((n*m%MOD*(n+m-2ll))%MOD)*inv[2]%MOD;
}

ll pat2(ll n){
    return ((n*(n+1)%MOD*inv[2])%MOD*-1+MOD)%MOD;

}

void solve(int ca){
    COMinit();
    ll N,M,K; cin>>N>>M>>K;

    ll ans=0ll;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            ll cnt=0ll;
            (cnt+=pat(i+1,j+1))%=MOD;
            (cnt+=pat(i+1,M-j))%=MOD;
            (cnt+=pat(N-i,j+1))%=MOD;
            (cnt+=pat(N-i,M-j))%=MOD;

            (cnt+=pat2(i))%=MOD;
            (cnt+=pat2(j))%=MOD;
            (cnt+=pat2(N-i-1))%=MOD;
            (cnt+=pat2(M-j-1))%=MOD;

            (cnt*=COM(N*M-2,K-2))%=MOD;

            (ans+=cnt)%=MOD;
        }
    }
    (ans*=inv[2])%=MOD;
    cout<<ans<<endl;

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 4992
package main

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

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
)

func main() {
	scanner.Split(bufio.ScanWords)
	n := scanInt()
	works := make(works, n)
	for i := 0; i < n; i++ {
		w := work{time: scanInt(), deadline: scanInt()}
		works[i] = w
	}

	// sort.Slice(works, func(i, j int) bool {
	// 	return works[i].deadline < works[j].deadline
	// })
	sort.Sort(works)

	elapsed := 0
	for i := 0; i < n; i++ {
		elapsed += works[i].time
		if elapsed > works[i].deadline {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}

type work struct {
	time     int
	deadline int
}

type works []work

func (w works) Len() int {
	return len(w)
}

func (w works) Swap(i, j int) {
	w[i], w[j] = w[j], w[i]
}

func (w works) Less(i, j int) bool {
	return w[i].deadline < w[j].deadline
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanText(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanTexts(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanText()
	}
	return s
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

// greatest common divisor(最大公約数)
func gcd(a, b int) int {

	if a < b {
		a, b = b, a
	}

	for {
		mod := a % b
		if mod == 0 {
			return b
		}
		a, b = b, mod
	}
}

// latest common multiple(最小公倍数)
func lcm(a, b int) int {
	return (a / gcd(a, b)) * b
}


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

struct Point {
  int x, y;
  Point() : x(0), y(0) {}
  Point(int x, int y) : x(x), y(y) {}
};

std::istream &operator>>(std::istream &is, Point &point) {
  is >> point.x >> point.y;

  return is;
}

int main() {
  int N;
  std::cin >> N;

  std::vector<Point> r(N), b(N);

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

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

  sort(b.begin(), b.end(), [](const Point& a, const Point& b) {
    return a.x < b.x || (a.x == b.x && a.y < b.y);
  });

  sort(r.begin(), r.end(), [](const Point& a, const Point& b) {
    return a.y > b.y || (a.y == b.y && a.x > b.x);
  });

  std::vector<bool> used(N, false);
  int answer = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (b[i].x > r[j].x && b[i].y > r[j].y && !used[j]) {
        used[j] = true;
        answer++;
        break;
      }
    }
  }

  std::cout << answer << std::endl;
}


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

using namespace std;

using ll = long long;

template <class T>
struct FenwickTree {
    int n;
    std::vector<T> x;
    FenwickTree(int _n = 0) : n(_n), x(n + 1, 0) {}
    int size() const { return n; }
    T Sum(int r) const {
        T S = 0;
        for (r = r - 1; r >= 0; r = (r & (r + 1)) - 1) S += x[r];
        return S;
    }
    T Sum(int l, int r) const { return Sum(r) - Sum(l); }
    void Add(int k, const T &a) {
        for (; k < n; k |= k + 1) x[k] += a;
    }
    void Set(int k, const T &a) { Add(k, a - Sum(k, k + 1)); }
};


class ProblemD {
public:
    ProblemD(ll _n) : n(_n), a(_n + 1), s(_n + 1, 0) {}
    void Input() { for (int i = 1; i <= n; ++i) cin >> a[i]; }

    int Solve() {
        const ll lim = ceil(n * (n + 1) / 4.0);

        ll lb = 0, ub = *max_element(a.begin(), a.end()) + 1;
        while (ub - lb > 1) {
//            cout << "lb = " << lb << ", ub = " << ub << endl;
            ll mid = 0.5 * (lb + ub), res = Check(mid);
//            cout << "x = " << mid << ", num = " << res << ", lim = " << lim << endl;

            if (lim <= res) lb = mid;
            else ub = mid;
        }

        return lb;
    }

private:
    ll n;
    vector<int> a;
    vector<ll> s;

    ll Check(const int x) {
        for (int i = 1; i <= n; ++i) s[i] = (x <= a[i] ? 1 : -1);
        for (int i = 1; i <= n; ++i) s[i] += s[i - 1];


        ll res = 0;
        FenwickTree<int> tree(2 * n + 1);

        tree.Add(s[0] + n, 1);
        for (int i = 1; i <= n; ++i) {
            res += tree.Sum(0, s[i] + n + 1);
            tree.Add(s[i] + n, 1);
        }

        return res;
    }
};

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

    int n;
    cin >> n;
    ProblemD p(n);
    p.Input();
    cout << p.Solve() << endl;

    return 0;
}

Measured memory_bytes: 2288
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int t = 0;

		t = a;
		a = b;
		b = t;

		t = a;
		a = c;
		c = t;

		System.out.println(a + " " + b + " " + c);

	}

}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define ll long long int


int main(){
    string s; cin >> s;
    int N = s.size(),cnt = 0,ans = 0;
    for(int i=0;i<N;i++){
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C'){
            cnt ++;
            ans = max(ans,cnt);     
        }else{
            cnt = 0;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
  int N, i, d1, d2, ans=0;
  cin >> N;
  int d[N];
  for(i=0; i<N; i++) cin >> d[i];
  if(N%2 == 1) ans = 0;
  else{
    sort(d, d+N);
    d1 = d[N/2 -1]; d2 = d[N/2];
    ans = d2 - d1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)

void solve()
{
    string s;
    cin >> s;
    int n = (int) s.length();
    vector<char> v;
    for(int i = 0; i < n; i++)
    {
        if(s[i] == 'B' && v.size() > 0)
        {
            v.pop_back();
        }
        else if(s[i] != 'B')
        {
            v.pb(s[i]);
        }
    }
    for(int i = 0; i < (int) v.size(); i++)
    {
        cout << v[i];
    }
    //cout << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    solve();
    return 0;
}

Measured memory_bytes: 256
import Data.List
import Data.Maybe
import Data.Array.IO
import qualified Data.ByteString.Lazy.Char8 as C

newA :: [[C.ByteString]] -> IO ()
newA xs = do
  ary <- newArray (0,2000000) 0
  solve ary xs 0 0

toI :: C.ByteString -> Int
toI = fst . fromJust . C.readInt

printArray :: IOUArray Int Int -> Int -> Int -> IO ()
printArray ary fs ls
  | fs == ls = return ()
  | otherwise = do
      x <- readArray ary (ls-1)
      if (x == (-1)) then
        printArray ary fs (ls-1)
        else do
        putStr $ show x
	printArray' ary	fs (ls-1)
	putStrLn ""

printArray' :: IOUArray Int Int -> Int -> Int -> IO ()
printArray' ary fs ls
  | fs == ls = return ()
  | otherwise = do
      x <- readArray ary (ls-1)
      if (x == (-1)) then
	printArray' ary fs (ls-1)
	else do
	putStr " "
	putStr $ show x
	printArray' ary	fs (ls-1)

solve :: IOUArray Int Int -> [[C.ByteString]] -> Int -> Int -> IO ()
solve ary [] fs ls = printArray ary fs ls
solve ary all@([a]:xs) fs ls
  | C.length a > 6 && C.index a 6 == 'F' = do
      x <- readArray ary (ls-1)
      if (x == (-1)) then
        solve ary all fs (ls-1)
        else solve ary xs fs (ls-1)
  | C.length a > 6 && C.index a 6 == 'L' = do
      x <- readArray ary fs
      if (x == (-1)) then
        solve ary all (fs+1) ls
        else solve ary xs (fs+1) ls
solve ary ([a,b]:xs) fs ls
  | C.index a 0 == 'i' = do
      writeArray ary ls (toI b)
      solve ary xs fs (ls+1)
solve ary ([_,a]:xs) fs ls = do
  search ary (toI a) fs ls
  solve ary xs fs ls
    where search ary i f l
            | f == l = return ()
            | otherwise = do
                x <- readArray ary (l-1)
                if (x == i) then
                  writeArray ary (l-1) (-1)
                  else search ary i f (l-1)

main = getLine >> C.getContents >>= newA . map C.words . C.lines


Measured memory_bytes: 36904
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int ck(int x,int n){
	int s=0;
	for(int i=0;i<n;i++){
		s+=(a[i]-1)/x;
	}
	return s;
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	int l=1,r=1e9,mid;
	while(l<r){
		mid=l+r>>1;
		if(ck(mid,n)<=k)r=mid;
		else l=mid+1;
	}
	printf("%d",r);
} 


Measured memory_bytes: 4500
#include <iostream>
#include <algorithm>
#include <queue>
#include <climits>

#define INF INT_MAX>>1 //要climits#includ

using namespace std;

typedef long long ll;

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

typedef struct robot{
	int x;
	int y;
	int dir;
	int cost;
}robot;

int main() {
	while(1) {
		int w, h; cin >> w >> h;
		if(!w && !h) break;

		int s[30][30];
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				cin >> s[i][j];
			}
		}
		int c[4];
		for(int i=0; i<4; i++){
			cin >> c[i];
		}

		int dp[30][30][4];
		fill(dp[0][0], dp[30][0], INF);
		dp[0][0][1] = 0;
		robot initial ={0, 0, 1, 0};
		queue<robot> q;
		q.push(initial);

		while(!q.empty()) {
			robot prev = q.front(); 
			q.pop();
			if(prev.cost > dp[prev.y][prev.x][prev.dir]) continue;

			for(int i = 0; i < 4; i++) {
				robot next;
				next.dir = (prev.dir + i) % 4;
				next.cost = prev.cost;
				if(s[prev.y][prev.x] != i) next.cost += c[i];
				next.y = prev.y + dy[next.dir];
				next.x = prev.x + dx[next.dir];
				if(next.y < 0 || h <= next.y || next.x < 0 || w <= next.x) continue;
				if(dp[next.y][next.x][next.dir] > next.cost) {
					dp[next.y][next.x][next.dir] = next.cost;
					q.push(next);
				}	
			}
		}

		int ans = INF;
		for(int i = 0; i < 4; i++){
			ans = min(ans, dp[h - 1][w - 1][i]);
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3176
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n,m;
bool e[500][500];
int dis[500];

void dfs(int c)
{
	rep(i,n)if(e[c][i]&&dis[i]>dis[c]+1)
	dis[i]=dis[c]+1,dfs(i);
}

int main()
{
	while(cin>>n>>m,n||m)
	{
		rep(i,n)fill_n(e[i],n,0);
		rep(i,m)
		{
			int a,b; cin>>a>>b; a--,b--;
			e[a][b]=e[b][a]=1;
		}
		fill_n(dis,n,inf); dis[0]=0;
		dfs(0);
		int ans=0;
		for(int i=1;i<n;i++)if(dis[i]<3)ans++;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1120
def main():
    s = input()


    flag = 0
    t = ""
    u = ""

    for i in s:
        if i == "A":
            flag = 1
        if flag == 1:
            t += i

    flag = 0

    for i in t[::-1]:
        if i == "Z":
            flag = 1
        if flag ==1:
            u += i

    print(len(u))

if __name__ == "__main__":
        main()


Measured memory_bytes: 3816
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main()
{
    int k;
    string s;
    cin>>k;
    getchar();
    getline(cin,s);
    if(s.length()<=k)
        cout<<s;
    else
    {
        for(int i=0;i<k;i++)
        {
            cout<<s[i];
        }
            cout<<"...";
    }
    return 0;
}


Measured memory_bytes: 3640
// inputに入力データ全体が入る
function Main(input) {
  lines = input.split("\n")
  line = lines[0].split(' ')
  ans = 0
  a = line[0] * 1
  b = line[1] * 1
  if (a > b) {
    ans += a
    a--
  } else {
    ans += b
    b--
  }
  if (a > b) {
    ans += a
  } else {
    ans += b
  }
  console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

enum {L, R};

const int keys[] = {
//a, b, c, d, e, f, g, h, i, j, k, l, m, n,
  L, L, L, L, L, L, L, R, R, R, R, R, R, R,
//o, p, q, r, s, t, u, v, w, x, y, z
  R, R, L, L, L, L, R, L, L, L, R, L
};

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  for (;;) {
    string line;
    cin >> line;
    if (line == "#") break;

    int len = line.length();
    int prv = keys[line[0] - 'a'];
    int count = 0;

    for (int i = 1; i < len; i++) {
      int cur = keys[line[i] - 'a'];
      if (prv != cur) count++;
      prv = cur;
    }

    cout << count << endl;
  }

  return 0;
}

Measured memory_bytes: 1188
void main()
{
    long n = rdElem;
    long[] a = rdRow;

    auto g = a.sort!"a < b".group.array;
    long now = !(n & 1);
    long result;
    foreach (x; g)
    {
        bool ok = true;
        if (x[0] == now)
        {
            if (x[0] == 0)
            {
                if (x[1] != 1) ok = false;
            }
            else
            {
                if (x[1] != 2) ok = false;
            }
        }
        else ok = false;
        if (!ok)
        {
            0.writeln;
            return;
        }
        now += 2;
    }

    modPow(2, n/2).writeln;
}

long modPow(long x, long y)
{
    long result = 1;
    while (y > 0)
    {
        if (y & 1) result = result * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return result;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4412
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll w,h,x,y;

    cin >> w >> h >> x >> y;

    cout << setprecision(17) << fixed;

    cout << (double)(w*h)/2.0 << " ";

    if(w % 2 == 0 && h % 2 == 0 && w/2 == x && h/2 == y){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
long long int dp[120][100020] = {};
int main() {
	int N, W;
	cin >> N >> W;
	vector<vector<int>> s(N + 20);
	for (int i = 1; i <= N; i++) {
		int a, b;
		cin >> a >> b;
		s[i].push_back(a);
		s[i].push_back(b);
	}
	for (int i = 1; i <= N; i++) {
		int w, v;
		w = s[i][0];
		v = s[i][1];
		for (int j = 0; j <= W; j++) {
			if (j - w < 0) {
				dp[i][j] = dp[i - 1][j];
			}
			else {
				dp[i][j] = max(dp[i - 1][j - w] + v, dp[i - 1][j]);
			}
		}
		if (i == N) {
			cout << dp[i][W];
		}
	}
}

Measured memory_bytes: 79360
n=int(input())
lis=list(int(input()) for _ in range(n))
lis2=lis
lis2=sorted(lis2)
MAX=lis2[-1]
second=lis2[-2]
if lis.count(MAX) ==1:
    lis3=[MAX for _ in range(n)]
    lis3[lis.index(MAX)]=second
    for i in range(n):
        print(lis3[i])
        
else:
    for _ in range(n):
        print(MAX)

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

long long m,n,x,y;
long long f[12]= {0,9,18,108,198,1098,1998,10998,19998,109998,199998,1099998};  

long long find(long long x) {
    if (x==0) return 0;		
    if (x<10) return x;		
    long long w,i,ans,t,na,a,b,nx;
    w=0;
    nx=x;
    while (nx) {		//求数x的位数
        w++;
        nx/=10;
    }
    ans=f[w-1];			//ans初始化
    t=1;
    for (int k=1; k<=(w/2); k++) t*=10;
    if (w%2==0) {   //处理位数为偶数的数
        a=(x/t);
        b=(x%t);
        t=t/10;
        ans=ans+(a-t);
        na=0;
        while (a) {
            na=na*10+a%10;
            a/=10;
        }
    } else {       //处理位数为奇数的数
        a=(x/t);
        t*=10;
        b=(x%t);
        t=t/10;
        ans=ans+(a-t);
        na=0;
        while (a) {
            na=na*10+a%10;
            a/=10;
        }
    }
    if (b>=na) ans++;
    return ans;

}

int main() {
    while (cin>>m>>n) {
        m=m-1;
        x=find(m);  //求1到m有多少个回文数
        y=find(n);  //求1到n有多少个回文数
        cout<<y-x<<endl;
    }
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  string s;
  cin >> s;
  if (s == "ABC") {
    cout << "ARC" << endl;
  }
  else {
    cout << "ABC" << endl;
  }
}


Measured memory_bytes: 3632
n, m = map(int, input().split())

if m % 2 == 0:
    for i in range(1, m // 2 + 1):
        print(i, m - i + 1)
        print(m + i, 2 * m - i + 2)
else:
    for i in range(m // 2 + 1):
        if i == 0:
            print(1, m + 1)
        else:
            print(i + 1, m - i + 1)
            print(m + i + 1, 2 * m - i + 2)


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

int main (){

    long long int A,B,K,i;
    map<int,int>m;
    cin >> A >> B >> K;
    for(i = A; i <= A+K-1; i++) {
        cout << i << endl;
        m[i]++;
        if(i == B){
            return 0;
        }
    }

    for(i = B-K+1; i <= B; i++) {
        if(m[i] == 0) {
            cout << i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int mai = N/1000;
        int change = 0;
        if (N%1000 != 0) {
            change = 1000*mai + 1000 - N;
        } else {
            change = 1000*mai  - N;
        } 
        System.out.println(change);
    }
}

Measured memory_bytes: 35700
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Node{
	bool operator<(const struct Node &arg) const{
		return weight < arg.weight;
	};
	int from,to,weight;
};

int parent[101],height[101];

int getParent(int id){
	if(parent[id] == id)return id;
	else{
		return parent[id] = getParent(parent[id]);
	}
}

bool isSame(int a, int b){
	return getParent(a) == getParent(b);
}

void unite(int a,int b){
	int a_parent = getParent(a);
	int b_parent = getParent(b);

	if(a_parent == b_parent)return;

	if(height[a_parent] > height[b_parent]){
		parent[b_parent] = a_parent;
	}else{
		if(height[a_parent] == height[b_parent])height[b_parent]++;
		parent[a_parent] = b_parent;
	}
}


int main(){

	int V,E,ans,maximum,minimum;
	bool FLG;
	Node nodes[4950];

	while(true){
		scanf("%d %d",&V,&E);
		if(V == 0 && E == 0)break;

		for(int i = 1; i <= V; i++){
			parent[i] = i;
			height[i] = 0;
		}

		for(int i = 0; i < E; i++){
			scanf("%d %d %d",&nodes[i].from,&nodes[i].to,&nodes[i].weight);
		}

		sort(nodes,nodes+E);

		maximum = 0;
		minimum = BIG_NUM;

		for(int i = 0; i < E; i++){
			if(!isSame(nodes[i].from,nodes[i].to)){
				maximum = max(maximum,nodes[i].weight);
				minimum = min(minimum,nodes[i].weight);
				unite(nodes[i].from,nodes[i].to);
			}
		}

		FLG = true;
		for(int i = 2; i <= V; i++){
			if(!isSame(1,i)){
				FLG = false;
				break;
			}
		}

		if(!FLG){
			printf("-1\n");
			continue;
		}

		ans = maximum - minimum;

		for(int slim = 0; slim <= ans-1; slim++){
			for(int start = 0; start < E;start++){

				for(int i = 1; i <= V; i++){
					parent[i] = i;
					height[i] = 0;
				}

				maximum = 0;
				minimum = BIG_NUM;

				for(int i = start;i < E && nodes[i].weight <= nodes[start].weight+slim;i++){
					if(!isSame(nodes[i].from,nodes[i].to)){
						maximum = max(maximum,nodes[i].weight);
						minimum = min(minimum,nodes[i].weight);
						unite(nodes[i].from,nodes[i].to);
					}
				}

				FLG = true;
				for(int i = 2; i <= V; i++){
					if(!isSame(1,i)){
						FLG = false;
						break;
					}
				}

				if(FLG){
					ans = slim;
					break;
				}
			}
			if(FLG)break;
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 2620
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
dif = T1*A1+T2*A2-T1*B1-T2*B2
if dif==0:
    print("infinity")
elif dif>0:
    if B1>A1:
        k = int(((B1-A1)*T1)/dif)
        if abs(((B1-A1)*T1)/dif-round(((B1-A1)*T1)/dif))<1e-20:
            print(2*round(((B1-A1)*T1)/dif))
        else:
            print(2*k+1)
    else:
        print(0)
else:
    if A1>B1:
        k = int(((A1-B1)*T1)/abs(dif))
        if abs((A1-B1)*T1/abs(dif)-round(((A1-B1)*T1)/abs(dif)))<1e-20:
            print(2*round(((A1-B1)*T1)/abs(dif)))
        else:
            print(2*k+1)
    else:
        print(0)

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

int main(){
	string s;
	cin>>s;
	bool flag1=false;
	bool flag2=false;
	bool flag3=false;
	if(s[0]=='A') flag1=true;
	int cnt=0;
	int pos=0;
	for(int i=2; i<s.size()-1; i++){
		if(s[i]=='C'){
			cnt++;
			pos=i;
		}
	}
	if(cnt==1) flag2=true;
	cnt=0;
	for(int i=1; i<s.size(); i++){
		if(i==pos) continue;
		if(isupper(s[i])) cnt++;
	}
	if(cnt==0) flag3=true;
	if(flag1==flag2&&flag2==flag3) cout<<"AC"<<endl;
	else cout<<"WA"<<endl;
}

Measured memory_bytes: 256
uses math;
var x,y,a,n,k:longint;
begin
  readln(k,n);
  for x:=0 to k do
  begin
    y:=min(n-x,k)-max(n-x-k,0)+1;
    if y>0 then
      inc(a,y);
  end;
  writeln(a);
end.

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define int long long
signed main(){
    int n,m;
    cin>>n>>m;
    char a[50][50],b[50][50];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            cin>>b[i][j];
        }
    }
    bool ans=false;
    for(int i=0;i<=n-m;i++){
        for(int j=0;j<=n-m;j++){
            int count=0;
            for(int k=0;k<m;k++){
                for(int l=0;l<m;l++){
                    if(a[i+k][j+l]==b[k][l])count++;
                }
            }
            if(count==m*m)ans=true;
        }
    }
    if(ans==true)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int n; cin >>n;
  vector<pair<int,int>> a(n),b(n);
  rep(i,n){
    int x,b; cin >>x >>b;
    a[i]={x,b};
  }
  rep(i,n){
    int c,d; cin >>c >>d;
    b[i]={c,d};
  }
  
  int cnt=0;
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  set<int> st;
  int j=0;
  rep(i,n){
    int border=b[i].first;
    while(j<n and a[j].first<border) st.insert(a[j++].second);
    auto itr=st.upper_bound(b[i].second);
    if(itr==st.begin())continue;
    cnt++;
    st.erase(--itr);
  }
  print(cnt);
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> p(N);
    REP(i, N)
    {
        cin >> p[i];
    }
    sort(ALL(p));

    ll ans = 0;
    REP(i, K)
    {
        ans += p[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 3632
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    int n; cin >> n;
    vector<ll> as(n);
    for(int i = 0; i < n; i++){
        cin >> as[i];
    }
    ll ans = 0;
    while(1){
        sort(as.rbegin(), as.rend());
        // if(as[0] < n && as.back() >= 0){ break; }
        if(as[0] < n){ break; }
        ll num = as[0] / n;
        as[0] -= num * n;
        for(int i = 1; i < n; i++){
            as[i] += num;
        }
        ans += num;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
dic = {i+1:[] for i in range(N)}

for i in range(M):
    f,g = map(int,input().split())
    dic[f].append(g)
    dic[g].append(f)


stack = [[1,1,[1]]]
root = 0
while len(stack) >0:
    now = stack[-1][0]
    length = stack[-1][1]
    visited = stack[-1][2]
    del stack[-1]
    for next in dic[now]:
        if next not in visited:
            temp = visited.copy()
            if length +1 <=N-1:
                temp.append(next)
                stack.append([next,length+1,temp])
            elif length +1 == N:
                root += 1


print(root)

Measured memory_bytes: 3064
#include <iostream>
#include <utility>

using namespace std;

struct Result {
  int residue;
  int count;
};

unsigned calc_log(int X, int e)
{
  unsigned count =0;
  while (X >= e) {
    X /= e;
    ++count;
  }
  return count;
}

int calc_residue(int X, int e)
{
  unsigned log = calc_log(X, e);
  int subtrahend = 1;
  for (unsigned l=0; l<log; ++l) {
    subtrahend *= e;
  }
  return X - subtrahend;
}

int calc(int N)
{
  if (N < 6)
    return N;
  int residue9 = calc_residue(N,9);
  int residue6 = calc_residue(N,6);
  int count9 = calc(residue9);
  int count6 = calc(residue6);
  return min(count9,count6)+1;
}

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

  unsigned count = calc(N);

  cout << count << endl;
  
  return 0;
}


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

using namespace std;

string n;
int d;
long long dp[10010][110][2];
const long long MOD = (long long)1e9 + 7;

long long calc(int k, int s, bool f){
    if(dp[k][s][f] >= 0) return dp[k][s][f];
    if(k == n.size()){
        if(s == 0)
            return dp[k][s][f] = 1;
        else
            return dp[k][s][f] = 0;
    }
    long long res = 0;
    int m = (f? n[k] - '0' : 9);
    for(int i = 0; i <= m; i++){
        res += calc(k + 1, (s + i) % d, f & (i == m));
        res %= MOD;
    }
    return dp[k][s][f] = res;
}

int main(){
    cin >> n >> d;
    for(auto&& i : dp){
        for(auto&& j : i){
            for(auto&& k : j){
                k = -1;
            }
        }
    }
    long long ans = (calc(0, 0, true) - 1 + MOD) % MOD;
    cout << ans << endl;
    return 0;
}


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

int main(){
	unsigned N, T;
	unsigned *t;
	unsigned end = 0, sum = 0;
	scanf("%d%d", &N, &T);
	t = (unsigned *)malloc(sizeof(unsigned) * N);
	for(unsigned i = 0; i < N; i++){
		scanf("%d", t + i);
		if(t[i] >= end){
			sum += T;
			end = t[i] + T;
		}else{
			sum += t[i] + T - end;
			end = t[i] + T;
		}
	}
	printf("%d", sum);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

struct edge{int to,cost;};

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

    int N; cin>>N;
    vector<vector<edge>> G(N);
    for(int i=0;i<N-1;i++){
        int a,b,c; cin>>a>>b>>c;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }    

    vector<int> dp(N);
    function<int(int,int)> dfs=[&](int v,int p)
    {
        int res=0;
        for(edge e:G[v]) if(e.to!=p){
            chmax(res,e.cost+dfs(e.to,v));
        }
        return dp[v]=res;
    };
    vector<int> ans(N);
    function<void(int,int,int)> dfs2=[&](int v,int d,int p)
    {
        vector<pair<int,int>> child;
        child.push_back({0,-1});
        for(edge e:G[v]){
            if(e.to==p) child.push_back({d+e.cost,e.to});
            else child.push_back({e.cost+dp[e.to],e.to});
        }
        sort(child.rbegin(),child.rend());
        ans[v]=child[0].first+child[1].first;
        for(edge e:G[v]) if(e.to!=p){
            if(e.to==child[0].second) dfs2(e.to,child[1].first,v);
            else dfs2(e.to,child[0].first,v);
        }
    };
    dfs(0,-1);
    dfs2(0,0,-1);
    // for(int i=0;i<N;i++) cout<<ans[i]<<' '; cout<<endl;
    cout<<*max_element(ans.begin(),ans.end())<<endl;
    return 0;
}


Measured memory_bytes: 36312
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
long long a[100005]={0};
int main()
{
	long long x;
	long long sum=0;
	scanf("%lld",&x);
	memset(a,0,sizeof(a));
	for(int i=1;i<=x;i++)
	{
		long long y;
		scanf("%lld",&y);
		if(y>100000)
			sum++;
		else
			a[y]++;
	}
	for(int i=1;i<=100000;i++)
	{
		if(a[i]!=0&&a[i]!=i)
		{
			if(a[i]>i)
				sum=sum+a[i]-i;
			else
				sum=sum+a[i];
		//	sum=sum+(a[i]>i?a[i]-i:a[i]);
		}
		
	}
	//cout<<a[3]<<endl;
	printf("%lld\n",sum);
	
	
	return 0;
}

Measured memory_bytes: 1024
import os
import os
import sys
from collections import defaultdict

import numpy as np
from scipy.misc import comb

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
A = np.array(A, dtype=int)


def test():
    ret = 0
    for i in range(N):
        for j in range(i + 1, N + 1):
            ret += A[i:j].sum() == 0
    return ret


counts = defaultdict(int)
counts[0] = 1
for s in A.cumsum():
    counts[s] += 1

ans = 0
for k, c in counts.items():
    ans += comb(c, 2, exact=True)
print(ans)


# print(test())


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

typedef long long ll;
using namespace std;

const ll INF = 1e9 + 7;
int n, m;

int main() {

  ll xx = 0, yy = 0;
  cin >> n >> m;

  for(int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    xx += (i * 2 - n + 1) * x % INF;
  }

  for(int i = 0; i < m; i++) {
    ll y;
    cin >> y;
    yy += (i * 2 - m + 1) * y % INF;
  }

  cout << (xx % INF) * (yy % INF) % INF <<endl;
}


Measured memory_bytes: 256