akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

struct LazySegmentTree {
private:
	int n; // length of node, lazy
	vector<ll> node, lazy;
	/* propagete the laziness of the k-th node. */
	void eval(int k, int l, int r) {
		if (lazy[k] != 0) {
			node[k] += lazy[k];
			if (r - l > 1) {
				lazy[2 * k + 1] += lazy[k] / 2;
				lazy[2 * k + 2] += lazy[k] / 2;
			}
			lazy[k] = 0;
		}
	}
public:
	LazySegmentTree() {}
	/* constructor. v is the data. */
	LazySegmentTree(vector<ll> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1, 0);

		for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2];
	}
	/* add x to s[a],s[a+1],...,s[b-1] */
	void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		eval(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] += (r - l) * x;
			eval(k, l, r);
		}
		else {
			add(a, b, x, 2 * k + 1, l, (l + r) / 2);
			add(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = node[2 * k + 1] + node[2 * k + 2];
		}
	}
	/* calculate the sum of s[a],s[a+1],...,s[b-1] */
	ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		eval(k, l, r);
		if (b <= l || r <= a) return 0;
		if (a <= l && r <= b) return node[k];
		ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
		ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
		return vl + vr;
	}
};

int n;
vector<int> color;
vector<vector<int>> g;

void input() {
	cin >> n;
	color.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> color[i]; --color[i];
	}
	g.resize(n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b; cin >> a >> b;
		--a, --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
}

LazySegmentTree cnt_color;
vector<ll> res;
vector<int> save;

void setup() {
	cnt_color = LazySegmentTree(vector<ll>(n, 0));
	res.resize(n, 0);
	save.resize(n);
}

void dfs(int s = 0, int p = -1) {
	save[s] = cnt_color.getsum(color[s], color[s] + 1);
	cnt_color.add(color[s], color[s] + 1, -save[s]);
	cnt_color.add(0, color[s], 1);
	cnt_color.add(color[s] + 1, n, 1);
	for (int nx : g[s]) {
		if (nx != p) {
			dfs(nx, s);
			ll tmp = cnt_color.getsum(color[s], color[s] + 1);
			res[color[s]] += tmp * (tmp - 1) / 2 + tmp;
			cnt_color.add(color[s], color[s] + 1, -tmp);
		}
	}
	ll tmp = cnt_color.getsum(color[s], color[s] + 1);
	cnt_color.add(color[s], color[s] + 1, -tmp + save[s]);
	if (s == 0) {
		for (int i = 0; i < n; ++i) {
			tmp = cnt_color.getsum(i, i + 1);
			res[i] += tmp * (tmp - 1) / 2 + tmp;
		}
		ll total = ((ll)n) * (n - 1) / 2 + n;
		for (int i = 0; i < n; ++i)
			res[i] = total - res[i];
	}
}

int main() {
	input();
	setup();
	dfs();
	for (auto r : res)
		cout << r << endl;
	return 0;
}

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

int get(int x) {
	int r = 1;
	for(int i = 1; i <= x; i++) r *= 2;
	return r;
}

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a, b, c, k; cin >> a >> b >> c >> k;
	for(int i = 0; i <= k; i++) {
		if(a < b * get(i) && b * get(i) < c * get(k - i)) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
	int main() {
		int a,b;
		cin>>a>>b;
		if(a==b)
			cout<<"Draw";
		else if(a<b&&a!=1)
			cout<<"Bob";
		else if(b<a&&b!=1)
			cout<<"Alice";
		else if(a==1)
			cout<<"Alice";
		else if(b==1)
			cout<<"Bob";
	}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
     
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
     
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
  int n, i, j;
  cin >> n;
  int m = inf, M = -1;
  vi num(101);
  for (i = 0; i < n; i++) {
    int a;
    cin >> a;
    m = min(m, a);
    M = max(M, a);
    num[a]++;
  }
  bool flag = false;
  if (num[m] > 2) {
    flag = false;
  }
  else if (num[m] == 2) {
    if (M == 2*m - 1) {
      for (i = m + 1; i <= M; i++) {
	if (num[i] < 2) {
	  cout << "Impossible" << endl;
	  return 0;
	}
      }
      flag = true;
    }
  }
  else if (num[m] == 1) {
    if (M == 2*m) {
      for (i = m + 1; i <= M; i++) {
	if (num[i] < 2) {
	  cout << "Impossible" << endl;
	  return 0;
	}
      }
      flag = true;
    }
  }
  if (flag) {
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
}



Measured memory_bytes: 256
n,m,l = map(int, input().split())
a = list()
for i in range(n):
    a.append(list(map(int, input().split())))
b = list()
for i in range(m):
    b.append(list(map(int, input().split())))

for i in range(n):
    print(*[sum([a[i][k] * b[k][j] for k in range(m)]) for j in range(l)])


Measured memory_bytes: 6584
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <tuple>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int h[n];
	rep(i,0,n) cin >> h[i];
	int locate=0;
	locate = h[0]-1;
	rep(i,1,n){
		if(locate==h[i]) continue;
		else if(locate<h[i]) locate = h[i]-1;
		else{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


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

#define int long long int
#define ll long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define all(a) a.begin(),a.end()
#define mod 1000000007
#define pi 3.141592653589
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod) ;
int power(int x, int y) ;
int gcd(int a, int b) ;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
// template<typename T>
// using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
//(*****FOR USING ORDERED SET CHANGE INT*******)

// struct chash {
//     const int RANDOM = (long long)(make_unique<char>().get()) ^ chrono::high_resolution_clock::now().time_since_epoch().count();
//     static unsigned long long hash_f(unsigned long long x) {
//         x += 0x9e3779b97f4a7c15;
//         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//         return x ^ (x >> 31);
//     }
//     static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; }
//     int operator()(int x) const { return hash_f(x)^RANDOM; }
// };

int power(int x, int y) ;
int gcd(int a,int b) ; 

vi v[1000001] ;
bool vis[1000001] ;

void dfs(int n) {
    vis[n] = true ;
    for(auto i : v[n]) {
        if(!vis[i]) {
            dfs(i) ;
        }
    }
}

signed main() {
    quickie
    int n, m ;
    cin >> n >> m ;
    rep(i, 0, m) {
        int a, b ;
        cin >> a >> b; 
        v[a].pb(b) ;
        v[b].pb(a) ;
    }
    int ans = 0 ;
    rep(i, 1, n+1) {
        if(!vis[i]){
            dfs(i) ;
            ans++ ;
        }
    }
    cout << ans-1 << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

int gcd(int a,int b) {
    if(a==0) return b;
    return gcd(b%a,a);
}



Measured memory_bytes: 31524
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

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

int sum , ans ;
string s ;

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

	cin >> s ;

	for (int i = 0 ; i < _sz(s) ; i ++) {
		if (s[i] > '0') {
			int tmp = sum + (s[i] - '1') + 9 * (_sz(s) - i - 1) ;
			ans = max(ans , tmp) ;
		}
		sum += s[i] - '0' ;
	}

	ans = max(ans , sum) ;

	cout << ans << '\n' ;
}

Measured memory_bytes: 892
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 1
    f = 0
    for i in range(n-1):
        if a[i] < a[i+1]:
            if f == -1:
                ans += 1
                f = 0
            else:
                f = 1
        elif a[i] > a[i+1]:
            if f == 1:
                ans += 1
                f = 0
            else:
                f = -1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
using namespace std;
long long a[100000],b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
int main()
{
	cin>>n>>z;
	for(i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for(i=n-1;i>n-z-1;i--)
	y+=a[i];
	cout<<y<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();

		long x[] = new long[n];
		long y[] = new long[n];
		long z[] = new long[n];

		for(int i=0; i<n; i++) {
			x[i]=sc.nextLong();
			y[i]=sc.nextLong();
			z[i]=sc.nextLong();
		}

		long ans = 0;
		for(int i=0; i<8; i++) {
			long s1 = 1;long s2 = 1;long s3 = 1;
			if((i>>0&1)==1) s1=-1;
			if((i>>1&1)==1) s2=-1;
			if((i>>2&1)==1) s3=-1;
			ArrayList<Long> sum = new ArrayList<Long>();
			for(int j=0; j<n; j++) {
				sum.add(s1*x[j] + s2*y[j] + s3*z[j]);
			}
			Collections.sort(sum, Collections.reverseOrder());
			long tmp=0;
			for(int j=0; j<m; j++) {
				tmp += sum.get(j);
			}
			ans = Math.max(ans, tmp);
		}
		System.out.println(ans);
		sc.close();
	}


}


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

using namespace std;

int main()
{
	int N, T;
	int min_v, max_sub, count, ans = 0;
	cin >> N >> T;

	vector<int> A(N);

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

	min_v = A[0];
	max_sub = 0;
	count = 1;
	for (int i = 1; i < N; i++)
	{
		int v = A[i] - min_v;
		if (min_v == A[i])
		{
			count++;
		}

		if (max_sub == v)
		{
			ans += count;
		}

		if (min_v > A[i])
		{
			min_v = A[i];
			count = 1;
		}

		if (max_sub < v)
		{
			max_sub = v;
			ans = count;
		}
		
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
from scipy.sparse.csgraph import floyd_warshall

N, M, L, *I = map(int, open(0).read().split())
ABC, ST = I[:3 * M], I[3 * M + 1:]

E = [[0] * N for _ in range(N)]
for a, b, c in zip(*[iter(ABC)] * 3):
    E[a - 1][b - 1] = E[b - 1][a - 1] = c

E = floyd_warshall(E)

for i, ei in enumerate(E):
    for j, eij in enumerate(ei):
        E[i][j] = (eij <= L)

E = floyd_warshall(E)

INF = float("inf")

A = []
for s, t in zip(*[iter(ST)] * 2):
    a = E[s - 1][t - 1] - 1
    A.append("-1" if a == INF else str(int(a)))

print("\n".join(A))

Measured memory_bytes: 40756
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();
		int[] h = new int[n];
		int result = 0;
		int tmp = 0;
		for(int i = 0; i < n; i++){
    		h[i] = sc.nextInt();
    		if(i > 0){
    		    if(h[i] <= h[i - 1]){
    		        tmp++;
    		    }else{
    		        result = max(result, tmp);
    		        tmp = 0;
    		    }
    		}
		}
		result = max(result, tmp);


		// 計算

		// 出力
		System.out.println(result);
	}

}


Measured memory_bytes: 52344
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){	
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	int size = s.size();
	int even = size%2==0 ? 1 : 0;
	int same = s[0]==s[size-1] ? 1 : 0;
	if(even^same == 1) cout << "Second" << '\n';
	else cout << "First" << '\n';

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    string S[N];
    int X[4] = {0};
    REP(i, N){
        cin >> S[i];

        if(S[i] == "AC") X[0]++;
        if(S[i] == "WA") X[1]++;
        if(S[i] == "TLE") X[2]++;
        if(S[i] == "RE") X[3]++;
    }

    cout << "AC x " << X[0] << endl;
    cout << "WA x " << X[1] << endl;
    cout << "TLE x " << X[2] << endl;
    cout << "RE x " << X[3] << endl;

    return 0;
}

Measured memory_bytes: 6740
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		if(a%2 != 0 && b%2 != 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		
		
	}

}


Measured memory_bytes: 23124
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;

const int MAXN = 2000;
int n , a[ MAXN + 5 ] , In[ MAXN + 5 ];
bool vis[ MAXN + 5 ];
vector< int > Graph[ MAXN + 5 ];
vector< int > DAG[ MAXN + 5 ];

void Make_Graph( ) {
	for( int i = 1 ; i <= n ; i ++ )
		for( int j = i + 1 ; j <= n ; j ++ )
			if( __gcd( a[ i ] , a[ j ] ) != 1 ) {
				Graph[ i ].push_back( j );
				Graph[ j ].push_back( i );
			}
}
void dfs( int u ) {
	vis[ u ] = 1;
	for( int i = 0 ; i < Graph[ u ].size( ) ; i ++ ) {
		int v = Graph[ u ][ i ];
		if( vis[ v ] ) continue;
		DAG[ u ].push_back( v ); In[ v ] ++;
		dfs( v );
	}
}
void Make_DAG( ) {
	for( int i = 1 ; i <= n ; i ++ )
		if( !vis[ i ] ) dfs( i );
}
void Topo( ) {
	priority_queue< int > Que;
	for( int i = 1 ; i <= n ; i ++ )
		if( !In[ i ] ) Que.push( i );
	
	while( !Que.empty( ) ) {
		int u = Que.top( ); Que.pop( );
		printf("%d ", a[ u ] );
		for( int i = 0 ; i < DAG[ u ].size( ) ; i ++ ) {
			int v = DAG[ u ][ i ];
			if( -- In[ v ] == 0 )
				Que.push( v );
		}
	}
}

int main( ) {
	scanf("%d",&n);
	for( int i = 1 ; i <= n ; i ++ )
		scanf("%d",&a[ i ]);
	sort( a + 1 , a + n + 1 );

	Make_Graph( );
	Make_DAG( );

	Topo( );
	return 0;
}

Measured memory_bytes: 17664
import java.util.Scanner;
import java.util.InputMismatchException;
class Main{
public static void main(String args[]){

    Scanner scan = new Scanner(System.in);
    try{
int a = scan.nextInt();
int b = scan.nextInt();


if(a<b){

System.out.println("a < b");
}


if(a>b){

System.out.println("a > b");
}


if(a==b){

System.out.println("a == b");
}










}catch (InputMismatchException e) {
        	System.out.println("try again!!");
        }





}
}



Measured memory_bytes: 26060
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<int> n(3);
    for (int i = 0; i < 3; i++) {
      cin >> n.at(i);
    };
    sort(n.begin(), n.end(), greater<int>());
    cout << n.at(0) * 10 + n.at(1) + n.at(2) << endl;
}


Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

h = onem()
w = onem()

ma = max(h,w)

p = onem()

print(-(-p//ma))











Measured memory_bytes: 3436
c = [list(map(int,input().split())) for _ in range(3)]
ans = "Yes"
for i in range(2):
    if c[0][i] - c[0][i+1] == c[1][i] - c[1][i+1] == c[2][i] - c[2][i+1]:
        pass
    else:
        ans = "No"
print(ans)

Measured memory_bytes: 3060
#include <iostream> // #include <stdio.h>
int main(void){
	int N, mi = 10000, ma = 0;
	std::cin >> N; // scanf(“%d”, &N);
	for(int i = 0; i < N; i++){
		int a;
		 std::cin >> a; // scanf(“%d”, &a);
		mi = std::min(mi, a); // if(a < mi) mi = a;
		ma = std::max(ma, a); // if(a > ma) ma = a;
	}
	std::cout << ma - mi << std::endl;
	// printf(“%d”, ma - mi);
}


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

int main(){
  int n,m,k;
  cin>>n>>m>>k;
  ll a[200005], b[200005], sum[200005], sa[200005], sb[200005];
  rep(i,n) cin>>a[i];
  rep(i,m) cin>>b[i];
  sa[0]=0; sb[0];
  rep(i,n) sa[i+1]=sa[i]+a[i];
  rep(i,m) sb[i+1]=sb[i]+b[i];

  ll ans=0;
  rep(ba,n+1) {
    ll time=sa[ba];
    ll book=ba;
    if(time>k) continue;
    int l=0,r=m+1;
    while(r-l>1){
      int c=(l+r)/2;
      if(time+sb[c]>k){
	r=c;
      }
      else{
	l=c;
      }
    }
    book+=l;
    ans=max(ans,book);
  }
  cout<<ans<<endl;
  return 0;
}


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

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

		int n_divide = 0;
		bool can_divide = true;

		while(can_divide) {
			for(int i=0; i<A.size(); i++) {
				if(A[i] % 2 == 0) {
						A[i] /= 2;
				} else {
						can_divide = false;
						break;
				}
			}

			if (can_divide) {
					n_divide++;
			}
		}

		cout << n_divide << endl;
		return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int lcm(int a, int b) { return a / __gcd(a, b) * b; }
int prime[20000000];
int a[300001];
map<int, int> mp;
vector<int> pr;
void sieve(int n)
{

    for (int p = 2; p * p <= n; p++)
    {

        if (prime[p] == 0)
        {

            for (int i = p * p; i <= n; i += p)
                prime[i] = p;
        }
    }
    for (int i = 2; i <= 20000000;i++){
        if(prime[i]==0)
            pr.pb(i);
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    sieve(20000000);
    //cin >> tc;
    while (tc--)
    {
        int n, m;
        cin >> n >> m;
        set<int> se;
        for (int i = 0; i < m;i++){
            int d;
            cin >> d;
            int a;
            for (int j = 0; j < d;j++){
                cin >> a;
                se.insert(a);
            }
        }
        int f = (int)se.size();
        cout << n - f << endl;
    }

    return 0;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//互除法
ll GCD(ll a, ll b){
  return b ? GCD(b,a%b) : a;
}

ll LCM(ll a, ll b){
  return (a / GCD(a,b))*b;
}

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll K; cin >> K;
  
  //main
  ll ans =0;
  
  FOR(i,K){
    FOR(j,K){
      FOR(k,K){
        ans += GCD(GCD(i+1,j+1),k+1); 
      }
    }
  }
  
  // output
  cout << ans << endl;

  return 0;
}

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

int main() {
  int R;
  cin>>R;
  if(R<1200)puts("ABC");
  else if(R<2800)puts("ARC");
  else puts("AGC");
  return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
a=[]
b=[]
G =[[] for _ in range(N)] #連結リスト
for i in range(M):
    ai,bi = map(int,input().split())
    ai -= 1
    bi -= 1
    G[ai].append(bi)
    G[bi].append(ai)
    a.append(ai)
    b.append(bi)
used = [0]*(N)
#幅優先探索で連結判定
def dfs(v):
    used[v] = True
    for u in G[v]:
        if demo1==v and demo2==u:
            continue
        if not used[u]:
            dfs(u)
    return
demo1=0
demo2=0
ans = 0
#各辺についてそれが橋かどうかチェック
for i in range(M):
    for j in range(N):
        used[j] = False
    demo1=a[i]
    demo2=b[i]
    dfs(a[i])
    if not used[b[i]]:
        ans += 1
print(ans)

Measured memory_bytes: 41456
#include <iostream>

using namespace std;

bool board[100][100];

int main(int argc, char *argv[]) {
	int A, B;
	cin >> A >> B;

	for (int y = 0; y < 50; y++) {
		for (int x = 0; x < 100; x++) {
			board[x][y] = false;
		}
	}

	for (int y = 50; y < 100; y++) {
		for (int x = 0; x < 100; x++) {
			board[x][y] = true;
		}
	}

	for (int i = 1, idx = 1; i < A; i++, idx += 2)
		board[idx % 100][(idx / 100) * 2 + 1] = true;

	for (int i = 1, idx = 1; i < B; i++, idx += 2)
		board[idx % 100][(idx / 100) * 2 + 51] = false;

	cout << 100 << " " << 100 << endl;
	for (int y = 0; y < 100; y++) {
		for (int x = 0; x < 100; x++) {
			if (board[x][y]) cout << ".";
			else cout << "#";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import math

N,K=map(int,input().split())
def sis(K,N):
    n1=K/N
    n2=math.log2(n1)
    n3=int(n2)
    if n2>n3:
        n3+=1
    return n3
ans=0
for i in range(N):
    if i>=K:
        ans+=1/N
    else:
        ans+=1/((2**sis(K,i+1))*N)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int ketasuu(int n) {
    if (n == 0) {
        return 1;
    }
    int sisuu=1, result=0;
    while (n/sisuu != 0) {
        sisuu *= 10;
        result++;
    }
    return result;
}
int nketaNum(int n) {
    int k=1;
    for (int i=0; i<n-1; i++) {
        k *= 10;
    }
    return 9*k;
}
int main() {
    int n;
    cin >> n;
    int result = 0;
    if (ketasuu(n)%2 == 0) {
        for (int i=1; i<ketasuu(n); i+=2) {
            result += nketaNum(i);
        }
    } else {
        result = n;
        for (int i=2; i<ketasuu(n); i+=2) {
            result -= nketaNum(i);
        }
    }
    cout << result << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LSOne(i) ((i) & -(i))

const int MAXN = 100;
int n, mis = 0;

int main (void) {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        if (x != i) mis++;
    }

    if (mis <= 2) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    cout << "\n";

    return 0;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define RFOR(i, k, j) for (int i = k - 1; i >= j; i--)
#define RREP(i, j) RFOR(i, j, 0)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

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

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x; 
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int m, d;
    cin >> m >> d;

    int ans = 0;
    FOR(i, 1, d + 1) FOR(j, 1, m + 1) {
        if (i % 10 < 2 or i / 10 < 2) continue;
        int x = (i % 10) * (i / 10);
        if (x == j) ans++;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
 
using namespace std;
using ll = long long;
 
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
 
#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
 
// constexpr int MOD = 1e9+7;
 
int main(void){
    Cin(int, n, m);
    Cins2(int, m, x, y);
    
    vc<bool> v(n); v[0] = 1;
    vc<int> c(n, 1);
    
    For(i, m){
        x[i] --, y[i] --;
        c[x[i]] --;
        c[y[i]] ++;
        if(v[x[i]]) v[y[i]] = true;
        if(c[x[i]] == 0) v[x[i]] = false;
    }
    
    int ans = 0;
    For(i, n) if(v[i]) ans ++;
    Cout(ans);
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main{

    public static void main(String args[]){
		solve();
    }
	
	private static void solve(){
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
		int sum = 0;
		for(int i = 0; i < N; i++){
			sum += sc.nextInt();
			if(sum > H)break;
		}
		System.out.println(sum >= H ? "Yes" : "No");
	}
}

Measured memory_bytes: 48468
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define int long long

int32_t main(){
	int k;
	cin >> k;
	int x = 7;
	for (int i = 0; i < 1000000; i++) {
//		cout << x << endl;
		if (x == 0 || x % k == 0){
			return cout << i + 1, 0;
		}
		x = (x * 10 + 7) % k;
	}
	cout << -1;
}


Measured memory_bytes: 3628
#include<stdio.h>

#define MAX_N 500001
#define INF (1<<30)

int cnt=0;
int L[MAX_N],R[MAX_N];

void merge(int *A,int left,int mid,int right){
  int i,j,k;
  
  int n1=mid-left;
  int n2=right-mid;
  
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];

  L[n1]=INF;
  R[n2]=INF;

  i=0;
  j=0;

  for(k=left;k<right;k++,cnt++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else {
      A[k]=R[j];
      j=j+1;
    }
  }
}

void mergeSort(int *A,int left,int right){
  if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(void){

  int n,A[MAX_N],i;
 
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  mergeSort(A,0,n);

  for(i=0;i<n;i++){
    printf("%d%c",A[i],(i<n-1?' ':'\n'));
  }  
  printf("%d\n",cnt);
  
  return 0;
}



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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n,i,t,M=-inf,m=inf;
	cin>>n;
	for (i=0;i<n;i++){
		cin>>t;
		m=min(t,m);
		M=max(t,M);
	}
	cout<<M-m;
	return 0;
}

Measured memory_bytes: 256
const check = (t,d_x,d_y)=>{
  const xy = d_x+d_y;
  if (t<xy) return false;
  return t%2 === xy%2;
};
const travel = (plan)=>{
  'use strict';
  const current = [0,0,0];

  for (let d of plan) {
    const abs_x = Math.abs(current[1] - d[1]);
    const abs_y = Math.abs(current[2] - d[2]);
    const time = d[0] - current[0];

    if(!check(time,abs_x,abs_y)){return false}
    else{current[0] = d[0],current[1] = d[1],current[2] = d[2]}
  }

  return true

};
function Main(input) {
  const plan = input.trim().split('\n').map(line=>line.split(' ').map(data=>parseInt(data))).slice(1);
  const result = travel(plan);
  console.log(result?'Yes':'No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 52904
#include<stdio.h>
int main(){
  int n,m,s=0,a,i,c=1;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    s+=a;
    if(s<=m)c++;
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
import bisect
import numpy as np

N=int(input())

A=list(map(int,input().split()))
A.sort()
minus=bisect.bisect_left(A,0)
Aabs=np.abs(np.array(A))
if minus%2==0 or (minus!=N and A[minus]==0):
  print(np.sum(Aabs))
else:
  Aabs_sort=np.sort(Aabs)
  print(np.sum(Aabs)-(2*Aabs_sort[0]))

Measured memory_bytes: 23284
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
c = {"r": p, "s": r, "p": s}

ans = 0
wins = [False] * k

for i in range(n):
    if not wins[i % k] or t[i] != t[i-k]:
        ans += c[t[i]]
        wins[i % k] = True
    else:
        wins[i % k] = False

print(ans)

Measured memory_bytes: 40560
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    string temp;
    cin>>temp;
    if((temp[0]==temp[1]&&temp[1]==temp[2])||(temp[1]==temp[2]&&temp[2]==temp[3]))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n, K;
    cin >> n >> K;
    vector<vector<vector<int>>> d(n + 1);
    for (int i = 0; i <= n; i++) {
        d[i].assign(1 << i, vector<int>(i + 1));
        string s;
        cin >> s;
        for (int j = 0; j < (1 << i); j++) {
            if (s[j] == '1') d[i][j][0]++;
        }
    }
    vector<vector<int>> r(n + 1);
    for (int i = 0; i <= n; i++) {
        r[i].assign(1 << i, 0);
    }

    for (int i = n; i > 0; i--) {
        for (int x = 0; x < (1 << i); x++) {
            for (int k = 0; k <= i; k++) {
                int xx = (x & ((1 << k) - 1));
                r[k][xx] += d[i][x][k];
                for (int c = 0; c <= 1; c++) {
                    int kk = k;
                    while (kk < i && ((x >> kk) & 1) != c) kk++;
                    if (kk < i) {
                        xx = x >> (kk - k);
                        xx &= ~((1 << k) - 1);
                        xx |= (x & ((1 << k) - 1));
                        d[i - (kk - k)][xx][k + 1] += d[i][x][k];
                    }
                }
            }
        }
    }

    for (int i = n; i >= 0; i--) {
        for (int x = 0; x < (1 << i); x++) {
            if (r[i][x] >= K) {
                for (int k = i - 1; k >= 0; k--) {
                    cout << ((x >> k) & 1);
                }
                return 0;
            }
        }
    }

    return 0;
}

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

int main() {
	int N, maxi = 0;
	map<string, int> M;
	cin >> N;
	for (int i = 0; i < N; i++) {
		string S;
		cin >> S;
		M[S]++;
		maxi = max(maxi, M[S]);
	}
	for (map<string, int>::iterator it = M.begin(); it != M.end(); it++) {
		if ((*it).second == maxi) {
			cout << (*it).first << endl;
		}
	}
	return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    int32 d = 0;
    int32 n2 = n;
    while(n2 > 0){
        d++;
        n2 /= 10;
    }
    int32 ans = 0;
    for(int32 i = 1; i < d; i+=2){
        ans += pow(10, i) - pow(10, i-1);
    }
    if(d % 2 == 1){
        ans += n - pow(10, d-1) + 1;
    }
    ANS(ans);
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	int minA = 999;
	int maxA = -999;
	rep(i, N){
		cin >> a[i];
		minA = min(minA, a[i]);
		maxA = max(maxA, a[i]);
	}
	int cost = 0;
	int ans = 100000000;
	for(int i = minA; i <= maxA; ++i){
		int cost = 0;
		for(auto an : a){
			cost += (an - i) * (an - i);
		}
		ans = min(ans, cost);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias M = Tuple!(long, "x", long, "h");

void main()
{
    auto nda = readln.split.to!(long[]);
    auto N = nda[0];
    auto D = nda[1];
    auto A = nda[2];
    M[] MS;
    foreach (_; 0..N) {
        auto xh = readln.split.to!(long[]);
        MS ~= M(xh[0], xh[1]);
    }
    sort!"a.x < b.x"(MS);
    auto dc = new long[](N);
    long d, x;
    foreach (i; 0..N) {
        d += dc[i];
        auto h = MS[i].h - d;
        if (h <= 0) continue;
        auto y = (h + A - 1) / A;
        x += y;
        if (i == N-1) continue;
        d += A*y;
        auto rg = MS[i].x + D*2;
        if (MS[i+1].x > rg) {
            dc[i+1] -= A*y;
        } else if (MS[$-1].x > rg) {
            auto l = i+1, r = N-1;
            while (l+1 < r) {
                auto m = (l+r)/2;
                if (MS[m].x > rg) {
                    r = m;
                } else {
                    l = m;
                }
            }
            dc[r] -= A*y;
        }
    }
    writeln(x);
}

Measured memory_bytes: 8316
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll modpow(ll a,ll n,ll mod){
    if(n==1) return a%mod;
    else if(n%2==0) return modpow(a*a%mod,n/2,mod);
    else return a*modpow(a*a%mod,(n-1)/2,mod)%mod;
}

ll modfact(ll n_a,ll n_z,ll mod){
    if(n_a==n_z) return n_z%mod;
    else return n_a*modfact(n_a-1,n_z,mod)%mod;
}

ll modcomb(ll n,ll m,ll mod){
    return modfact(n,n-m+1,mod)*modpow(modfact(m,1,mod),mod-2,mod)%mod;
}

int main(){
    ll n,a,b,ans;
    cin>>n>>a>>b;
    ans=modpow(2,n,1e9+7)-modcomb(n,a,1e9+7)-modcomb(n,b,1e9+7)-1;
    while(ans<0) ans+=1e9+7;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  int n,m; cin>>n>>m;
  std::vector<int> v(m,0);
  int ans=0;
  rep(i,n) {
    int k; cin>>k;
    rep(j,k) {
      int num; cin>>num;
      v[num-1]++;
    }
  }
  debug(v);
  rep(i,m) {
    if (v[i] == n) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 508
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define INF 2e18;
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()
typedef long double f80;

const int N = 5005;

int dp[N][N];
pair<int,int> p[N];

inline bool cmp(const pii &a, const pii &b) {
    return a.fi + a.se < b.fi + b.se;
}

signed main()
{
   // freopen("inp.txt","r",stdin);
   // freopen("out.txt","w",stdout);
    int n;
    cin >> n;
    fr(i, 1, n) {
        cin >> p[i].fi >> p[i].se;
    }
    sort(p + 1, p + n + 1, cmp);
    fr(i, 0, N - 1) {
        fr(j, 0, N - 1) {
            dp[i][j] = 1e18;
        }
    }
    dp[0][0] = 0;
    fr(i, 0, n - 1) {
        fr(j, 0, n - 1) {
            if(dp[i][j] == 1e18) continue;
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            if(dp[i][j] <= p[i + 1].fi) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + p[i + 1].se);
        }
    }
    int ans = 0;
    fr(i, 1, n) {
        if(dp[n][i] != 1e18) {
            ans = i;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 195968
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>bool chmax(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int h,w,k;
    cin>>h>>w>>k;
    
    auto dp=make_vec<ll>(h+10,w+10);
    dp[0][0]=1;
    rep(i,h) rep(j,w) {
        ll x=0,y=0,z=0;
        for(int bit=0; bit<(1<<(w-1)); bit++) {
            bool ok=true;
            rep(k,w-2) {
                if((bit&(1<<k)) && (bit&(1<<(k+1)))) ok=false;
            }
            if(!ok) continue;
            
            if(j>0 && bit&(1<<(j-1))) x++;
            else if(bit&(1<<j)) z++;
            else y++;
        }
        
        if(j>0) {
            dp[i+1][j-1]+=dp[i][j]*x;
            dp[i+1][j-1]%=MOD;
        }
        
        dp[i+1][j]+=dp[i][j]*y;
        dp[i+1][j]%=MOD;
        
        dp[i+1][j+1]+=dp[i][j]*z;
        dp[i+1][j+1]%=MOD;
        
        //cout<<x<<" "<<y<<" "<<z<<endl;
    }
    
    cout<<dp[h][k-1]<<endl;
    //rep(i,h+1) rep(j,w) cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
}


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

using namespace std;

int n,a[20];
long long ans;
char s[20];

void dfs(int x)
{
	if(x==n)
	{
		long long nowsum=0;
		for(int i=1;i<=n;i++)
		{
			nowsum=nowsum*10+s[i]-'0';
			if(a[i])
			{
				ans+=nowsum;
				nowsum=0;
			}
		}
		ans+=nowsum;
		return;
	}
	a[x]=1;
	dfs(x+1);
	a[x]=0;
	dfs(x+1);
}

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	dfs(1);
	cout<<ans;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n){
        cin >> h[i];
    }

    h.push_back(0);
    bool f = false;
    int tmp = 105;
    int x;
    ll ans = 0;
    rep(i, n+1){
        rep(j, n+1){
            if(h[j] > 0){
                tmp = min(tmp, h[j]);
                if(!f){
                    x = j;
                    f = true;
                }
            }else{
                if(f){
                ans += tmp;
                for (int k = x; k < j; ++k) {
                        h[k] -= tmp;
                }
                f = false;
                tmp = 105;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
  char s[1000];
  scanf("%s",s);
  
  int n;
  n=strlen(s);
  int count=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      if(s[i]=='L') count++;
    }else{
      if(s[i]=='R') count++;
    }
  }
  if(count==0) printf("Yes");
  else printf("No");
 
  return 0;
}

Measured memory_bytes: 128