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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "UNRESTORABLE" << endl;
}
//-----------------------------------------
string s,t ;

bool is_ok(int i){
    string u = s.substr(i,SZ(t)) ;
    REP(j,SZ(t)){
        if(j<SZ(u) && u[j]!=t[j] && u[j]!='?'){
            return false ;
        }
    }
    return true ;
}

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s >> t ;
    vstr ans ;
    if(SZ(s)-SZ(t)<0){
        no() ;
        return 0 ;
    }
    REP(i,SZ(s)-SZ(t)+1){
        string tmp = "" ;
        if(is_ok(i)){
            REP(j,SZ(s)){
                if(j<i || j>=i+SZ(t)){
                    if(s[j]=='?'){
                        tmp += "a" ;
                    }
                    else{
                        tmp += s[j] ;
                    }
                }
                else if(j==i){
                    tmp += t ;
                }
            }
            ans.PB(tmp) ;
        }
    }
    if(SZ(ans)==0){
        no() ;
        return 0 ;
    }
    sort(ALL(ans)) ;
    cout << ans[0] <<endl; 
    

    return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  int l, a, b, c, d;
  cin >> l >> a >> b >> c >> d;
  while (a > 0 || b > 0){
    l--;
    a -= c;
    b -= d;
  }
  cout << l << endl;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int N; std::cin >> N;
    std::vector<int> A(N);
    for(int i(0); i < N; ++i) std::cin >> A[i];
    long long ans(0);
    for(int i(1); i < N; ++i){
        if(A[i-1] > A[i]){
            ans += A[i-1] - A[i];
            A[i] = A[i-1];
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N=(int)1e5+5;

int n,m;
vector<int>g[N];
int dp[N];

void calc(int nod)
{
    dp[nod]=1;
    for(auto &nou:g[nod])
    {
        if(dp[nou]==0) calc(nou);
        dp[nod]=max(dp[nod],1+dp[nou]);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(dp[i]==0)
        {
            calc(i);
        }
        ans=max(ans,dp[i]);
     ///   cout<<i<<" : "<<dp[i]<<"\n";
    }
    ans--;
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 7552
#include <iostream>
using namespace std;
int main(){
    int a, b, c, t;
    cin >> a >> b >>c;
	
	if (a > b){
        t = a;
		a = b;
		b = t;
		t = 0;
	}
	if(b > c){
		t = b;
		b = c;
		c = t;
		t = 0;
	}
	if (a > b){
        t = a;
		a = b;
		b = t;
		
	}
	
	cout << a << " " << b << " " << c << endl;
	return 0;
}

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

int N;
int A[101],B[101] = {0};

int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
		B[A[i]]++;
	}
	bool judge = true;
	if(N>=3 && B[1]>=2) judge = false;
	for(int i=N-1;i>0;i--){
		if(B[i]==0) continue;
		else{
			if(B[i]<2) judge = false;
			else{
				B[i] -= 2;
				for(int j=i-1;j>=(i+1)/2;j--){
					if(i%2==0 && j==i/2){
						if(B[j]!=1) judge = false;
						else B[j]--;
					}else{
						if(B[j]<2) judge = false;
						else B[j] -= 2;
					}
				}
				if(i%2==0){
					for(int j=1;j<i/2+1;j++){
						if(B[j]>0) judge = false;
					}
				}else{
					for(int j=1;j<(i+1)/2+1;j++){
						if(B[j]>0) judge = false;
					}
				}
				break;
			}
		}
	}
	if(judge) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn
import scala.collection.mutable._

object Main extends App {

  val Array(n, m) = StdIn.readLine.split(" ").map(_.toInt)
  val a = Iterator.continually(StdIn.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .toArray

  val graph = Array.fill(n+1)(ListBuffer.empty[Int])
  a.foreach(e => {
    graph(e(0)) += e(1)
  })

  val visit = Array.ofDim[Boolean](n+1)
  def dfs(pos:Int, cnt:Int):Unit = {
    if(cnt < 0) return
    visit(pos) = true
    // print(pos + " ")
    for(i <- graph(pos)) {
      dfs(i, cnt-1)
    }
  }

  dfs(1,2)
  val ans = if(visit(n)) "POSSIBLE" else "IMPOSSIBLE"
  println(ans)
}

Measured memory_bytes: 99752
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int h, w, c;

typedef vector<vector<int> > matrix;
typedef pair<int,int> pii;

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

matrix bfs(matrix ba, int color) {
  queue<pii> Q;
  Q.push(pii(0,0));
  bool visited[w][h];
  memset(visited,0,sizeof(visited));

  int hoge = ba[0][0] ;
  
  while(!Q.empty()) {
    int x = Q.front().first;
    int y = Q.front().second;
    Q.pop();
    if (visited[x][y]) continue;
    visited[x][y] = 1;
    ba[x][y] = color;
    
    REP(k,4) {
      int xx = x+dx[k];
      int yy = y+dy[k];

      if (xx<0||xx>=w||yy<0||yy>=h) continue;
      if (ba[xx][yy]!=hoge||visited[xx][yy])continue;
      Q.push(pii(xx,yy));
    }
  }
  return ba;
}

int bfs2(matrix ba) {
  queue<pii> Q;
  Q.push(pii(0,0));
  bool visited[w][h];
  memset(visited,0,sizeof(visited));

  int hoge = ba[0][0] ;
  int cnt = 0;
  while(!Q.empty()) {
    int x = Q.front().first;
    int y = Q.front().second;
    Q.pop();
    if (visited[x][y]) continue;
    visited[x][y] = 1;
    cnt++;
    
    REP(k,4) {
      int xx = x+dx[k];
      int yy = y+dy[k];

      if (xx<0||xx>=w||yy<0||yy>=h) continue;
      if (ba[xx][yy] != hoge || visited[xx][yy])continue;
      Q.push(pii(xx,yy));
    }
  }
  return cnt;
}

int solve(matrix ba, int cnt) {
  if (cnt == 5) {
    int hoge = bfs2(ba);

    return hoge;
  }
  if (cnt==4)
    return bfs2(bfs(ba,c-1));
  int res = 0;
  REP(i,6) {
    if (ba[0][0] == i) continue;
    res = max(res, solve(bfs(ba, i), cnt+1));
  }
  return res;
}
int main() {
  while(cin>>h>>w>>c, h) {
    matrix ba(w,vector<int>(h));
    REP(y,h)
      REP(x,w) {
      cin>>ba[x][y];
      ba[x][y]--;
    }
    cout << solve(ba,0) << endl;
  }
}

Measured memory_bytes: 920
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	ll W;
	cin >> W;
	vector<ll> w(n);
	vector<ll> v(n);

	for(int i = 0;i < n;i++)cin >> w[i] >> v[i];

	//dp[i][j][k]:=i番目まで決めたときにj個とったとき,w_i-w_1の総和がkであるときの価値の最大値.
	vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(n+1,vector<ll>(301,0)));

	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			if(i < j)break;
			for(int k = 0;k <= 300;k++){
				dp[i+1][j][k] = max(dp[i+1][j][k],dp[i][j][k]);
				if(k + (w[i] - w[0]) <= 300)dp[i+1][j+1][k+(w[i]-w[0])] = max(dp[i+1][j+1][k+(w[i]-w[0])],dp[i][j][k]+v[i]);
			}
		}
	}

	ll ans = 0;
	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= 300;j++){
			if(w[0] * i + j <= W)ans = max(ans,dp[n][i][j]);
		}
	}

	cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int half = n/2;
  vector<int> b(n, 0);
  for (int i = half; i < n; i++) {
    if (a[i] == 1) {
      b[i] = 1;
    }
  }
  for (int i = half-1; i >= 0; i--) {
    int cnt = 0;
    for (int j = 2; j*(i+1) <= n; j++) {
      if (b[j*(i+1)-1] == 1) {
        cnt++;
      }
    }
    if ((cnt%2 == 0 && a[i] == 0) || (cnt%2 == 1 && a[i] == 1)) {
      b[i] = 0;
    }
    else {
      b[i] = 1;
    }
  }
  int ans_cnt = 0;
  vector<int> ans(0);
  for (int i = 0; i < n; i++) {
    if (b[i] == 1) {
      ans_cnt++;
      ans.push_back(i+1);
    }
  }
  cout << ans_cnt << endl;
  for (auto A : ans) {
    cout << A << " ";
  }
  cout << endl;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 2000001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,
q,q1,q2,q3,q4,r,s,t,u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,id4,lim;

char str[Mx];
void solve(){
  l=0;r=n-1;
  c=0;
  while(l<r){
    while(l<r){
      if(str[r]=='R'){
        break;
      }
      r--;
    }
    while(l<r){
      if(str[l]=='W'){
        break;
      }
      l++;
    }
    if(l<r){
      c++;
      l++;r--;
    }
  }
  printf("%lld\n",c);
}
int main()
{
    scanf("%lld",&n);
    scanf("%s",str);
    solve();
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
const int M = 2;
struct hs {
	int v[M];
	hs(){
		memset(v, 0, sizeof(v));
	}
};
hs mods;
int mds[] = {
	961'748'927,
	961'820'429,
	1'000'000'007,
	1'000'000'009,
	1'003'162'753,
	1'023'893'771
};
hs create(int x){
	hs r;
	for(int i = 0; i < M; i++){
		r.v[i] = x % mods.v[i];
		if(r.v[i] < 0) r.v[i] += mods.v[i];
	}
	return r;
}
hs operator + (hs a, hs b){
	hs r;
	for(int i = 0; i < M; i++){
		r.v[i] = a.v[i] + b.v[i];
		if(r.v[i] >= mods.v[i]) r.v[i] -= mods.v[i];
	}
	return r;
}
hs operator - (hs a, hs b){
	hs r;
	for(int i = 0; i < M; i++){
		r.v[i] = a.v[i] - b.v[i];
		if(r.v[i] < 0) r.v[i] += mods.v[i];
	}
	return r;
}
hs operator * (hs a, hs b){
	hs r;
	for(int i = 0; i < M; i++){
		r.v[i] = 1ll * a.v[i] * b.v[i] % mods.v[i];
	}
	return r;
}
bool operator < (hs a, hs b){
	for(int i = 0; i < M; i++) if(a.v[i] != b.v[i]) return a.v[i] < b.v[i];
	return false;
}
int pwr(int a, int b, int mod){
	int r = 1;
	for(; b; b>>=1, a = 1ll * a * a % mod) if(b&1) r = 1ll * r * a % mod;
	return r;
}
bool is_prime(int x){
	for(int i = 2; i * i <= x; i++) if(x % i == 0) return false;
	return true;
}
const int maxn = 300300;
using Poly = pair<hs, hs>;
hs eval(Poly f, hs x){
	return f.first + (f.second * x);
}
Poly poly[maxn];
int main(){
	srand(time(NULL));
	memcpy(mods.v, mds, sizeof(int) * M);
	hs x, mx, minus = create(-1), plus = create(1);
	int xx;
	do {
		xx = 900'999'999 + 50;
		xx += rand() % 1000;
	} while(!is_prime(xx));
	x = create(xx);
	for(int i = 0; i < M; i++){
		mx.v[i] = pwr(x.v[i], mods.v[i] - 2, mods.v[i]);	
		assert((1ll * mx.v[i] * x.v[i] % mods.v[i]) == 1);
	}
	int n; cin >> n;
	string s; cin >> s;
	poly[n] = {create(0), create(1)};
	for(int i = n - 1; i >= 0; i--){
		poly[i] = poly[i + 1];
		if(s[i] == '+'){
			poly[i].first = poly[i].first - poly[i].second;
		} else if(s[i] == '-'){
			poly[i].first = poly[i].first + poly[i].second;
		} else {
			hs mul = x;
			if(s[i] == '<')
				mul = mx;
			poly[i].second = poly[i].second * mul;
		}
	}
	Poly norm = poly[n];
	for(int i = 0; i < n; i++){
		if(s[i] == '+'){
			norm.first = norm.first + norm.second;
		} else if(s[i] == '-'){
			norm.first = norm.first - norm.second;
		} else if(s[i] == '<'){
			norm.second = norm.second * x;
		} else {
			norm.second = norm.second * mx;
		}
	}
	hs tot = norm.first;
	map<hs, int> cnt;
	cnt[poly[n].first]++;
	long long ans = 0;
	for(int i = n - 1; i >= 0; i--){
		ans += cnt[eval(poly[i], tot)];
		cnt[poly[i].first]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 36484
x,k,d = map(int, input().split())
x = abs(x)
if x - d*k >= 0:
    print(abs(x-d*k))
else:
    a = x // d
    if k % 2 == 0:
        if a % 2 == 0:
            print(abs(x - d*a))
        else:
            print(abs(x - d * (a+1)))
    else:
        if a % 2 == 0:
            print(abs(x - d * (a + 1)))
        else:
            print(abs(x - d * a))



Measured memory_bytes: 9068
#include <iostream> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
using namespace std; 
const int MAX_N = 1 << 10; 
int N, M, a[MAX_N][MAX_N], c[MAX_N][MAX_N]; 
int cnt[MAX_N]; 
int main () { 
	cin >> N >> M; 
	for (int i = 1; i < 1 << max(N, M); i++) cnt[i] = cnt[i ^ (i & -i)] + 1; 
	for (int i = 1; i < 1 << N; i++) 
		for (int j = 1; j < 1 << M; j++) c[i][j] = cnt[i & j] & 1; 
	for (int i = 1; i < 1 << N; i++) 
		for (int j = 1; j < 1 << M; j++) 
			a[i][j] = c[i][j] ^ c[i - 1][j] ^ c[i][j - 1] ^ c[i - 1][j - 1]; 
	for (int i = 1; i < 1 << N; i++, putchar('\n')) 
		for (int j = 1; j < 1 << M; j++) putchar(a[i][j] + '0'); 
    return 0; 
} 

Measured memory_bytes: 11808
#include <iostream>
#include <cstring>
using namespace std;
int a,b,c;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	int d=b-c;
	if (d>=0){
		printf("%d",b+c);
	}else{
		printf("%d",min(b+c,b*2+min(c,a+1)));
	}
}

Measured memory_bytes: 256
#include<complex>
#include<stdio.h>
#define F(a,b,c) acos((b*b+c*c-a*a)/2/b/c)
int main(){int n;float d,e,f,g,h,i;for(scanf("%d",&n);n--;){scanf("%f%f%f%f%f%f",&d,&g,&e,&h,&f,&i);std::complex<float> a(d,g),b(e,h),c(f,i);float A=abs(b-c),B=abs(c-a),C=abs(a-b),L=F(A,B,C),s=sin(2*L),t=sin(2*F(B,C,A)),u=sin(2*F(C,A,B)),v=s+t+u;printf("%.3f %.3f %.3f\n",(d*s+e*t+f*u)/v,(g*s+h*t+i*u)/v,A/sin(L)/2);}}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const int INF = 1e9;
const int N = 1e5 + 5;
char s[N];
ii st[4*N];
ii dp[N];

ii query(int v, int tl, int tr, int l, int r) {
	if (l > r)
		return {INF, INF};
	if (l == tl && r == tr)
		return st[v];
	int tm = (tl + tr) / 2;
	return min(query(v*2, tl, tm, l, min(r, tm)),
			query(v*2+1, tm+1, tr, max(l, tm+1), r));
}

void update(int v, int tl, int tr, int pos, ii val) {
	if (tl == tr)
		st[v] = {val.first, pos};
	else {
		int tm = (tl + tr) / 2;
		if (pos <= tm)
			update(v*2, tl, tm, pos, val);
		else
			update(v*2+1, tm+1, tr, pos, val);
		st[v] = min(st[v*2], st[v*2+1]);
	}
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, m;
	scanf("%d%d", &n, &m);
	scanf("%s", s);

	for (int i = 1; i <= n; i++) dp[i] = {INF, INF};
	for (int i = 1; i <= n; i++) {
		if (s[i] == '1')
			dp[i] = {INF, -1};
		else if (i <= m)
			dp[i] = {1, 0};
		else {
			dp[i] = query(1, 1, n, i - m, i - 1);
			if (dp[i].first < INF) ++dp[i].first;
		}
		update(1, 1, n, i, dp[i]);
	}

	if (dp[n].first == INF) {
		puts("-1");
		return 0;
	}

	vi ans;
	for (int x = n; x != 0; x = dp[x].second) {
		ans.push_back(x - dp[x].second);
	}
	for (int i = ans.size() - 1; i >= 0; i--) printf("%d ", ans[i]);
	puts("");
}


Measured memory_bytes: 3836
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>












ll a,b,c,x,y,res;


void solve()
{
	cin>>a>>b>>c>>x>>y;
	if(x>y)
	{
		swap(x,y);
		swap(a,b);
	}
	if(2*c<a+b)
	{
		res=2*c*x;
		y-=x;
		if(2*c<b)res+=2*c*y;
		else res+=b*y;
	}
	else
	{
		res=a*x+b*y;
	}
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

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

using namespace std;

#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define ll long long
const int maxn=1e6+10;
const int mod=1e9+7;
const double pi=acos(-1);

ll a[maxn];
ll n;

ll check(ll x){
	ll res=0;
	for(int i=0;i<n;i++){
		if(a[i]<0){
			ll L=i,R=n;
			while(R-L>1){
				ll mid=(L+R)>>1;
				if(a[i]*a[mid]<=x){//这里要注意和下面不一样的是 当a[i]<0的时候mid取小 乘积反而会增大
					R=mid;
				}else{
					L=mid;
				}
			}
			res+=n-R;
		}else{
			ll L=i,R=n;
			while(R-L>1){
				ll mid=(L+R)>>1;
				if(a[i]*a[mid]<=x){//a[i]>0 mid取大 乘积增大
					L=mid;
				}else{
					R=mid;
				}
			}
			res+=L-i;
		}
	}
	return res;
}

int main()
{
    ll k;
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);
    ll l=-1e18,r=1e18;
    ll ans;
    while(l<r-1)
    {
        ll mid=(l+r)/2;
        if(check(mid)>=k)r=mid;
        else
            l=mid;
    }
    printf("%lld",r);
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 500001

struct node{
  struct node *parent;
  struct node *left;
  struct node *right;
  int key;
};

typedef struct node Node;
Node *root,*NIL;

void Insert(int id){
  Node *x,*y,*z;
  y = NIL;
  x = root;

  z = (Node *)malloc(sizeof(Node));
  z->key = id;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
  
};
void Inorder(Node *id){
  if(id==NIL)return;

  Inorder(id->left);
  printf(" %d",id->key);

  Inorder(id->right);
};
void Preorder(Node *id){
  if(id==NIL)return;

  printf(" %d",id->key);
  
  Preorder(id->left);
  Preorder(id->right);
};
int Find(Node *id, int key){
  int count = 0;
  if(id==NIL){
    //printf("no\n");
    return 0;
  }
  if(key==id->key){
    //printf("yes\n");
    //count++;
    return 1;
  }
  if(key < id->key){
  count += Find(id->left,key);
  }
  else count +=  Find(id->right,key);
  return count;
  
};
int main(){

  int i,j,n,id,find,count=0,judge;
  char order[MAX];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){ //parent
    scanf("%s",order);
    if(strcmp(order,"insert")==0){
      scanf("%d",&id);
      Insert(id);
    }
    else if(strcmp(order,"find")==0){
      scanf("%d",&find);
      judge = Find(root,find);
      if(judge == 1){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
    }
    else{
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
  }

  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x;
		N-=x;
	}
	if(N<0) N=-1;
	cout<<N<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3656
from math import ceil
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    a,b,c,d = map(int, readline().split())

    x = ceil(c / b)
    y = ceil(a / d)

    if x <= y:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9120
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n;
	cin >> n;

	//エラトステネスの篩でP_max以下の素数vector primeをつくる
	bool *pr;
	int P_max = 100; //10^6くらいまでが現実的か
	pr = (bool*)malloc(sizeof(bool) * P_max);
	REP(i, P_max) {
		pr[i] = i;
	}
	REP(i, P_max + 1) pr[i] = true;
	pr[0] = false;
	pr[1] = false;
	for(int i = 2; i * i <= P_max; i++){ 
		if(pr[i] == true){
			for(int j = 2 * i; j <= P_max; j+=i){
				pr[j] = false;
			}
		}
	}
	vector<int> prime;
	for(int i = 2; i <= P_max; i++){
		if(pr[i]) prime.push_back(i);
	}
	//

	//整数Xの素因数分解の結果をmapで返す。上のvector primeはもちろんいる
	map<int, int> prf;
	REP1(j,n){
		int X = j;
		int diving = X; //これをどんどん割っていく。dividingが正しい
		for(int i = 0; diving > 1 && prime[i] * prime[i] <= X; i++){
			while (diving % prime[i] == 0)
			{
				diving /= prime[i];
				prf[prime[i]]++;
			}
		}
		if(diving > 1)prf[diving]++;
	}

	for(auto iti = prf.begin(); iti != prf.end(); iti++){
		if(iti->second >= 74) ans++;
		for(auto itj = next(iti, 1); itj != prf.end(); itj++){
			if(iti->second >= 24 && itj->second >= 2) ans++;
			if(iti->second >= 2 && itj->second >= 24) ans++;
			if(iti->second >= 14 && itj->second >= 4) ans++;
			if(iti->second >= 4 && itj->second >= 14) ans++;
			for(auto itk = next(itj, 1); itk != prf.end(); itk++){
				if(iti->second >= 4 && itj->second >= 4 && itk->second >= 2) ans++;
				if(iti->second >= 4 && itj->second >= 2 && itk->second >= 4) ans++;
				if(iti->second >= 2 && itj->second >= 4 && itk->second >= 4) ans++;
			}
		}		
	}

	cout << ans << endl;
}

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

int main() {
  int x;
  cin >> x;
  if (400 <= x && x <= 599) {
    cout << "8";
    return 0;
  } else if (600 <= x && x <= 799) {
    cout << "7";
    return 0;
  } else if (800 <= x && x <= 999) {
    cout << "6";
    return 0;
  } else if (1000 <= x && x <= 1199) {
    cout << "5";
    return 0;
  } else if (1200 <= x && x <= 1399) {
    cout << "4";
    return 0;
  } else if (1400 <= x && x <= 1599) {
    cout << "3";
    return 0;
  } else if (1600 <= x && x <= 1799) {
    cout << "2";
    return 0;
  } else {
    cout << "1";
    return 0;
  }
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	int n;
	sd(n);
	int h[n];
	fi(0,n,1)sd(h[i]);
	int dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	fi(2,n,1){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1];
}

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

namespace CookieExchanges {
    class Program {
        static void Main(string[] args) {
            string[] s = Console.ReadLine().Split();
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);
            int ans = 0;
            if (a == b && b == c) {
                if (a % 2 == 0) {
                    Console.WriteLine(-1);
                    return;
                }
                else {
                    Console.WriteLine(0);
                    return;
                }
            }
            while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
                int tmpA = a / 2, tmpB = b / 2, tmpC = c / 2;
                a = tmpB + tmpC;
                b = tmpA + tmpC;
                c = tmpA + tmpB;
                ans++;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy.sort()
vectors = set()
for i in range(n-1):
    for j in range(i+1, n):
        xi, yi = xy[i]
        xj, yj = xy[j]
        if xj-xi == 0 and yj-yi == 0:
            continue
        unit_vector = (xj-xi, yj-yi)
        vectors |= {unit_vector}
ans = n
for vector in vectors:
    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            xi, yi = xy[i]
            xj, yj = xy[j]
            if vector == (xj-xi, yj-yi):
                cnt += 1
    ans = min(ans, n-cnt)
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cassert>
#include <cstring>
#include <climits>
 
using namespace std;
 
#define FOR(k,a,b) for(int k=(a); k < (b); k++)
#define FORE(k,a,b) for(int k=(a); k <= (b); k++)
#define REP(k,a) for(int k=0; k < (a); k++)
 
#define ALL(c) (c).begin(), (c).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub))
 
#define dump(x) cerr << #x << ": " << (x) << endl;
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
 
const int INF = 1000000000;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
int main(void) {
    ll n, m;
    cin >> n >> m;

    ll pairs = min(n, m / 2);
    n -= pairs;
    m -= pairs * 2;

    dump(n);
    dump(m);
    dump(pairs);

    if (m > 0) {
        pairs += m / 4;
    }

    printf("%lld\n", pairs);

    return 0;
}


Measured memory_bytes: 888
/*
I am not somebody you can put inside a box
And I am not somebody who will let you take my spot
It's written on my face I'm somebody who never stop
I do it because I gotta I don't do it for you props
Nah, you can keep those
I'm aiming way higher than planes in Heathrow
And I'm sorry to say but my game can't be sold
And look to be honest either you got it or don't
But if you got a dream and a vision
Put it in your mind that you gotta go out and get it
People try to stop you it's so hard in the beginning
But you said that you a winner so keep going ain't no quiting
I'm giving you the words that out me in this posotion
Some people hear and some people listen
Wanna be the best then you gotta learn the difference
*/
#include <bits/stdc++.h>                                           
 
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long	
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define ll long long
#define vi vector < int >
#define pii pair < int, int > 
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()                                                                    
#define pb push_back   
#define ppb pop_back
#define mp make_pair
#define s second
#define f first                                               
	
   
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;   
   
const int N = 2e3 + 13, inf = 1e9, mod = 1e9 + 7, block = 444;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
const ll INF = 1e18;
//fucking constants

string s, t; 

main () {
	int ans = inf;
	cin >> s >> t;
	for (int i = 0; i < sz(s); ++i) {
		int j = i + sz(t) - 1;
		if (j >= sz(s)) 
			break;
		int cur = 0;
		for (int x = i; x <= j; ++x)
			if (s[x] != t[x - i])
				++cur;
		ans = min(ans, cur);
	}

	cout << ans << endl;
}

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

int main()
{
  int n;
  cin >> n;
  int a[4][13]={0};
  char x;
  int y;
 
  for(int i=0;i<n;i++)
    {
      cin >> x >> y;
      if(x=='S')
	a[0][y-1]=1;
      if(x=='H')
	a[1][y-1]=1;
      if(x=='C')
	a[2][y-1]=1;
      if(x=='D')
	a[3][y-1]=1;
    }


  for(int i=0;i<4;i++)
    {
      for(int j=0;j<13;j++)
	{
	  if(a[i][j]==0)
	    {
	      if(i==0)cout << 'S' << " " << j+1 << endl;
	      if(i==1)cout << 'H' << " " << j+1 << endl;
	      if(i==2)cout << 'C' << " " << j+1 << endl;
	      if(i==3)cout << 'D' << " " << j+1 << endl;
	    }
	}
    }

  return 0;
}

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

int main() {
  const ll M = 1e9+7;
  int n; cin >> n;
  ll ans = 1;
  for (int i = 1; i<=n; i++) {
    ans = ans * i % M;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
//28/03/2020
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'


#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};
struct OverloadedNode{
    ll val,pos;
    bool operator < (const OverloadedNode &rhs) const {
        if(val==rhs.val) return pos<rhs.pos;
        else return val<rhs.val;
    }
};
//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//typedef tree<OverloadedNode,null_type,less<OverloadedNode>,rb_tree_tag,tree_order_statistics_node_update>OverloadedPbds;

//Number Theory
template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}

//Geometry
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan2( double(y1-y2) , double(x1-x2));}


/*Containers*/
//vector<ll>v;
//deque<ll>dq;
//stack<ll>stk;
//map<ll,ll>mp;
//unordered_map<ll,ll>ump;
//set<ll>st;
//multiset<ll>mst;
//unordered_set<ll>ust;
//unordered_multiset<ll>umst;
//priority_queue<ll,deque<ll>,greater<ll>>pq;
//Pbds<ll>ost;
/*OverLoaded Containers*/
//vector<OverloadedNode>v;
//deque<OverloadedNode>dq;
//stack<OverloadedNode>stk;
//map<OverloadedNode,OverloadedNode>mp;
//set<OverloadedNode>st;
//multiset<OverloadedNode>mst;
//priority_queue<OverloadedNode>pq;
//OverloadedPbds oost;
/*Global Variables*/

int main(){
    _fastio
    ll k,n;
    cin>>k>>n;
    ll a[n+10];
    ll ans=0;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(ll i=1;i+1<=n;i++){
        ans=max(ans,a[i+1]-a[i]);
    }
    ans=max(ans,a[1]+k-a[n]);

    cout<<k-ans<<en;




    return 0;
}


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

int main() {
  int64_t H,W;
  cin>>H>>W;
  if(H==1||W==1){
    cout<<1<<endl;
    return 0;
  }
  if(H%2==1 && W%2==1){
    cout<<H*(W-1)/2+H/2+1<<endl;
  }else{
    cout<<(H*W)/2<<endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T> class segtree {
private:
    int n,sz,h;
    vector<T> node, lazy;
    void eval(int k) {
        if(lazy[k]){
            node[k] += lazy[k];
            if(k < n) {
                lazy[k*2] += lazy[k] / 2, lazy[k*2+1] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }
    
public:
    segtree(int N) : sz(N), h(0) {
        n = 1;
        while(n < sz) n *= 2, h++;
        node.resize(2*n, 0), lazy.resize(2*n, 0);
        for(int i = 0; i < sz; i++) node[i+n] = 0;
        for(int i = n-1; i >= 1; i--) node[i] = node[2*i] + node[2*i+1];
    }
    void range(int a, int b, T x, int k=1, int l=0, int r=-1){
        if(r < 0) r = n;
        eval(k);
        if(b <= l || r <= a){
            return;
        }
        if(a <= l && r <= b){
            lazy[k] += (r-l)*x;
            eval(k);
        }else{
            range(a, b, x, 2*k, l, (l+r)/2);
            range(a, b, x, 2*k+1, (l+r)/2, r);
            node[k] = node[2*k] + node[2*k+1];
        }
    }
    T query(int a, int b) {
        a += n, b += n - 1;
        for(int i = h; i > 0; i--) eval(a >> i), eval(b >> i);
        b++;
        T res1 = 0, res2 = 0;
        while(a < b) {
            if(a & 1) eval(a), res1 += node[a++];
            if(b & 1) eval(--b), res2 += node[b];
            a >>= 1, b >>= 1;
        }
        return res1 + res2;
    }
    void print(){for(int i = 0; i < sz; i++) cout<<query(i,i+1)<< " ";cout<<endl;}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    vector<pii>a;
    cin >> n >> m;
    a.resize(n);
    rep(i,n){
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(),a.end(),[&](pii b,pii c){
        return b.second-b.first < c.second-c.first;
    });
    int pos = 0;
    segtree<int>seg(m+1);
    for(int d = 1; d <= m; d++){
        int ans = 0;
        while(pos < n and a[pos].second - a[pos].first + 1 < d){
            seg.range(a[pos].first,a[pos].second+1,1);
            pos++;
        }
        ans = n-pos;
        for(int k = d; k <= m; k += d){
            ans += seg.query(k,k+1);
        }
        cout << ans << "\n";
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int n;
  std::cin >> n;
  std::vector<int> x(n), y(n);
  rep(i, n) {
    int t = 0;
    std::cin >> t;
    x[i] = t, y[i] = t;
  }
  sort(x.begin(), x.end());
  int left = x[n / 2 - 1], right = x[n / 2];

  rep(i, n) {
    if (y[i] < right) {
      std::cout << right << std::endl;
    } else {
      std::cout << left << std::endl;
    }
  }

  return 0;
}


Measured memory_bytes: 4772
fun main(args: Array<String>) {
    getInputIntList()
    var second: List<Int> = getInputIntList()

    var count = 0;
    var max = 0
    second.forEach {
        if (it >= max) {
            count++
            max = it
        }
    }
    println(count)
}

fun getInputIntList() : List<Int> {
    val str = readLine()!!.toString()
    return str.split(Regex("\\s+")).map{b -> Integer.parseInt(b)}
}

Measured memory_bytes: 33980
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
using ll=long long;
const int M=100010;

int x[12][5];
int erase(){	//まず、全体を見る.消去する数字を0にして、総得点を出力;
	int a=2,ans=0,tmp;
	rep(h,0,12){
		rep(i,0,3){
			if(x[h][i]&&x[h][i]==x[h][i+1]&&x[h][i+1]==x[h][i+2])
				tmp=x[h][i],a++;
		}
		if(a>2){
			rep(i,0,4)if(x[h][i]==tmp&&x[h][i]==x[h][i+1]){
				x[h][i]=0;
				if(i==3||x[h][i+1]!=x[h][i+2])x[h][i+1]=0;
			}
			ans+=a*tmp;
			a=2;
		}
	}
	return ans;
}
void fall(){	//上の段から探索し、一つ下の段が0なら落とす;
	for(int i=11;i!=0;i--){
		rep(j,0,5){
			if(x[i][j]!=0&&x[i-1][j]==0){
				x[i-1][j]=x[i][j];
				x[i][j]=0;
				if(x[i+1][j]!=0&&x[i][j]==0){
					i+=2,j=-1;
				}
			}
		}
	}
}


int main(){
	while(1){
		int h,ans=0;
		cin>>h;
		if(h==0)break;
		rep(i,0,12){
			rep(j,0,5)x[i][j]=0;
		}
		for(int i=h-1;i>=0;i--){
			rep(j,0,5)cin>>x[i][j];
		}
		int z=-1;
		while(z!=0){
			z=erase();
			ans+=z;
			fall();
//			for(int i=11;i>=0;i--)
//				rep(j,0,5){
//				cout<<x[i][j];
//				if(j==4)cout<<endl;
//			}
//
//			cout<<ans<<endl;
//			cout<<"--------------"<<endl;
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3000
rectangle = 0
diamond = 0
while true do
  begin
  a, b, diagonal = gets.chomp.split(',').map{|x| x.to_i}
  rescue
    break
  end
  if diagonal**2 == a**2 + b**2 then
    rectangle += 1
  elsif a == b then
    diamond += 1
  end
end

puts rectangle, diamond

Measured memory_bytes: 6104
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int a,b,d;
    cin>>a>>b>>d;
    int cnt = 0;
    rep(i,a,b+1){
        if ( i % d == 0 ){
            cnt++;
        }
    }
    cout<<cnt<<endl;

}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3604
import java.util.*;
import java.io.*;

public class Main {
	static FastReader f = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);
	

	public static void main(String[] args) {
		//int t = f.nextInt();
		//while(t-- > 0)
			solve();
		out.close();
	}

	static void solve() {
		int n = f.nextInt();
		int max = 0, cur = 0;
		while(n-- > 0) {
			int a = f.nextInt(), b = f.nextInt();
			if(a == b) {
				cur++;
			} else {
				cur = 0;
			}
			max = Math.max(cur, max);
		}

		out.println(max >= 3 ? "Yes" : "No");
	}

	static class FastReader {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() {
			while(st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch(IOException ioe) {
					ioe.printStackTrace();
				}
			}
			return st.nextToken();
		}

		String nextLine() {
			String s = "";
			try {
				s = br.readLine();
			} catch(IOException ioe) {
				ioe.printStackTrace();
			}

			return s;
		}

		int  nextInt() {
			return Integer.parseInt(next());
		}
	}
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S; cin >> S;
  REP(i, 3){
    if(S[i] == '7'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 200100;

int N, M;
pair <int, int> bomb[MAXN];
int blist[MAXN];

int cv[MAXN];
vector <pair <int, int> > edge[MAXN];
int par[MAXN];
int pnum[MAXN];
bool seen[MAXN];
vector <int> vnode;

vector <int> ans;

void flood (int cloc)
{
    seen[cloc] = true;
    vnode.push_back(cloc);
    for (pair <int, int> pp : edge[cloc])
    {
        int neigh = pp.first, nnum = pp.second;
        if (!seen[neigh])
        {
            par[neigh] = cloc;
            pnum[neigh] = nnum;
            flood (neigh);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    
    cin >> N >> M;
    for (int i = 0; i < N; i++)
        cin >> bomb[i].first >> bomb[i].second;
    sort (bomb, bomb + N);

    for (int i = 0; i < N; i++)
        blist[i] = bomb[i].first;
    blist[N] = 1.1e9;

    for (int i = 0; i <= N; i++)
    {
        cv[i] = 0;
        if (i < N)
            cv[i] ^= bomb[i].second;
        if (i > 0)
            cv[i] ^= bomb[i-1].second;

        seen[i] = false;
    }

    N++;
    for (int i = 0; i < M; i++)
    {
        int l, r; cin >> l >> r;
        r++;
        int a = lower_bound(blist, blist + N, l) - blist;
        int b = lower_bound(blist, blist + N, r) - blist;
        edge[a].push_back(make_pair (b, i + 1));
        edge[b].push_back(make_pair (a, i + 1));
    }

    bool bad = false;
    for (int i = 0; i < N; i++)
    {
        if (!seen[i])
        {
            vnode.clear();
            flood (i);

            int cp = 0;
            for (int node : vnode)
                cp ^= cv[node];
            if (cp)
                bad = true;
            else
            {
                reverse(vnode.begin(), vnode.end());
                for (int node : vnode)
                {
                    if (cv[node])
                    {
                        ans.push_back(pnum[node]);
                        cv[node] ^= 1;
                        cv[par[node]] ^= 1;
                    }
                }
            }
        }
    }

    if (bad)
        cout << "-1\n";
    else
    {
        cout << ans.size() << "\n";
        sort (ans.begin(), ans.end());
        for (int i = 0; i < ans.size(); i++)
        {
            if (i) cout << " ";
            cout << ans[i];
        }
        cout << "\n";
    }
}

Measured memory_bytes: 19064