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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
#define VLCIN(a, n) REP(i,n){cin >> a[i];}
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = (ll)pow(10,7);
/****** define constant end ********/
/****** define variable start ******/
ll n, m;
vl l, r, c;
Graph G;
/******* define variable end *******/
std::vector<ll> d;

void dijkstra(ll s){
	std::priority_queue<P, std::vector<P>, std::greater<P>> que;
	for(ll i = 0; i < n; i++) d[i] = INF;
	d[s] = 0;
	que.push(P(0, s));

	while(!que.empty()){
		P p = que.top(); que.pop();
		ll v = p.second;
		if(d[v] < p.first) continue;
		for(ll i = 0; i < G[v].size(); i++){
			Edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
int solve() {
	cin >> n >> m;
	RES(l, m);
	RES(r, m);
	RES(c, m);
	RES(d, n);
	G.resize(n);
	REP(i, n-1){
		Edge e = {i, 0};
		G[i+1].push_back(e);
	}
	REP(i, m){
		cin >> l[i] >> r[i] >> c[i];
		l[i]--;
		r[i]--;
		Edge e = {r[i], c[i]};
		G[l[i]].push_back(e);
	}
	dijkstra(0);
	if(d[n-1] == INF) cout << -1 << endl;
	else cout << d[n-1] << endl;
	return 0;
}
int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 15120
#include<bits/stdc++.h>
using namespace std;
int cntl=0,cntr=0;
int n;
string s;
int main()
{
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++)
	{
        if(s[i]=='(')
        {
        	cntl++;
		}
        else
        {
            if(cntl>0)
            {
            	cntl--;
			}
            else
            {
            	cntr++;
			}
        }
    }
    for(int i=0;i<cntl;i++)
    {
    	s=s+')';
	}
    for(int i=0;i<cntr;i++)
    {
    	s='('+s;
	}
    cout<<s;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 100005
 
#define PI 3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 int
 
#define mod  1000000007

map<string, int> m;

int main()
{
	FAST;
	ll n;
	cin >> n;
	string a[n+5];
	for(ll i = 0; i < n; i ++){
		cin >> a[i];
	}
	m[a[0]] = 1;
	for(ll i = 1; i < n; i ++){
		if(m[a[i]] == 1 || a[i][0] != a[i-1][a[i-1].size() - 1]){
			cout << "No";
			return 0;
		}
		else{
			m[a[i]] = 1;
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 3668
fn main() {
    let n = rv::<usize>()[0];
    let mut a = Vec::with_capacity(n);
    for i in 0..n {
        a.push(rv::<usize>());
        for j in 0..n-1 {
            a[i][j]-=1;
        }
        a[i].reverse();
    }
    let mut k=0;
    let mut u=vec![true;n];
    let mut x=(0..n).collect::<Vec<usize>>();
    let mut y=Vec::with_capacity(n);
    let mut m=n;
    while m>0 {
        k+=1;
        for &i in &x { if u[i] {
            let j = a[i][a[i].len()-1];
            if u[j] && i==a[j][a[j].len()-1] {
                let mut f=|i:usize| {
                    a[i].pop();
                    u[i]=false;
                    y.push(i);
                };
                f(i);
                f(j);
            }
        }}
        if y.is_empty() {
            k=-1;
            break;
        }
        for &i in &y {
            if a[i].is_empty() {
                m-=1;
            }
            else {
                u[i]=true;
            }
        }
        x.clear();
        std::mem::swap(&mut x, &mut y);
    }
    println!("{}",k);
}
fn rl() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}
fn rv<T>() -> Vec<T>
  where T: std::str::FromStr, T::Err: std::fmt::Debug, {
    rl().split_whitespace().map(|x|x.parse::<T>().unwrap()).collect()
}

Measured memory_bytes: 12540
import math

X = int(input())

dp = [[0] * 100 for _ in range(X + 1)]

maxint = 1

for i in range(2, int(math.sqrt(X)) + 1):
    dp[i][1] = i
    for j in range(2, 100):
        dp[i][j] = dp[i][j - 1] * i
        if dp[i][j] > X:
            maxint = max(maxint, dp[i][j - 1])
            break
            

print(maxint)

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

int main()
{
    int n, min{2000}, max{0};
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int a;
        scanf("%d", &a);
        min = std::min(min, a);
        max = std::max(max, a);
    }
    printf("%d\n", max - min);

    return 0;
}

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

int main (){
    int A,B;
    string S,T,U;
    
    cin >> S >> T;

    cin >> A >> B;

    cin >> U;

    if(U==S){
        A = A-1;
    }else{
        B = B-1;
    }

    cout << A << " " << B << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[1100000], cnt, g[20];
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	g[0] = 1;
	cnt = 0;
	while (true)
	{
		g[cnt + 1] = g[cnt] * 3 + 1;
		if (g[++cnt] >= n)
			break;
	}
	int ret = 0;
	for (int i = cnt - 1; i >= 0; i--)
	{
		for (int j = g[i]; j < n; j++)
		{
			int v = a[j], w = j - g[i];
			while (w >= 0 && a[w] > v)
			{
				a[w + g[i]] = a[w];
				w -= g[i];
				ret++;
			}
			a[w + g[i]] = v;
		}
	}
	cout << cnt << endl;
	for (int i = cnt - 1; i >= 0; i--)
		printf(i ? "%d " : "%d\n", g[i]);
	cout << ret << endl;
	for (int i = 0; i < n; i++)
		printf("%d\n", a[i]);
	return 0;
}



Measured memory_bytes: 7140
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int64_t n;
    cin >> n;

    cout << n * (n - 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#if loc||local
#define _GLIBCXX_DEBUG
#endif

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  vector<double> d(n);
  cin>>d;
  vector<ll> a(n);
  rep(i,n)a[i]=(ll)1e9*d[i]+0.5;

  vector<pll> b(n);
  rep(i,n){
    int tow=0,five=0;
    while(a[i]%2==0){tow++;a[i]/=2;}
    while(a[i]%5==0){five++;a[i]/=5;}
    chmin(tow,19);chmin(five,19);
    b[i] = {tow,five};
  }
  auto table = vec<ll>(20,20);
  ll ans = 0;
  for(auto [i,j]:b){
    rep(x,20)rep(y,20){
      if(i+x>=18&&j+y>=18)ans+=table[x][y];
    }
    table[i][j]++;
  }
  cout<<(ans)<<endl;



}

Measured memory_bytes: 9580
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
const int INF = 1e9;
const long long INFLL = 1LL<<60;

vector<ll> enum_divisor(ll m) {
  vector<ll> divisors;
  for (ll i = 1; i*i <= m; ++i) {
    if (m % i != 0) continue;
    divisors.push_back(i);
    if (i * i != m) divisors.push_back(m / i);
  }
  return divisors;
}

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

  ll n;
  cin >> n;

  auto divisors = enum_divisor(n);
  ll ans = INFLL;
  for (ll m : divisors) {
    chmin(ans, (m-1) + (n / m) - 1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
package main

import (
	"fmt"
	"sort"
)

func main() {
	a := make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	if a[0] == 5 && a[1] == 5 && a[2] == 7 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

int main() {
int n,m;
cin >> n >> m;

vector<vector<int>> g(n);
vector<int> ans(n,-1);

rep(i,m)
{int a,b;
 cin >> a >> b;
 a--; b--;
 g[a].push_back(b);
 g[b].push_back(a);
}

//BFS
queue<int> que;
que.push(0);
while(!que.empty())
{  int v = que.front(); que.pop();
   rep(i,g[v].size())
   {if(ans[g[v][i]]==-1)
    {ans[g[v][i]]=v;
     que.push(g[v][i]);
    }
   }

}
cout<<"Yes"<<endl;
for (int i = 1; i <n;i++)
{cout<<ans[i]+1<<endl;
}

//最後にそれぞれ+1して出力

}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

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

using namespace std;

int main(){
  string s, t;
  cin >> s;
  cin >> t;
  int n = s.size();
  
  bool ans = true;
  
  vector<int> s_kind(26, -1);
  vector<int> t_kind(26, -1);
  char c, d;
  char c_prev = s[0];
  s_kind[c_prev - 'a'] = 0;
  char d_prev = t[0];
  t_kind[d_prev - 'a'] = 0;
  for(int i = 1; i < n; i++){
    c = s[i];
    d = t[i];
    if(c_prev == c && d_prev != d){
      ans = false;
      break;
    }
    if(c_prev != c){
      if(s_kind[c - 'a'] == t_kind[d - 'a']){
        s_kind[c - 'a'] = i;
        t_kind[d - 'a'] = i;
      }else{
        ans = false;
        break;
      }
    }
    c_prev = c;
    d_prev = d;
  }
  
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = 1e5 + 10;
const ll MOD = 1e9 + 7;
int N, M, K, Q;
int A[110];

int main()
{
	int i, j, k;
	scanf("%d", &N);
	int sum = 0;
	for (i = 0; i < N; ++i) {
		scanf("%d", &A[i]);
		sum += A[i];
	}
	sort(A, A + N);
	i = 0;
	while (sum % 10 == 0) {
		while (i < N && A[i] % 10 == 0) ++i;
		if (i == N) {
			sum = 0;
			break;
		}
		sum -= A[i];
		i++;
	}
	printf("%d", sum);

}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

freq=dict()
for i in range(n):
    a[i]-=i
    try:
        freq[a[i]]+=1
    except:
        freq[a[i]]=1

ans =0
for i in range(n):
    try:
        ans+=freq[-a[i]-2*i]
    except:
        pass
    freq[a[i]]-=1

print(ans)



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

using namespace std ;

#define N 200007
#define inf 0x7fffffff

int n ;
int a[N] , b[N] ;

bool check(int x){
    for(int i = 1 ; i <= 2 * n - 1 ; i++ ) b[i] = ( a[i] >= x ) ;
    for(int i = 0 ; i <= n - 2 ; i++ ){
        if( (b[i + n] == 0 && b[i + n + 1] == 0) || (b[n - i] == 0 && b[n - i - 1] == 0 ) ) return 0 ;
        if( (b[i + n] == 1 && b[i + n + 1] == 1) || (b[n - i] == 1 && b[n - i - 1] == 1 ) ) return 1 ;
    }
    return b[1] ;
}

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

    int l = inf , r = -inf ;
    for(int i = 1 ; i <= 2 * n - 1 ; i++ ) scanf("%d" , &a[i] ) , l = min( l , a[i] ) , r = max( r , a[i] ) ;

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

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

const int MAXN = 5e5+5;
int par[MAXN];
int sz[MAXN];
multiset<int> s1;
vector<multiset<int>> v1;
int subarrays[MAXN];
int arr[MAXN];
int ans=1e9;
pair<int,int> arr2[MAXN];

int findpar(int a){
    if(par[a]==a){
        return a;
    }
    return par[a] = findpar(par[a]);
}
void merge(int a,int b){
    a = findpar(a);
    b = findpar(b);
    if(a==b){
        return;
    }
    if(sz[a]<sz[b]){
        swap(a,b);
    }
    par[b] = a;
    sz[a]+=sz[b];
}
int main() {
    int n,k,q;
    cin>>n>>k>>q;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        arr2[i].first = arr[i];
        arr2[i].second = i;
    }
    sort(arr2+1,arr2+n+1);
    for(int i=1;i<=n;i++){
        int curr=  arr2[i].first;
        v1.clear();
        s1.clear();
        for(int j=1;j<=n;j++){
            if(arr[j]<curr){
                if(s1.size()>=k){
                    v1.push_back(s1);
                }
                s1.clear();
            }else{
                s1.insert(arr[j]);
            }
        }
        if(s1.size()>=k){
            v1.push_back(s1);
        }
        if(s1.size()){
            s1.clear();
        }
        multiset<int> s2;
        
        for(auto x:v1){
            int cnt=0;
            for(auto y:x){
                cnt++;
                if(cnt > x.size()-k+1){
                    break;
                }
               
                s2.insert(y);
            }
        }
        int cnt = 0;
        for(int x:s2){
            cnt++;
            if(cnt==q){
                ans = min(ans,x-curr);
                
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4736
n, q = gets.split.map(&:to_i)
queue = n.times.map {gets.split}.map! {|a| [a[0], a[1].to_i] }

time = 0

while !queue.empty?
  a = queue.shift
  m = [a[1], q].min
  a[1] = a[1] - m
  time += m

  if a[1] > 0
    queue.push(a)
  else
    puts "#{a[0]} #{time}"
  end
end



Measured memory_bytes: 17836
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, y;
    cin >> x >> y;
    int cnt = 0;
    ll ans = x;
    while (ans <= y) {
        cnt++;
        ans *= 2;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int L[M], R[M];
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i];
    L[i]--;
    R[i]--;
  }
  int b[N + 2]{};
  for (int i = 0; i < M; i++) {
    b[L[i]]++;
    b[R[i] + 1]--;
  }
  for (int i = 0; i <= N; i++) {
    b[i + 1] += b[i];
  }
  int cnt = 0;
  for (int i : b) {
    if (i == M) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <string.h>

int main(void){
	
	int i, len, cut, hit = 0;
	char s[101], ns_1[8], ns_2[8];
	char k[7] = "keyence";
	
	scanf("%s",s);
	
	if(strcmp(s, k) == 0){
		printf("YES");
		return 0;
	}
	
	len = strlen(s);
	
	for(i = 0; i <= 7; i++){
		if(i != 0){
			strncpy(ns_1, s, i);
			ns_1[i] = '\0';
		}else{
			ns_1[0] = '\0';
		}
		
		if(i != 7){
			strncpy(ns_2, s + len - (7 - i), 7 - i);
			ns_2[7 - i] = '\0';
		}else{
			ns_2[0] = '\0';
		}
		
		strcat(ns_1, ns_2);
		ns_1[7] = '\0';
		
		if(strcmp(ns_1, k) == 0){
			printf("YES");
			return 0;
		}
		
	}
	
	printf("NO");
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define pi 3.141592653589793238
#define fi first
#define se second
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<int> v(n);
    int s=0;
    for(int i=0;i<n;i++)cin>>v[i],s+=v[i];
    sort(v.begin(),v.end(),greater<int>());
    // cerr<<s<<" ";
    if((double)v[m-1]>=(double)s/(4.0*m))
    cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;
using Int = int64_t;
Int solve() {
    Int N, K;
    cin >> N >> K;
    map<Int, Int> m;
    for (Int i = 0, a, b; i < N; i++) {
        cin >> a >> b;
        m[a] += b;
    }
    Int size = 0;
    for (const auto& p : m) {
        size += p.second;
        if (size >= K) return p.first;
    }
    return 0;
}
int main() {
    cout << solve() << endl;
}

Measured memory_bytes: 4224
n, h, w = map(int, input().split())

a = [i for i in range(n)]
b = [i for i in range(n)]

for i in range(n):
    a[i], b[i] = map(int, input().split())

ans = 0

for i in range(n):
    if a[i] >= h and b[i] >= w:
        ans += 1


print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> swi(N);
  vector<bool> pass(N,false);
  for (int i=0; i<N; i++) {
    cin >> swi[i];
    swi[i]--;
  }
  int ans = 0;
  int now = 0;
  pass[0] = true;
  for (;;) {
    now = swi[now];
    if (pass[now]) {
      cout << -1 << endl;
      return 0;
    }
    pass[now] = true;
    ans++;
    if (now == 1) {
      cout << ans << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,p[SZ],g[SZ];
int mx[SZ][2],bb[2][SZ];
int qry(int*a,int t)
{
	int aa=-2.141e9;
	for(;t>=1;t-=t&-t)
		aa=max(aa,a[t]);
	return aa;
}
pair<int*,int> ed[5555555]; int en,dn[SZ];
void edt(int*a,int t,int u)
{
	for(;t<=n+1;t+=t&-t)
		if(a[t]<u) ed[++en]=mp(&a[t],a[t]),a[t]=u; 
}
bool chk(int t,int v)
{return t>=0&&qry(bb[t&1],v)>=t;}
int main()
{
	scanf("%d",&n);
	const int inf=int(2e9)+1;
	for(int i=1;i<=n+1;++i)
		bb[0][i]=0,bb[1][i]=-inf;
	mx[n+1][1]=-inf;
	for(int i=1;i<=n;++i)
		scanf("%d",p+i),
		p[i]=n+1-p[i];
	int mi=1e9;
	for(int i=1;i<=n;++i)
		mi=min(mi,p[i]),
		g[i]=1+(mi==p[i]);
	for(int i=n;i>=1;--i)
	{
		for(int j=0;j<2;++j)
			mx[i][j]=qry(bb[(j-g[i])&1],p[i])+g[i];
		for(int j=0;j<2;++j)
			edt(bb[j],p[i],mx[i][j]);
		dn[i]=en;
	}
	int cx=0,cy=0,Q=0;
	for(int i=1;i<=n;++i) Q+=(g[i]==2);
	if(!chk(Q,n+1))
	{
		puts("-1");
		return 0;
	}
	string s;
	int mx=n+1,my=n+1;
	for(int i=1;i<=n;++i)
	{
		Q-=(g[i]==2);
		int ox=p[i]<mx,oy=p[i]<my;
		while(en>dn[i+1])
			*ed[en].fi=ed[en].se,--en;
		if(chk((cx+ox-cy)+Q,my)
		||chk(-(cx+ox-cy)+Q,min(mx,p[i])))
			s.pb('0'),cx+=ox,mx=min(mx,p[i]);
		else if(chk((cy+oy-cx)+Q,mx)
		||chk(-(cy+oy-cx)+Q,min(my,p[i])))
			s.pb('1'),cy+=oy,my=min(my,p[i]);
		else throw "GG";
	}
	puts(s.c_str());
}


Measured memory_bytes: 75268
(defun split (string &key (delimiterp #'delimiterp))
  (loop :for beg = (position-if-not delimiterp string)
    :then (position-if-not delimiterp string :start (1+ end))
    :for end = (and beg (position-if delimiterp string :start beg))
    :when beg :collect (subseq string beg end)
    :while end))
(defun delimiterp (c) (position c " ,.;/"))

(defun make-array-from-list (l)
  (make-array (list (length l)) :initial-contents l)
)

(defun modExpt (a e m)
  (let ((res 1) (bit_str (format nil "~B" e)))
    (loop :for c :across bit_str :do
          (if (eq c #\0)
            (setq res (mod (* res res) m))
            (setq res (mod (* (mod (* res res) m) a) m))
            )
          )
    res))

(defun main()
  (let ((mod_ 1000000007)
        (n (read))
        (as (sort (make-array-from-list (map 'list #'parse-integer (split (read-line)))) #'<))
         (checker 1))

    (cond ((oddp (mod n 2)) (if (not (= (aref as 0) 0))
                              (progn (princ 0) (princ #\newline) (return-from main)))
                            (setq as (subseq as 1 (length as))) (setq checker 2))
          )

    (loop :for a :across as :and i :from 0 :do
          (cond ((evenp (mod i 2)) (if (not (= a checker))
                                     (progn (princ 0) (princ #\newline) (return-from main))))
                (t (if (not (= a checker))
                     (progn (princ 0) (princ #\newline) (return-from main)) (setq checker (+ checker 2))))))

    (princ (modExpt 2 (floor (/ n 2)) mod_)) (princ #\newline)
    )
)
(main)

Measured memory_bytes: 37348
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] d = new int[n];
    
    for(int i = 0; i < n; i++){
      d[i] = sc.nextInt();
    }
    
    Arrays.sort(d);
    
    int ans = 1;
    for(int i = 1; i < n; i++){
      if(d[i-1] != d[i]){
        ans++;
      }
    }
   
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 35932
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int d,g;
    cin>>d>>g;
    vector<int>p(d),c(d);
    rep(i,d){
        cin>>p[i]>>c[i];
    }
    int ans=1e9;
    for(int mask=0;mask<(1<<d);mask++){
        int s=0,num=0,rest_max=-1;
        for(int i=0;i<d;i++){
            if(mask&(1<<i)){
                s+=100*(i+1)*p[i]+c[i];
                num+=p[i];
            }else{
                rest_max=i;
            }
        }
        if(s<g){
            int s1=100*(rest_max+1);
            int need=(g-s+s1-1)/s1;
            if(need>=p[rest_max]){
                continue;
            }
            num+=need;
        }
        ans=min(ans,num);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long long saiko(long long a,long long b){
  long long x=a*b;
  
  if(a<b){
    long long s=a;
    a=b;
    b=s;
  }
  
  long long r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  
  long long ret=x/b;
  return ret;
}
  
  
int main(){
  long long a,b,c,d;
  long long _c,_d,_cd;
  scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
  
  _c=((b-a+a%c)-((b-a+a%c)%c))/c;
  if(a%c==0){
    _c=_c+1;
  }
  
  _d=((b-a+a%d)-((b-a+a%d)%d))/d;
  if(a%d==0){
    _d=_d+1;
  }
  
  _cd=((b-a+a%(saiko(c,d)))-((b-a+a%(saiko(c,d)))%(saiko(c,d))))/(saiko(c,d));
  if(a%(saiko(c,d))==0){
    _cd=_cd+1;
  }
  
  printf("%lld",b-a+1-_c-_d+_cd);
}

Measured memory_bytes: 128
import math

n, m = map(int, input().split())

if abs(n - m) > 1:
    print(0)
    exit()

a = max(n, m)
b = min(n, m)

if a - b == 1:
    print(math.factorial(a) * math.factorial(b) % (10 ** 9 + 7))
else:
    print(math.factorial(a) * math.factorial(b) * 2 % (10 ** 9 + 7))


Measured memory_bytes: 5180
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC131A
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();//S[0]～S[3]にデータが読み込まれる

            //同じ文字が続いたらBad、続かないならGood
            if (S[0] == S[1]||S[1]==S[2]||S[2]==S[3])
            {
                Console.WriteLine("Bad");
            }
            else
            {
                Console.WriteLine("Good");
            }
        }
    }
}


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

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

  for (int k10{}; k10 <= N; ++k10) {
    for (int k5{}; k5 <= N - k10; ++k5) {
      if (k10 * 10000 + k5 * 5000 > Y) continue;
      int k1 = N - k10 - k5;
      if (k10 * 10000 + k5 * 5000 + k1 * 1000 == Y) {
        cout << k10 << " " << k5 << " " << k1 << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;
  return 0;
}


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


int main() {
	map<char, string> s;
	char target1 ='a';
	char target2;
	cin >> s['a'] >> s['b'] >> s['c'];
	while (!(s['a'].empty() &&target1=='a')&& !(s['b'].empty() && target1 == 'b') && !(s['c'].empty() && target1 == 'c')) {
		target2 = s[target1][0];
		s[target1].erase(0,1);
		target1 = target2;
	}
	if (s['a'].empty() && target1 == 'a') {
		cout << "A";
	}
	else if (s['b'].empty() && target1 == 'b') {
		cout << "B";
	}
	else if (s['c'].empty() && target1 == 'c') {
		cout << "C";
	}
}

Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

# 最短距離を幅優先探索で求める
# 最短経路以外の.を全て黒く塗りつぶせば最高得点

n_blank = [flatten for inner in s for flatten in inner].count(".")

distance = [[-1]*W for _ in range(H)]
current_position = [0,0]
distance[0][0] = 0
next_positions = deque()
next_positions.append(current_position) # このようにしないとデック内部が2重リストにならない

# ある地点を渡すと、その地点から到達可能かつ距離未計算の地点のリストを返す
def not_investigated_positions(current_position):
    output = []
    for udrl in [[0,1],[0,-1],[1,0],[-1,0]]:
        y = current_position[0]+udrl[0]
        x = current_position[1]+udrl[1]
        if 0 <= y <= H-1 and 0 <= x <= W-1:
            if s[y][x] == "." and distance[y][x] == -1:
                output.append([y,x])
    return output

while len(next_positions)>0 and current_position!=[H-1,W-1]:
    current_position = next_positions.popleft()
    for q in not_investigated_positions(current_position):
        distance[q[0]][q[1]] = distance[current_position[0]][current_position[1]] + 1
        next_positions.append(q)

if current_position == [H-1,W-1]:
    print(n_blank - (distance[H-1][W-1]+1))
else:
    print(-1)


Measured memory_bytes: 3436
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    ab, bc, ca = il()
    print((bc*ab)//2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10156
#include<bits/stdc++.h>
using namespace std;
#define MAXN	100005
bool visited[MAXN];
int n, m, num[MAXN], tmp[MAXN], dest[MAXN];
long long k, x[MAXN], delta[MAXN], ans[MAXN];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &x[i]);
		delta[i] = x[i] - x[i - 1];
		num[i] = i;
	}
	scanf("%d%lld", &m, &k);
	for (int i = 1; i <= m; i++) {
		int x;
		scanf("%d", &x);
		swap(num[x], num[x + 1]);
	}
	for (int i = 1; i <= n; i++) {
		if (visited[i]) continue;
		int tot = 0, pos = i;
		while (!visited[pos]) {
			visited[pos] = true;
			tmp[tot++] = pos;
			pos = num[pos];
		}
		for (int j = 0; j < tot; j++)
			dest[tmp[j]] = tmp[(j + k) % tot];
	}
	for (int i = 1; i <= n; i++)
		ans[i] = delta[dest[i]];
	for (int i = 1; i <= n; i++) {
		ans[i] += ans[i - 1];
		printf("%lld.0\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 5120
#include<stdio.h>

long int cal(long int a,long int b){
	long int s;
	while(1){
	a=a-b;
	if(a==b)break;
	else if(a<b){
		s=a;
		a=b;
		b=s;
		}
	}
	return a;
} 

int main(void){
	long int a,b,x,y;
	while(scanf("%ld%ld",&a,&b)!=EOF){
	if(a==b)x=a;
	else if(a>b)x=cal(a,b);
	else x=cal(b,a);
	
	y=a*b/x;
	printf("%d %d\n",x,y);
	}


	return 0;

}

Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String[] strArray = br.readLine().split("\\s");
            Integer[] intArray = new Integer[3];
            for (int i = 0; i < strArray.length; i++) {
                intArray[i] = Integer.valueOf(strArray[i]);
            }
            if (intArray[0] < intArray[1] & intArray[1] < intArray[2]) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch (IOException e) {
            System.err.println(e);
        }

    }
}

Measured memory_bytes: 16892
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long K = sc.nextLong();
		
        if(A>=K){
		System.out.println(A-K + " " + B);
        }else if(A<K && (B-(K-A))>=0){
		System.out.println("0 "+ (B-(K-A)));
        }else{
 		System.out.println("0 0");           
        }
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <queue>
#include <vector>
#include<algorithm>
using namespace std;

#define INF 1e+15
#define MAX_V 100001

struct edge {
    long long to;
    long long cost;
};

// <最短距離, 頂点の番号>
using P = pair<long long, long long>;

long long V;
vector<edge> G[MAX_V];
long long d[MAX_V];

void prim(long long s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        long long v = p.second;
        if (d[v] < p.first) continue;
        //if prim,
        d[v] = -d[v];
        //for keep tree
        for (long long i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > e.cost) {
                d[e.to] = e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> V;
    long long x[V], y[V];
    vector<pair<long long, long long> > vecx, vecy;
    for(long long i=0; i<V; i++){
        cin >> x[i] >> y[i];
        vecx.push_back(make_pair(x[i],i));
        vecy.push_back(make_pair(y[i],i));
    }
    sort(vecx.begin(),vecx.end());
    sort(vecy.begin(),vecy.end());
    for(long long i=0; i<V-1; i++){
        edge e1 = {vecx[i+1].second,vecx[i+1].first-vecx[i].first};
        G[vecx[i].second].push_back(e1);
        edge e2 = {vecx[i].second,vecx[i+1].first-vecx[i].first};
        G[vecx[i+1].second].push_back(e2);
        edge e3 = {vecy[i+1].second,vecy[i+1].first-vecy[i].first};
        G[vecy[i].second].push_back(e3);
        edge e4 = {vecy[i].second,vecy[i+1].first-vecy[i].first};
        G[vecy[i+1].second].push_back(e4);
    }
    
    prim(0);
    
    long long sum=0;
    for(long long i=0; i<V; i++){
        sum += -d[i];
    }
    cout << sum << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 19684
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7;
#define input_from_file  freopen("input.txt", "r", stdin);

int main()
{
  // input_from_file;
  ll n,w=0,x=0,y=0,z=0,sum=0;
  cin>>n;vector<ll> vec(n,0);
      for(int i=0;i<n;i++)    {cin>>vec[i];sum+=vec[i];}
	    // if(n==1)    {cout<<vec[0];return 0;}
	    // if(n==2)    {cout<<max(vec[0],vec[1])-min(vec[0],vec[1]);return 0;}
	    
	    vector<vector<ll>> dp(n,vector<ll> (n,0));
	    for(int i=0;i<n;i++)    dp[i][i]=vec[i];
	    for(int i=0;i<n-1;i++)    dp[i][i+1]=max(vec[i],vec[i+1]);
	    for(int gap=2;gap<n;gap++){
	        for(int i=0;i<n-gap;i++){
	            w=dp[i+2][i+gap];
	            x=dp[i+1][i+gap-1];
	            z=dp[i][i+gap-2];
	            dp[i][i+gap]=max(vec[i]+min(x,w),vec[i+gap]+min(x,z));
	        }
	    }
	    cout<<2*dp[0][n-1]-sum<<endl;
  return 0;
}


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

int main()
{
  int input_n;
  int vector_x[100], vector_y[100];
  double xy_fabs = 0;
  double d_xy_p1 = 0, d_xy_p2 = 0, d_xy_p3 = 0, d_xy_pinf = 0;
  int counter_i;

  scanf("%d", &input_n);

  for(counter_i = 0 ; counter_i < input_n ; counter_i++)
    scanf("%d", &vector_x[counter_i]);

  for(counter_i = 0 ; counter_i < input_n ; counter_i++)
    {
      scanf("%d", &vector_y[counter_i]);
      
      xy_fabs = fabs(vector_x[counter_i] - vector_y[counter_i]);

      d_xy_p1 = d_xy_p1 + xy_fabs;
      d_xy_p2 = d_xy_p2 + pow(xy_fabs, 2.0);
      d_xy_p3 = d_xy_p3 + pow(xy_fabs, 3.0);

      if(d_xy_pinf < xy_fabs)
	d_xy_pinf = xy_fabs;
    }

  d_xy_p2 = sqrt(d_xy_p2);
  d_xy_p3 = pow(d_xy_p3, 1.0/3.0);

  printf("%lf\n", d_xy_p1);
  printf("%lf\n", d_xy_p2);
  printf("%lf\n", d_xy_p3);
  printf("%lf\n", d_xy_pinf);
  
  return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;
int a[maxn],f[maxn],s[maxn],tot=0;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
	  cin>>a[i];
	sort(a+1,a+n+1);
	int k=1;
	tot++;f[tot]=a[1];
	ll ans=0;  
	for(int i=1;i<=n;++i)
	  for(int j=i+1;j<=n;++j)
	    for(int k=j+1;k<=n;++k)
		  {
		  	  int x,y,z;
		  	  x=a[i];y=a[j];z=a[k];
		  	  if((x+y)>z&&(x+z)>y&&(y+z)>i&&x!=y&&x!=z&&y!=z)
		  	    ans++;
	      }
	cout<<ans<<endl;		  
}


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

int main(){
	int N;
	cin >> N;
	int a[N];
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	int ans = 1000000;
	for(int i = -100; i <= 100; i++){
		int cost = 0;
		for(int j = 0; j < N; j++){
			cost += (a[j] - i) * (a[j] - i);
		}
		ans = min(ans, cost);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int H,W,N;
vector<int> vec[200009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>H>>W>>N;
    rep(i,N){
        int x,y; cin>>x>>y;
        if(x<y) continue;
        vec[y].push_back(x);
    }
    
    rep1(i,W) sort(all(vec[i]));
    
    int nowx=1, mn=H;
    rep1(i,W){
        nowx++;
        if(nowx>mn) break;
        for(auto x:vec[i]){
            if(x<nowx) continue;
            if(x==nowx){
                chmin(mn,nowx-1);
                cout1(mn)
                return 0;
            }
            chmin(mn,x-1);
            break;
        }
        bool f=true;
        if(i<W&&vec[i+1].size()){
            f=false;
            vec[i+1].push_back(H+1);
            for(auto x:vec[i+1]){
                if(x<nowx) continue;
                if(x==nowx) nowx++;
                else{
                    f=true;
                    break;
                }
            }
        }
        if(!f) break;
    }
    cout1(mn)
}

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

int n, m;
int bit[100001];
P v[300000];

void add(int k, int x) {
	while (k <= m) {
		bit[k] += x;
		k += k &-k;
	}
}
int sum(int k) {
	int res = 0;
	while (k > 0) {
		res += bit[k];
		k -= k&-k;
	}
	return res;
}
int main() {
	scanf("%d%d", &n, &m);
	rep(i, n) {
		int l, r; scanf("%d%d", &l, &r);
		v[i] = P(r - l + 1, l);
	}
	sort(v, v + n);
	int s = 0;
	for (int i = 1; i <= m; i++) {
		while (s < n && v[s].first < i) {
			add(v[s].second, 1); add(v[s].second + v[s].first, -1);
			s++;
		}
		int ans = n - s;
		for (int j = 0; j <= m; j += i)ans += sum(j);
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 3712
n, k=map(int, input().split())
mod=10**9 +7
def calc(num):
    small=num*(num-1)//2
    large=num*(2*n -num+1)//2
    return large-small+1

ans=0
for i in range(k, n+2):
    ans+=calc(i)
    ans%=mod

print(ans)

Measured memory_bytes: 9120
N = input()
A,B = map(int, raw_input().split())
P = map(int, raw_input().split())
a,b,c = 0,0,0
for p in P:
  if p<=A:
    a += 1
  elif p<=B:
    b += 1
  else:
    c += 1
print min(a, b, c)


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

typedef long long ll;
typedef pair<int,int> pii;
// modint
// const ll mod = 1e9+7;
const ll mod = 998244353;

template< int mod >
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
      return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inv();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
    
  ModInt inv() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  
  static int get_mod() { return mod; }
};
 
using mint = ModInt<mod>;
vector<mint> fact;

mint com(ll a, ll b){
  if(b > a){
    return 0;
  }
  mint ret = 1;
  ret *= fact[a];
  ret *= fact[a-b].inv();
  ret *= fact[b].inv();
  return ret;
}

int main(){
  cout << setprecision(10);

  ll N,A,B,K;
  cin >> N >> A >> B >> K;

  fact.assign(N+1, 1);
  fact[0] = 1;
  for(ll i = 1; i <= N; i++){
    fact[i] = fact[i-1] * i;
  }


  mint ans = 0;
  for(ll i = 0; i <= N; i++){
    ll tmp = K - A * i;
    if(tmp>=0 && tmp % B == 0){
      ll j = tmp / B;
      mint ret = com(N,i);
      ret *= com(N,j);
      ans += ret;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4536
import Control.Applicative

main :: IO ()
main = do
  xy <- (map read . words) <$> getLine
  putStrLn $ solve xy

solve :: [Int] -> String
solve xy
  | (xy !! 0) <  (xy !! 1) = "a < b"
  | (xy !! 0) == (xy !! 1) = "a == b"
  | (xy !! 0) >  (xy !! 1) = "a > b"
  | otherwise = ""
                

Measured memory_bytes: 3504
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    P tasks[N];
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        tasks[i] = P(a, b);
    }

    sort(tasks, tasks+N);

    priority_queue<int> q;

    int id = 0;
    ll ans = 0;
    for(int i=0; i<=M; i++){
        while(id < N && tasks[id].first <= i){
            q.push(tasks[id].second);
            id++;
        }
        if(!q.empty()){
            ans = ans + q.top();
            q.pop();
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1660
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn f(renzoku: &Vec<u64>) -> u64 {
    let mut ans: u64 = 0;
    for r in renzoku {
        ans += r / 2;
    }
    ans
}

fn main() {
    let s: String = read();
    let cv: Vec<char> = s.chars().collect();
    let k: u64 = read();

    let mut renzoku: Vec<u64> = vec![];
    let mut cnt: u64 = 1;
    for i in 1..cv.len() {
        if cv[i] == cv[i - 1] {
            cnt += 1;
        } else {
            renzoku.push(cnt);
            cnt = 1;
        }
    }
    renzoku.push(cnt);

    if renzoku.len() == 1 {
        println!("{}", (renzoku[0] * k) / 2);
    } else if cv[0] == cv[cv.len() - 1] {
        let mut ans: u64 = f(&renzoku);
        let tmp = renzoku.pop().unwrap();
        renzoku[0] += tmp;
        ans += f(&renzoku) * (k - 1);
        println!("{}", ans);
    } else {
        println!("{}", f(&renzoku) * k);
    }
}


Measured memory_bytes: 4352
main = interact$show.solve.map read.words

solve :: [Int] -> Int
solve [n,a,b] = sum [x|x <- l n, bounds (culc x) a b]
 where
  l x = [a| a<-[1..10000], a<=x]
  bounds x a b = a<=x && x<=b
  culc 0 = 0
  culc x = mod x 10 + culc (div x 10)

Measured memory_bytes: 508
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define INF 1145141919810893931
using namespace std;

int main() {
	ll n; cin >> n;
	while (n) {
		vector<ll> a(n);
		vector<ll> b(n - 2);
		rep(i, n) cin >> a[i];
		sort(a.begin(), a.end());
		ll b_count = 0;
		nrep(i, 1, n - 1) b[b_count++] = a[i];
		ll sum = 0;
		rep(i, b.size()) sum += b[i];
		cout << sum / b.size() << endl;
		cin >> n;
	}
	return 0;
}

Measured memory_bytes: 3080
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define INF (ll)1000000007
// chmax chmin
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; }

int main(void){

    ll N, A, B;
    cin >> N >> A >> B;
    ll X[N];
    REP(i,N) cin >> X[i];

    ll ans = 0;
    REP(i,N-1){
        if(A*(X[i+1]-X[i]) >= B) ans += B;
        else ans += A*(X[i+1]-X[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100000+5;
int n,m,dp[MAXN],x,y,deg[MAXN],ans;
vector<int> V[MAXN];

int main(){
	cin>>n>>m;
	for(int i=0;i<m;++i) cin>>x>>y,++deg[y],V[x].push_back(y);
	queue<int> Q;
	for(int i=1;i<=n;++i) if(!deg[i]) Q.push(i);
	while(Q.size()){
		int p=Q.front(); Q.pop();
		for(int i=0;i<V[p].size();++i){
			--deg[V[p][i]],dp[V[p][i]]=max(dp[V[p][i]],dp[p]+1),ans=max(ans,dp[V[p][i]]);
			if(!deg[V[p][i]]) Q.push(V[p][i]);
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

int M[101][101], d[101], n;

void set()
{
	int u, k, v;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			M[u][v] = 1;
		}
	}

	for (int i = 1; i <= n; i++)
		d[i] = -1;
}

void bfs(int x)
{
	queue<int> Q;

	Q.push(x);
	d[x] = 0;

	while (!Q.empty()) {
		int u = Q.front();
		for (int i = 1; i <= n; i++) {
			if (M[u][i] == 1 && d[i] == -1) {
				Q.push(i);
				d[i] = d[u] + 1;	
			}
		}
		Q.pop();
	}
}

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

	cin >> n;
	set();

	bfs(1);

	for (int i = 1; i <= n; i++)
		cout << i << " " << d[i] << endl;

	return 0;
}

Measured memory_bytes: 1240