akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = [0]*N
    B=[]
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            if ans[j-1] == 1:
                cons += 1
        if A[i-1] == 1 and cons % 2 == 0:
            ans[i-1] = 1
            B.append(i)
            #ans_str = ans_str + str(i) + " "
            continue
        if A[i-1] == 0 and cons % 2 == 1:
            ans[i-1] = 1
            B.append(i)
            #ans_str = ans_str + str(i) + " "
            continue
            
    print(len(B))
    print(*B)
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 65616
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

ll mod_pow(ll a,ll b,ll p){ //(a^b)%p
	ll res=1;
	a%=p;

	while(b>0){
		if(b&1==1) res=((res%p)*(a%p))%p;
		a=(a%p*a%p)%p;
		b>>=1;
	}
	return res;
}

//mod_inv=mod_pow(denominator,MOD-2,MOD);

int32_t main(){
	fastio();
	int n;
	cin >> n;
	int cnt = 0;
	int val = 0;
	string s;
	cin >> s;
	for(int i = 0; i < n; i++){
		if(s[i] == '1') cnt++;
		
	}
	if(cnt == 0){
		for(int i = 1; i <= n; i++){
			cout << 1 << "\n";
		}
		return 0;
	}
	if(cnt == 1){
		if(s[n - 1] == '1'){
			for(int i = 0 ; i <= n - 2; i++){
				cout << 2 << "\n";
			}
			cout << 0 << "\n";
			return 0;
		}
		
		for(int i = 0 ; i < n; i++){
			if(s[i] == '1'){
				cout << 0 <<"\n";
			}else{
				if(i == n - 1)
				cout << 2 <<"\n";
				else cout << 1 <<"\n"; 
			}
		}
		return 0;
	}else{
		int x = cnt + 1, y = cnt - 1 ;
		int l = 0, r = 0;
		for(int i = 0 ; i < n; i++){
			if(s[i] == '1'){
				l += mod_pow(2, n - 1 - i, x);
				r += mod_pow(2, n - i - 1 , y);
			}
		}
		for(int i = 0; i < n; i++){
			if(s[i] == '1'){
				int to_minus = mod_pow(2,(n - i - 1) , y);
				int k = (r - to_minus + y ) % y;
				int ans = 1;
				while(k > 0 ){
					k %= __builtin_popcount(k);
					ans++;
				}
				cout << ans <<"\n";
			}else{
				int to_add = mod_pow(2, n - i - 1 , x);
				int k = (l + to_add) % x;
				int ans = 1;
				while(k > 0 ){
					k %= __builtin_popcount(k);
					ans++;
				}
				cout << ans <<"\n";
			}
		}
	}
}

Measured memory_bytes: 3780
#include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					for (int x = 0; x < 10; x++) {
						if (i + j + k + x == n)ans++;
					}
				}
			}
		}
		cout << ans <<endl;
	}
}

Measured memory_bytes: 3008
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

template <typename T> T mod_div(T a, T b, T m);
template <typename T> T mod_pow(T n, T r, T m);

int main() {
	uint N;
	cin >> N;
	
	vector<uint> A(N);
	map<uint, uint> prs;
	
	ull mod = pow(10, 9) + 7;
	
	for(uint i=0; i<N; i++) {
		uint a;
		cin >> a;
		A[i] = a;
		
		for(uint j=2; j<=a && j*j<=A[i]; j++) {
			uint cnt = 0;
			while(a % j == 0) {
				cnt++;
				a /= j;
			}
			
			if(cnt > 0) prs[j] = max(prs[j], cnt);
		}
		
		if(a != 1) prs[a] = max(prs[a], (uint)1);
	}
	
	ull lcmA = 1;
	for(auto itr = prs.begin(); itr != prs.end(); ++itr) {
		lcmA = lcmA * mod_pow((ull)itr->first, (ull)itr->second, mod) % mod;
		//cout << itr->first << " " << itr->second << endl;
	}
	
	ull ans = 0;
	for(uint i=0; i<N; i++) {
		ans = (mod_div(lcmA, (ull)A[i], mod) + ans) % mod;
	}
	
	cout << ans;
	
	return 0;
}

template <typename T> T mod_pow(T n, T r, T m) {
	T ret = 1;
	T tmp = n;
	
	while(r != 0) {
		if(r % 2) {
			ret *= tmp;
		}
		tmp *= tmp;
		tmp %= m;
		ret %= m;
		r /= 2;
	}
	return ret;
}

template <typename T> T mod_inv (T a, T m) {
	return mod_pow(a, m - 2, m);
}

template <typename T> T mod_div (T a, T b, T m) {
	return a * mod_inv(b, m) % m;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int h, w;
    cin >> h >> w;
    vstr s(h + 2, ".");
    rep(i, h)
    {
        string str;
        cin >> str;
        s[i + 1] += str;
        s[i + 1].pb('.');
    }
    rep(i, w + 1)
    {
        s.front().pb('.');
        s.back().pb('.');
    }

    for (int i = 1; i < h + 1; ++i)
    {
        for (int j = 1; j < w + 1; ++j)
        {
            if (s[i][j] == '#')
            {
                if (s[i + 1][j] == '.' &&
                    s[i - 1][j] == '.' &&
                    s[i][j + 1] == '.' &&
                    s[i][j - 1] == '.')
                {
                    No;
                    return;
                }
            }
        }
    }
    Yes;
}

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


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  string s;
  cin >> s;
  int n = s.length();
  int64 ans = 0;
  for (int b = 0; b < 1 << (n - 1); b++) {
    vector<int> ps;
    ps.push_back(0);
    for (int k = 0; k < n - 1; k++) {
      if (b & (1 << k)) {
        ps.push_back(k + 1);
      }
    }
    ps.push_back(n);

    for (int i = 0; i + 1 < ps.size(); i++) {
      string t = s.substr(ps[i], ps[i + 1] - ps[i]);
      ans += stoll(t);
    }
  }
  cout << ans << endl;
}

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

int main() {
    long long n,i;
    scanf("%lld",&n);
    for(i=0;i<40;i++){
        long long a=pow(2,i),b=pow(2,i+1);
        if(n>=a&&n<b){
            //printf("%lld%lld\n",a,b);
            printf("%lld\n",b-1);
            return 0;
        }
    }
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    x,a,b=MI()
    if abs(x-a)<abs(x-b):
        print("A")
    else:
        print("B")

main()


Measured memory_bytes: 38256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;


int main(){
    int N,Y;
    cin>>N>>Y;
    bool b=0;
    int A,B,C;

    rep(i,0,N+1){
        rep(j,0,N-i+1){
            if(Y==i*10000+j*5000+(N-i-j)*1000){
                b=1;
                A=i;B=j;C=N-i-j;
                break;
            }
        }
        if(b)break;
    }
    if(b)cout<<A<<" "<<B<<" "<<C<<endl;
    else cout<<-1<<" "<<-1<<" "<<-1<<endl;

}

Measured memory_bytes: 256
#include <vector>
#include <cassert>

//Monoid
// value_t
// op
// id

template<typename Monoid>
class SegmentTree{
  public:
  using value_t=typename Monoid::value_t;
  using size_t=std::size_t;

  private:
  size_t n,n0;
  std::vector<value_t> dat;

  public:
  SegmentTree(size_t n_):n(n_){
    assert(n_>0);
    n0=1;
    while(n0<n)n0<<=1;
    dat=std::vector<value_t>(2*n0-1,Monoid::id);
  }

  SegmentTree(const std::vector<value_t>& tmp):n(tmp.size()){
    assert(n>0);
    n0=1;
    while(n0<n)n0<<=1;
    dat=std::vector<value_t>(2*n0-1,Monoid::id);
    for(long long i=0;i<n;i++)dat[i+n0-1]=tmp[i];
    for(long long i=n0-2;i>=0;i--)dat[i]=Monoid::op(dat[2*i+1],dat[2*i+2]);
  }

  void update(size_t i,value_t val,bool change){
    assert(0<=i&&i<n);
    std::size_t now=i+n0-1;
    if(change)dat[now]=val;
    else dat[now]=Monoid::op(dat[now],val);

    while(now>0){
      now=(now-1)>>1;
      dat[now]=Monoid::op(dat[2*now+1],dat[2*now+2]);
    }
  }

  value_t fold(size_t a,size_t b){
    assert(0<=a&&a<=b&&b<=n);
    value_t rval=Monoid::id,lval=Monoid::id;
    size_t l=a+n0-1,r=b+n0-1;
    for(;l<r;l>>=1,r>>=1){
      if(!(r&1)){
        r--;
        rval=Monoid::op(dat[r],rval);
      }
      if(!(l&1)){
        lval=Monoid::op(lval,dat[l]);
        l++;
      }
    }

    return Monoid::op(lval,rval);
  }
};

struct Monoid{
  using value_t=long long;
  static constexpr value_t id=0;
  static constexpr value_t op(value_t a,value_t b){
    return a|b;
  }
};

#include <string>
#include <iostream>

using ll=long long;

int main(){
  ll n;
  std::cin>>n;
  std::string s;
  std::cin>>s;
  
  std::vector<ll> tmp(n);
  for(ll i=0;i<n;i++)tmp[i]=(1ll<<(s[i]-'a'));
  
  SegmentTree<Monoid> seg(tmp);
  
  ll q;
  std::cin>>q;
  
  for(ll i=0;i<q;i++){
    ll mode;
    std::cin>>mode;
    if(mode==1){
      ll a;
      char c;
      std::cin>>a>>c;
      seg.update(a-1,1ll<<(c-'a'),true);
    }else{
      ll l,r;
      std::cin>>l>>r;
      ll val=seg.fold(l-1,r);
      ll cnt=0;
      for(ll j=0;j<26;j++)if((val>>j)&1)cnt++;
      std::cout<<cnt<<"\n";
    }
  }
}

Measured memory_bytes: 13060
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int[][] a;
	int n;

	void run(){
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			a=new int[n][n];
			for(int j=0; j<n; j++){
				String s=sc.next();
				for(int i=0; i<n; i++){
					a[j][i]=s.charAt(i)-'0';
				}
			}
			solve();
		}
	}

	void solve(){
		int ans=0;
		for(int j=0; j<n; j++){
			for(int i=0, k=0; i<n; i++)
				ans=Math.max(ans, k=(k+1)*a[j][i]);
			for(int i=0, k=0; i<n; i++)
				ans=Math.max(ans, k=(k+1)*a[i][j]);
			for(int i=0, k=0; j+i<n; i++)
				ans=Math.max(ans, k=(k+1)*a[j+i][i]);
			for(int i=0, k=0; j-i>=0; i++)
				ans=Math.max(ans, k=(k+1)*a[j-i][i]);
			for(int i=0, k=0; j+i<n; i++)
				ans=Math.max(ans, k=(k+1)*a[j+i][n-1-i]);
			for(int i=0, k=0; j-i>=0; i++)
				ans=Math.max(ans, k=(k+1)*a[j-i][n-1-i]);
		}
		println(""+ans);

	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int n, k;
int r, s, p;
int ans[100003];
char A[100003];

int main()
{
	// freopen("input.in", "r", stdin);

	scanf("%d %d\n", &n, &k);
	scanf("%d %d %d\n", &r, &s, &p);
	for(int i = 0; i < n; i++) scanf("%c", &A[i]);

	int res = 0;
	for(int i = 0; i < n; i++)
	{
		if(i < k) 
		{
			res += (A[i] == 'r')? p : (A[i] == 's')? r : s;
			ans[i] = 1;
		}
		else
		{
			if(A[i] == A[i-k] && ans[i-k]) continue;
			res += (A[i] == 'r')? p : (A[i] == 's')? r : s;
			ans[i] = 1;
		}
	}
	printf("%d\n", res);
}

Measured memory_bytes: 768
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int w[n];
	for(int i=0;i<n;i++)
	{
		cin>>w[i];
	}
	int min=200,s;

	for(int i=0;i<n;i++)
	{
		int a=0,b=0
		;
		
		for(int j=0;j<=i;j++)
		{
		a+=w[j];
	}
		for(int j=i+1;j<n;j++)
		{
			b+=w[j];
		}
		if(a>b) s=a-b;
		else s=b-a;
		if(s<min) min=s;
	}
	cout<<min;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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

vector<pii> primefactor(int n){
    vector<pii> ret;
    for(int i = 2; i*i <= n; i++)if(n % i == 0){
        int cnt = 0;
        while(n%i == 0)n /= i, cnt++;
        ret.push_back(pii(i,cnt));
    }
    if(n != 1)ret.push_back(pii(n,1));

    return ret;
}

signed main(void) {
    int a,b;
    cin >> a >> b;
    int g = gcd(a,b);
    vp v = primefactor(g);
    cout << v.size()+1 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N;
		N = stdIn.nextInt();
		int[] x, y;
		x = new int[N];
		y = new int[N];
		for(int i = 0; i < N; i++) {
			x[i] = stdIn.nextInt();
			y[i] = stdIn.nextInt();
		}

		double sum = 0;
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				if(i == j){ continue; }
				double d = distance(x[i], x[j], y[i], y[j]);
				sum += d;
			}
		}
		System.out.println(sum / kaijou(N) * kaijou(N - 1));
	}

	static double distance(int x1, int x2, int y1, int y2) {
		int x, y;
		x = x1 - x2;
		y = y1 - y2;
		x *= x;
		y *= y;
		return Math.sqrt(x + y);
	}

	static int kaijou(int N) {
		int ans = 1;
		while(N > 0){
			ans *= N;
			N--;
		}
		return ans;
	}
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision

typedef long long ll;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

using namespace std;
void omajinai() {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
    //freopen("txt.csv","r",stdin);
}


int main(){
    omajinai();
    int N; cin>>N;
    vector<int> p(N+1);
    for(int i = 1; i<=N;i++) cin>>p[N+1-i];
    vector<ll> a(N+1),b(N+1);
    for(int i = 1 ; i<=N;i++){
        a[i] = i; b[N+1-i] = i;
    }
    for(int j = 1; j<=N;j++){
        int x= p[j];
        for(int i = x; i<=N;i++ ) a[i]+=N+1-j;
        for(int i = x; i>=0;i-- ) b[i]+=N+1-j;
    }
    cout<<a[1];
    for(int i = 2 ; i<=N;i++)cout<<" "<<a[i];
    cout<<endl;
    cout<<b[1];
    for(int i = 2 ; i<=N;i++)cout<<" "<<b[i];
    cout<<endl;
    
    
}

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

#define F first
#define S second
#define ll long long
#define pb push_back
#define endl '\n'

using namespace std;

int main()
{
	ios_base :: sync_with_stdio(false) ;
	cin.tie(0); cout.tie(0) ;
	int a , b , c , k ;
	cin >> a >> b >> c >> k ; 
	if(k <= a + b){
		cout << min(k , a) << endl ; 
		return 0 ; 
	}
	k -= a + b ; 
	cout << a - k << endl ; 
	return 0 ; 
}



Measured memory_bytes: 3652
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int r, s, p;

int point(char c)
{
	if (c == 'r')
		return p;
	if (c == 's')
		return r;
	if (c == 'p')
		return s;
}

int main()
{
	int n, k;
	cin >> n >> k >> r >> s >> p;
	vector<char> c(n, '\0');
	for (int i = 0; i < n; i++)
		cin >> c[i];

	long result = 0;

	for (int i = 0; i < k; i++)
	{
		char bef = '\0';
		for (int j = i; j < n; j += k)
		{
			if (bef != c[j])
			{
				result += point(c[j]);
				bef = c[j];
			}
			else
				bef = '\0';
		}
	}

	printf("%ld", result);

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x *= 10;
        x += ch - '0';
        ch = getchar();
    }
    return x * f;
}

int a[100005];
int main() {
    int n = read(), x = read();
    for (int i = 1; i <= n; ++i) {
        a[i] = read();
    }
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n; ++i) {
        if (x < a[i]) {
            printf("%d", i - 1);
            return 0;
        }
        x -= a[i];
    }
    if (x == 0) printf("%d", n);
    else printf("%d", n - 1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n + 1); i++)
// vector<vector<int>> A(3, vector<int>(4));
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind tree(N);

    for(int i = 0; i < M; i++) {
        int  x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1); // xの木とyの木を併合する
    }

    int cnt=0;
    for(int i=0;i<N;i++){
        if(!tree.same(0,i)){
            tree.unite(0, i);
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3852
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

A,B,C = map(int,input().split())
extra = []

import time

now = time.time()

for i in range(B):
    if i*A % B == C:
        print("YES")
        break

    if i == B-1:
        print("NO")


Measured memory_bytes: 6600
import statistics


N = int(input())
A = list(map(int, input().split()))

A = [a - i for i, a in enumerate(A)]

M = int(statistics.median(A))
R = []

for m in [M-2, M-1, M, M+1, M+2]:
    R.append(sum([abs(a - m) for a in A]))

print(min(R))


Measured memory_bytes: 27240
#include <iostream>
using namespace std;
 
int main(void){
    int n, m;
    cin >> n >> m;
    int l[100000];
    int r[100000];
    int rmin;
    int lmax;
 
    for(int i = 0; i < m; i++){
        cin >> l[i] >> r[i];
    }
    rmin = r[0];
    for(int i = 1; i < m; i++){
        if(rmin > r[i]){
            rmin = r[i];
        }
    }
 
    lmax = l[0];
    for(int i = 1; i < m; i++){
        if(lmax < l[i]){
            lmax = l[i];
        }
    }
    cout << max(rmin - lmax + 1, 0) << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define N 10001000
const int mod=1e9+7;
const int mx=(1<<20)-1;
typedef long long ll;
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],p,ans,s[N],m,dp[N];
vector<int> vec[N];
int main(){
	n=read();
	s[0]=1;
	for(int i=1;i<=n;++i){
		a[i]=read();
		p^=a[i];
		s[i]=s[i-1]+(p==0);
		vec[p].push_back(i);
	}
	for(int u=1;u<=mx;++u){
		if(vec[u].empty())continue;
		if(p&&p^u)continue;
		int sum=0,qwq=0;
		for(int i=0;i<(int)vec[u].size();++i){
			dp[i]=(1LL*sum*s[vec[u][i]]-qwq+mod+1)%mod;
			sum=(sum+dp[i])%mod;
			qwq=(qwq+1LL*dp[i]*s[vec[u][i]])%mod;
		}
		ans=(ans+(p?dp[vec[u].size()-1]:sum))%mod;
	}
	if(!p){
		int tmp=1;
		for(int i=1;i<s[n]-1;++i){
			(tmp<<=1)%=mod;
		}
		ans=(ans+tmp)%mod;
	}
	printf("%d\n",ans);
	return 0;
}




Measured memory_bytes: 251044
def main():
    N = int(input())
    A = list(map(int, input().split()))
    # 単調増加になる区間の両端で売買
    actions = ['' for _ in range(N)]
    left = 0
    for right in range(1, N):
        if A[right - 1] > A[right]:
            if left != right - 1:
                actions[left] = 'buy'
                actions[right - 1] = 'sell'
            left = right
    if left != right:
        actions[left] = 'buy'
        actions[right] = 'sell'
    money = 1000
    stock = 0
    for i, action in enumerate(actions):
        if action == 'buy':
            stock = money // A[i]
            money -= stock * A[i]
        elif action == 'sell':
            money += stock * A[i]
            stock = 0
    print(money)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9148
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s=new Scanner(System.in);
		int sh=s.nextInt();
		int w=s.nextInt();
		
		if(w>=sh)
		{
		    System.out.println("unsafe");
		}
		else
		System.out.println("safe");
	}
}


Measured memory_bytes: 27076
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{
    
    class Program
    {
        public static (long m,long s)[,] dp;

        static void Main(string[] args)
        {
            checked
            {
                var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
                Console.SetOut(sw);

                var vals = Console.ReadLine().Split(' ').
                    Select(x => long.Parse(x)).ToList();
                
                
                var X = vals[0];
                var K = vals[1];
                var D = vals[2];
                

                //L.Sort();

                long ans = X;

                if (Math.Abs(K) >= Math.Abs(X/D))
                {
                    ans = Math.Abs(X);
                    var quo = ans / D;
                    ans = Math.Abs(ans % D - ((K - quo) % 2 * D));
                }
                else
                {
                    ans = Math.Abs(X) - Math.Abs(K * D);
                }
                

                

                Console.WriteLine(ans);

                Console.Out.Flush();
            }




        }
    }
}




Measured memory_bytes: 28124
package main

import (
  "fmt"
)

func abs(a int) int {
  if a > 0 {
    return a
  }
  return -a
}

func main() {
  var N, K int
  fmt.Scan(&N, &K)
  
  h := make([]int, N)
  dp := make([]int, N)

  fmt.Scan(&h[0])
  dp[0] = 0
  for i := 1; i < N; i++ {
    fmt.Scan(&h[i])
    dp[i] = -1
    for j := 1; j <= K && j <= i; j++ {
      p := abs(h[i-j] - h[i]) + dp[i-j]
      if dp[i] > p || dp[i] == -1 {
        dp[i] = p
      }
    }
  }
  fmt.Println(dp[N-1])
}

Measured memory_bytes: 5504
def main():
    D = int(input())
    C = list(map(int, input().split()))
    S = [list(map(int, input().split()))for _ in range(D)]

    types = []
    for i in range(D):
        t = S[i].index(max(S[i])) + 1
        types.append(t)

    for type in types:
        print(type)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,sum=0;
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>j;
        sum+=j;
    }
    if(sum<=n)
    {
        cout<<(n-sum)<<endl;
    }
    else

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

}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int k = sc.nextInt();
      	sc.nextLine();
      
      
      	int cost[] = new int[n];
      	for(int i = 0; i < n; i++)
          cost[i] = sc.nextInt();
      
      
      	int result[] = new int[n];
      	result[0] = 0;

      	for(int i = 1; i < result.length; i++){
          	for(int j = 1; j <= k && (i-j) >= 0; j++){
              	if(j > 1) 
                  minSet(result, i, Math.abs(cost[i] - cost[i-j]) + result[i-j]);   
              	else
                  result[i] = Math.abs(cost[i] - cost[i-j]) + result[i-j];
            }
        }
      
     	System.out.println(result[result.length-1]);
    }
      
   	static void minSet(int[] result, int index, int cost){
      if(result[index] > cost)
        result[index] = cost;
    }
}

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; string S; cin >> N >> S;
  for(auto c:S) {
    char a = c+N;
    if(a > 'Z') a = a - 26;
    cout << a;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(A: int, B: int, N: int):
    # print(A/B)
    # for x in range(1, N+1):
    #     print(x % B, int(A*x/B) - A*int(x/B))

    if B-1 <= N:
        print(int((B-1)*A/B))
    else:
        print(int(N*A/B))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(A, B, N)


if __name__ == '__main__':
    main()


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

long long MOD = 1e9+7;
int MAX_INT = 1e9;

long long H, W;
vector<vector<long long>> cost_map(1000+1, vector<long long>(1000+1, 0));

// 最大公約数
long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
// 最小公倍数
long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}

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

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

  for(int u : island_map[0]) {
    for(int v : island_map[u]) {
      if(v == N-1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }

  cout << "IMPOSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 22912
//	-*- mode: C++ -*-
//	A/B Problem
//		Write a program which reads two integers a and b, and calculates the following values:

//		a ÷ b: d (in integer)
//		remainder of a ÷ b: r (in integer)
//		a ÷ b: f (in real number)
//	Input
//		Two integers a and b are given in a line.

//	Output
//		Print d, r and f separated by a space in a line. For f, the output should not contain an absolute error greater than 10-5.

//	Constraints
//		1 ≤ a, b ≤ 109
//	Sample Input 1
//		3 2
//	Sample Output 1
//		1 1 1.50000

#include <iostream>

int	main(int	argc,
		 char*	argv[])
{
	unsigned int	a	{0};
	unsigned int	b	{0};

	std::cin >> a >> b;

	std::cout << a / b << ' ' << a % b << ' ' << std::fixed << static_cast<double>(a) / static_cast<double>(b) << '\n';
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int N, M; cin >> N >> M;
    int max_n = N+1, min_n = 0;
    int l, r;
    REP(i, M){
        cin >> l >> r;
        min_n = max(min_n, l);
        max_n = min(max_n, r);
    }
    if((max_n-min_n+1) < 0){
        cout << 0 << endl;
    }else{
        cout << (max_n-min_n+1) << endl;
    }
}

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

using namespace std;
using ll = long long;

int main() {
    ll n,a,b = 0;

    cin >> n >> a >> b;

    ll c,d = 0;

    c = n % (a + b);
    d = n / (a + b);

    ll sum = 0;

    sum = d * a + min(c,a);

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll a[2010];

ll dp[2010][2010];
vector<P> vec;

ll calc(int x, int y) {
    if (x + y >= n) return 0;
    if (dp[x][y] < 0) {
        P p = vec[x+y];
        ll res = 0;
        res = calc(x+1, y) + p.first * abs(p.second - x);
        res = max(res, calc(x, y+1) + p.first * abs(p.second - (n-y-1)));
        dp[x][y] = res;
    }
    return dp[x][y];
}

ll solve() {
    for (int i = 0; i < n; i++) {
        vec.push_back(make_pair(a[i], i));
    }
    sort(RALL(vec));
    memset(dp, -1, sizeof(dp));
    return calc(0, 0);
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int n,k;
    cin>>n>>k;
    if(n%k==0){
        cout<<0<<endl;
    }else{
        cout<<1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;

namespace abc163B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            long N = long.Parse(str[0]);
            long M = long.Parse(str[1]);
            long[] a = new long[M];
            long B = 0;
            str = Console.ReadLine().Split();
            for (long i = 0; i < M; i++)
            {
                a[i] = long.Parse(str[i]);
                B = B + a[i];
            }
            if (N - B >= 0)
                Console.WriteLine(N - B);
            else
                Console.WriteLine(-1);
        }
    }
}


Measured memory_bytes: 28492
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=(s);i<(t);++i)
#define per(i,s,t) for(int i=((t)-1);i>=s;--i)
#define repb(i,s,t) for(int i=(s);i<=(t);++i)
#define lepb(i,s,t) for(int i=(s);i>=(t);--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
#define mst(a,b) memset(a,b,sizeof(a))
#define dd(x) cout<<#x<<'='<<x<<' '
#define de(x) cout<<#x<<'='<<x<<'\n'
#define fi first
#define se second
#define sq(x) ((x)*(x))
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int inf = 0x3f3f3f3f;
const ll inff = 4557430888798830399ll;
const db eps = 1e-10;
const db pi = acos(-1.0);
const ll mod = 1e9+7;

char s[100005];

int main()
{
//	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,f;
	scanf("%s",s+1);
	n=strlen(s+1);
	repb(i,1,n-1)if(s[i]!=s[n-i])return !printf("-1\n");
	if(s[1]=='0'||s[n]=='1')return !printf("-1\n");
	f=1;
	repb(i,2,n)
	{
		printf("%d %d\n",f,i);
		if(s[i-1]=='1')f=i;	
	}
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
 
const int N = 2e5 + 9, B = 2001, P = 1e9 + 7;
 
int n, x[N], y[N], f[B << 1][B << 1], ans;
 
int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d%d", &x[i], &y[i]), ++f[B - x[i]][B - y[i]];
	for (int i = 1; i <= 4001; ++i) {
		for (int j = 1; j <= 4001; ++j) {
			f[i][j] = (f[i][j] + f[i - 1][j] + f[i][j - 1]) % P;
		}
	}
	for (int i = 1; i <= n; ++i) ans = (ans + f[B + x[i]][B + y[i]]) % P;
	memset(f, 0, sizeof f);
	for (int i = 0; i <= 4000; ++i) f[0][i] = 1;
	for (int i = 1; i <= 4000; ++i) {
		f[i][0] = 1;
		for (int j = 1; j <= 4000; ++j) {
			f[i][j] = (f[i][j] + f[i - 1][j] + f[i][j - 1]) % P;
		}
	}
	for (int i = 1; i <= n; ++i) ans = (ans - f[x[i] << 1][y[i] << 1]) % P;
	printf("%d\n", 500000004ll * (ans + P) % P);
	return 0;
}

Measured memory_bytes: 64384
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")




int main() {

    ll n,d; cin >> n >> d;
    ll x,y,ans = 0;
    rep(i,n){
        cin >> x >> y;
        if(x*x + y*y <= d*d) ans ++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int N=4005;
int n,dp[N][N],f[N][N],g[N][N],fw[N],fb[N];
struct node
{
    char c;
    int x;
}a[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++)
    {
        scanf(" %c %d",&a[i].c,&a[i].x);
        if(a[i].c=='W') fw[a[i].x]=i;
        else fb[a[i].x]=i;
    }
    for(int i=1;i<=2*n;i++)
    {
        for(int j=0;j<=n;j++)
            f[i][j]=f[i-1][j],g[i][j]=g[i-1][j];
        for(int j=a[i].x-1;j>=0;j--)
            if(a[i].c=='W') f[i][j]++;
        else g[i][j]++;
    }
    memset(dp,inf,sizeof(dp));
    dp[0][0]=0;
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
    {
        if(i+1<=n)
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]+f[fw[i+1]][i]+g[fw[i+1]][j]-1);
        if(j+1<=n)
            dp[i][j+1]=min(dp[i][j+1],dp[i][j]+f[fb[j+1]][i]+g[fb[j+1]][j]-1);
    }
    printf("%d\n",dp[n][n]);
}


Measured memory_bytes: 187904
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

int main() {
    int N;
    while(cin >> N, N){
        vector<pii> sq(N);
        sq[0] = mp(0,0);
        int mx = 0, Mx = 0, my = 0, My = 0;
        repi(i,1,N){
            int n, d;
            cin >> n >> d;
            int nx = sq[n].first+dx[d];
            int ny = sq[n].second+dy[d];
            mx = min(mx, nx); Mx = max(Mx, nx);
            my = min(my, ny); My = max(My, ny);
            sq[i] = mp(nx, ny);
        }
        cout << Mx - mx + 1 << ' ' << My - my + 1<< endl;
    }
    return 0;
}

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

int main() {
	int w, h, n;
	cin >> w >> h >> n;
	int x1 = 0, x2 = w, y3 = 0, y4 = h;
	for (int i = 0; i < n; i++) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1) {
			if (x1 < x)x1 = x;
		} else if (a == 2) {
			if (x < x2)x2 = x;
		} else if (a == 3) {
			if (y3 < y)y3 = y;
		} else {
			if (y < y4)y4 = y;
		}
	}
	if (x2 - x1 > 0 && y4 - y3 > 0) {
		cout << (x2 - x1) * (y4 - y3) << endl;
	} else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
 
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
 
#define INF 87654321
#define IINF 87654321987654321
#define MOD 1000000007

typedef pair<int, long> Pil;

struct SegmentTree {
	int n;
	vector<ll> sum, mx;
	void init(int sz) {
		n = 1;
		while(n < sz) n <<= 1;
		sum.assign(2*n, 0);
		mx.assign(2*n, 0);
	}

	void add(int p, ll val) {
		if(p <= 0 || p > n) return;
		p += n-1;
		sum[p] += val;
		mx[p] = sum[p];
		for(p >>= 1; p; p >>= 1) {
			sum[p] = sum[2*p] + sum[2*p+1];
			mx[p] = max(mx[2*p], sum[2*p] + mx[2*p+1]);
		}
	}

	ll maxSum(int p) {
		if(p <= 0) return 0;
		vector<int> vi;
		for(p += n-1; p; p >>= 1) {
			if(!(p&1)) {
				vi.push_back(p);
				p--;
			}
		}
		reverse(vi.begin(), vi.end());
		ll curSum = 0, mxSum = 0;
		for(int i : vi) {
			mxSum = max(curSum + mx[i], mxSum);
			curSum += sum[i];
		}
		return mxSum;
	}
} tree;


const int MAXN = 2e5 + 50;
int l[MAXN], r[MAXN], n, m;
ll a[MAXN];
vector<Pil> adj[MAXN], rev[MAXN];
void readInput() {
	scanf("%d%d", &n, &m);
	repp(i, m) scanf("%d%d%lld", &l[i], &r[i], &a[i]);
	repp(i, m) {
		adj[l[i]].emplace_back(r[i], a[i]);
		rev[r[i]].emplace_back(l[i], a[i]);
	}
}

void solve() {
	tree.init(n);
	ll res = 0, cur = 0;
	for(int k = 1; k <= n; k++) {
		for(auto e : adj[k]) {
			cur += e.second;
			tree.add(k, -e.second);
			tree.add(e.first+1, e.second);
		}
		ll val = tree.maxSum(k-1) + cur;
		//printf("%d: %lld %lld\n", k, val, cur);
		res = max(res, val);
		tree.add(k, val);
		tree.add(k+1, -val);
		for(auto e : rev[k]) {
			cur -= e.second;
			tree.add(e.first, e.second);
			tree.add(k+1, -e.second);
		}
	}
	printf("%lld\n", res);
}


int main() {
	readInput();
	solve();
}

Measured memory_bytes: 33408
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
 
using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m,v,p;
  cin>>n>>m>>v>>p;
  vecll a(n);
  for(auto&& e:a)cin>>e;
  boost::sort(a, greater<ll>());
  ll ans = p;
  ll sum = m;
  for(auto&& i:irange(p, n)) {
    if (a[p-1] - a[i] > m) break;
    ll remv = v-p-(n-i)+1;
    ll remn = i-p+1;
    ll diff = a[i-1] - a[i];
    sum -= remn * diff;
    ll oldsum = sum;
    sum += m;
    //cerr<<i<<' '<<oldsum<<' '<<remv<<endl;
    if (remv <= 0) {
      ++ans;
      continue;
    }
    if (oldsum / m < remv) break;
    ++ans;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
from heapq import heappush, heappop, heapify

n, k = map(int, input().split())
a = list(map(int, input().split()))


def check(x):
    # 最長の丸太をx以下にできるか
    # 任意の丸太をx以下にできるか
    cnt = 0
    for ai in a:
        if ai > x:
            if ai % x == 0:
                cnt += ai // x - 1
            else:
                cnt += ai // x
    # print('check', x, cnt)
    return cnt <= k


lb = 0  # False
ub = max(a)  # True
while ub - lb > 1:
    mid = (ub + lb) // 2
    # print(mid, check(mid))
    if check(mid):
        ub = mid
    else:
        lb = mid

print(ub)


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


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

	rep(i, n) b[i] = 0;

	rep(i, n) {
		b[a[i]-1] = i;
	}

	rep(i, n) {
		cout << b[i]+1 << " ";
	}

	cout << endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vi l(k), r(k);
  rep(i,k) cin >> l[i] >> r[i];
  vector<mint> dp(n+1), sum(n+1);
  dp[1] = 1;
  sum[1] = dp[1];
  for(int i=2; i<=n; i++){
    rep(j,k){
      if(i - r[j] -1 >= 0 && i - l[j] >= 0) {
        dp[i] += sum[i - l[j]] - sum[i - r[j] -1];
        //cout << i - r[j] << i - l[j] - 1 << " ";
      }
      else if(i - l[j] >= 0) dp[i] += sum[i - l[j]];
    }
    sum[i] = sum[i-1] + dp[i];
  }
  cout << dp[n] << endl;
  //rep(i,n+1) cout << dp[i] << endl;
}


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

int main() {
    int x, n;
    cin >> x >> n;
    vector<int> p(102, 0);
    rep(i, n) {
        int x;
        cin >> x;
        p[x] = 1;
    }

    int minError = 1e5;
    int ans = 0;
    rep(i, 102) {
        if (p[i] == 1) continue;

        int e = abs(i - x);
        if (e < minError) {
            ans = i;
            minError = e;
        }
    }

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


Measured memory_bytes: 3636