akhauriyash/Code-Regression huggingface dataset:
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
'''
p = 10 ** 9 + 7
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
'''


#a = list(map(int, input().split()))

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

j = min(n-1,k)

p = 10 ** 9 + 7
N = 10 ** 5 * 5
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans = 1

for ii in range(j):
    i = ii+1
    ans += cmb(n,i,p)*cmb(n-1,i,p)
    ans %= p

print(ans)








































Measured memory_bytes: 120296
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
typedef long long ll;
typedef unsigned long long ull;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()ss		
#define debug system("pause")				//デバッグ用

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

	int a,p;
    cin>>a>>p;
    int pi=0;
    
    p+=a*3;
    pi=p/2;
    cout<<pi<<endl;
    
    
}

Measured memory_bytes: 256
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    *s, = map(lambda x: x.count("1"), zip(*a))
    for i, _s in enumerate(s):
        ans += _s * (n - _s) * pow(2, 59 - i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 72940
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int i,n,m,k;cin>>n>>m>>k;
  vector<long long> a(n),b(m);
  for(i=0; i<n; ++i){ cin>>a[i]; a[i]+=(i>0? a[i-1]:0);}
  for(i=0; i<m; ++i){ cin>>b[i]; b[i]+=(i>0? b[i-1]:0);}
  int cnt,res=0;
  int disa=upper_bound(a.begin(),a.end(),k)-a.begin();
  int disb=upper_bound(b.begin(),b.end(),k)-b.begin();
  if(disa>disb) while(disa--){ cnt=1+disa+(upper_bound(b.begin(),b.end(),k-a[disa])-b.begin()); res=max(res,cnt);}
  else while(disb--){ cnt=1+disb+(upper_bound(a.begin(),a.end(),k-b[disb])-a.begin()); res=max(res,cnt);}
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 6428
def main():
  mod = 10**9 + 7
  n, k = map(int, input().split(' '))
  A = list(range(n+1))
  A_rev = A[::-1]
  cumsum_A = [0]
  cumsum_A_rev = [0]
  for i in range(len(A)):
    cumsum_A.append(A[i]+cumsum_A[i])
    cumsum_A_rev.append(A_rev[i]+cumsum_A_rev[i])
  ans = 0
  
  for i in range(k, n+2):
    tmp_min = cumsum_A[i]
    tmp_max = cumsum_A_rev[i]
    ans += (tmp_max - tmp_min + 1)
  print(ans%mod)
    

if __name__ == '__main__':
  main()

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

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

int main()
{
  int N;
  cin >> N;
  int i;
  rep(i, 9)
  {
    int j;
    rep(j, 9)
    {
      if ((i + 1) * (j + 1) == N)
      {
        cout << "Yes";
        return 0;
      }
    }
  }

  cout << "No";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>

using namespace std;

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << max(0, min(B, D) - max(A, C)) << endl;
  return 0;
}


Measured memory_bytes: 256
"use strict"

const Main= input =>{
  input=input.split(" ")
  const a =input[0]
  const b = input[1]
  const c =a*b
if(c%2==1){
  console.log("Odd")
} else{
  console.log("Even")
}
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
class Array
  def rank
    self.map { |v| self.count { |a| a < v } + 1 }
  end
end

while true
  w, h = gets.split.map(&:to_i)
  break if w == 0
  xa = {}; ya = {}
  xa[0] = 0; xa[w] = 0
  ya[0] = 0; ya[h] = 0
  points = []
  gets.to_i.times do
    p = gets.split.map(&:to_i)
    points << p
    xa[p[0]] ||= 0; xa[p[2]] ||= 0
    ya[p[1]] ||= 0; ya[p[3]] ||= 0
  end
  xa.keys.rank.zip(xa.keys).each{ |r, x| xa[x] = r }
  ya.keys.rank.zip(ya.keys).each{ |r, y| ya[y] = r }
  xs = xa.size; ys = ya.size
  fld = Array.new(ys+1){ Array.new(xs+1, true) }
  fld[0].fill(false); fld[ys].fill(false)
  fld.map{ |arr| arr[0] = arr[xs] = false }
  for p in points
    x1, y1, x2, y2 = p
    for y in (ya[y1]...ya[y2])
      for x in (xa[x1]...xa[x2])
        fld[y][x] = false
      end
    end
  end
  ret = 0
  for y in (1...ys)
    for x in (1...xs)
      next unless fld[y][x]
      arr = []
      arr << [y, x]
      until arr.empty?
        ny, nx = arr.shift
        [[-1,0],[0,-1],[1,0],[0,1]].each do |dy, dx|
          px = nx+dx; py = ny+dy
          if fld[py][px]
            arr << [py, px] 
            fld[py][px] = false
          end
        end
      end
      ret += 1
    end
  end
  p ret
end

Measured memory_bytes: 14284
#include<stdio.h>
int main()
{
	long long int n , i, j;
	scanf("%lld", &n);
	long long int A[n], count=1;
	for(i=0; i<n; i++)
		scanf("%lld", &A[i]);
	if(n==1){
		printf("1\n");
		return 0;
	}
	long long int min=A[0];
	for(i=1; i<n; i++){
		if(A[i]<=min){	
			min=A[i];
			count++;
		}
	}
	printf("%lld\n",count);
	return 0;
}


Measured memory_bytes: 1664
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        p: [usize1; n],
    }
    let mut a = vec![];
    let mut b = vec![];
    for i in 1..(n + 1) {
        a.push(i * 20001);
        b.push(i * 20001);
    }
    b.reverse();
    for i in 0..n {
        a[p[i]] += i;
        b[p[i]] += i;
    }
    for i in 1..n {
        assert!(a[i - 1] < a[i]);
        assert!(b[i - 1] > b[i]);
        let x = p[i - 1];
        let y = p[i];
        assert!(a[x] + b[x] < a[y] + b[y]);
    }
    let mut out = String::new();
    for a in a {
        out.push_str(&format!("{} ", a));
    }
    out.pop();
    out.push('\n');
    for b in b {
        out.push_str(&format!("{} ", b));
    }
    out.pop();
    println!("{}", out);
}

fn main() {
    run();
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    ll n, m; cin >> n >> m;
    V<ll> a(n);
    priority_queue<P<ll ,ll> > q;
    for(int i = 0; i < n; i++){
        ll a; cin >> a;
        q.push(make_pair(a, 1));
    }
    for(int i = 0; i < m; i++){
        ll b, c; cin >> b >> c;
        q.push(make_pair(c, b));
    }

    ll ans = 0;
    for(int i = 0; i < n; i++){
        auto p = q.top();
        q.pop();
        ans += p.first;
        if(p.second > 1){
            p.second--;
            q.push(p);
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 6896
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long mod = 1000000007;
const long long MOD = 998244353;

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

	int n;
	string s;
	cin >> n >> s;

	ll abc[26] = { 0 };
	rep(i, n) ++abc[s[i] - 'a'];

	ll ans = 1;
	rep(i, 26) {
		ans *= abc[i] + 1;
		ans %= mod;
	}

	cout << ans - 1 << "\n";

	return 0; 
}


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

int T, N, K, X[100000 + 10], A[100000 + 10];
int main()
{
	cin >> T;
	for(int t = 0; t < T; ++t)  //この末尾に;をつけてたせいでデータセット1個しか読み込まれずエラーになってた悲しい
	{		
		cin >> N >> K;
		for (int i = 0; i < N; ++i)
			cin >> X[i];
		if (N > 1)
		{
			for (int i = 0; i < (N-1); ++i)A[i] = X[i + 1] - X[i];//テキストにあったように"int i = 0; i + 1 < N; ++i"とするとエラー吐く
		
			sort(&A[0], &A[N - 1]);
			
		}
			if (N > K)
			{
				int M = N - K;
				int sum = 0;
				for (int i = 0; i < M; ++i) sum += A[i];
				cout << sum << endl;
			}
			else cout << 0 << endl;
	}
}


Measured memory_bytes: 3880
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;

//#define DEBUG_MODE
//#define FILE_INPUT

void DebugPrint(int a[], int n)
{
#ifdef	DEBUG_MODE
	for (int i = 0; i < n; ++i) {
		cout << a[i] << " ";
	}
	cout << endl;
#endif
}

int gcd(int a, int b)
{
  if (a < b) {
	swap(a, b);
  }
  if (b == -1) {
	  return a;
  }
  int c = a % b;
  if (c == 0) {
    return b;
  }
  else {
    return gcd(b, c);
  }
}
int multi_gcd(int n, int *a) 
{
  int gcd_val = gcd(a[0], a[1]);
  for (int i = 2; i < n; ++i) {
    gcd_val = gcd(gcd_val, a[i]);
  }
  return gcd_val;
}

int main()
{
#ifdef FILE_INPUT
	ifstream in("test2.txt");
	cin.rdbuf(in.rdbuf());
#endif	/* FILE_INPUT */

  unsigned int n;
  cin >> n;
  unsigned int m = 1;
  for (;; ++m) {
	  if ((1U << m) >= n) {
		  break;
	  }
  }
  unsigned int nn = 1 << m;
  int **a = new int*[m];
  for (unsigned int i = 0; i < m; ++i) {
	  a[i] = new int[nn];
  }
  for (unsigned int i = 0; i < nn; ++i) {
	  if (i < n) {
	    cin >> a[0][i];
	  }
	  else {
		a[0][i] = -1;
	  }
  }
  DebugPrint(a[0], nn);
  unsigned int step = 1;
  for (unsigned int i = 1; i < m; ++i) {
	  for (unsigned int j = 0; j < nn; j += 2 * step) {
		  int value = gcd(a[i - 1][j], a[i - 1][j + step]);
		  for (unsigned int k = 0; k < 2 * step; ++k) {
			  a[i][j + k] = value;
		  }
	  }
	  step *= 2;
	  DebugPrint(a[i], nn);
  }
  int *b = new int[nn];
  for (unsigned int i = 0; i < nn; ++i) {
	  b[i] = a[0][i ^ 1];
  }
  DebugPrint(b, nn);
  step = 2;
  for (unsigned int i = 1; i < m; ++i) {
	  for (unsigned int j = 0; j < nn; ++j) {
		  b[j] = gcd(b[j], a[i][j ^ step]);
	  }
	  step *= 2;
	  DebugPrint(b, nn);
  }


  int max = 0;
  for (unsigned int i = 0; i < nn; ++i) {
	  if (b[i] > max) {
		  max = b[i];
	  }
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 9472
from math import factorial as fa

n,m = map(int,input().split())
if n == m:
    a = n 
    b = m
else:
    a = max(n,m)
    b = min(n,m)

    
cn = 10**9 + 7

if  a-b > 1:
    print(0)
elif a - b == 1:
    print(fa(a)*fa(b) % cn)
else:
    print(fa(a)*fa(b)*2 % cn)
    

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll r;
  cin >> r;

  cout << 3*r*r << endl;

  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){ 
for (int k = 0; k < 114514; ++k){
int H, W; 
cin >> H >> W; 
  if(H == 0 && W == 0){
   break; 
  }
for (int i = 0; i < H; ++i) {
  for (int j = 0; j < W; ++j) { 
    cout << "#"; 
   }
  cout << endl; 
  }
 cout << endl; 
}
}


Measured memory_bytes: 3128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.parseInt(line);

		int i = 1;

		while (i <= n) {
			String I = String.valueOf(i);
			if (I.matches(".*3.*")) {
				System.out.print(" " + i);
			}

			else if (i % 3 == 0) {
				System.out.print(" " + i);

			} else if (i % 10 == 3) {
				System.out.print(" " + i);

			}
			i++;
		}
		System.out.println("");
	}

}

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

int c[501];
int s[501];
int f[501];

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

    for(int i=0; i < n-1; i++) cin >> c[i] >> s[i] >> f[i];

    for(int j=0; j < n-1; j++){
        int t = 0;
        for(int i=j; i < n-1; i++){
            while(1){
                if(s[i] <= t and (s[i] - t) % f[i] == 0){
                    t += c[i];
                    break;
                }
                t += 1;
            }
        }
        cout << t << endl;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define rollcall cout<<"I'm Sucu."<<endl
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll

const int MAX_V = 1000;
struct edge{int end,cap,rev;};
vector<edge> G[MAX_V];
bool accessed[MAX_V]={};
int V;

void Ford_add_edge(int from,int end,int cap){
    G[from].push_back((edge){end,cap,(int)G[end].size()});
    G[end].push_back((edge){from,0,(int)G[from].size()-1});
}

int Ford_dfs(int v,int t,int f){
    if(v==t)return f;
    accessed[v]=true;
    for(int i=0;i<G[v].size();i++){
        edge &e = G[v][i];
        if(!accessed[e.end]&&e.cap>0){
            int d = Ford_dfs(e.end,t,min(f,e.cap));
            if(d>0){
                e.cap -= d;
                G[e.end][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

int FordFulkerson(int s,int t){
    int flow=0;
    while(1){
        memset(accessed,0,sizeof(accessed));
        int f = Ford_dfs(s,t,INF);
        if(f==0) return flow;
        flow+=f;
    }
}

signed main(void){
    int N,Ans;
    int a[100],b[100],c[100],d[100];
    cin >> N;
    REP(i,N){
        cin >> a[i] >> b[i];
    }
    REP(i,N){
        cin >> c[i] >> d[i];
    }
    //ソースは500,シンクは501
    REP(i,N){
        Ford_add_edge(500,i,1);
    }
    REP(i,N){
        REP(j,N){
            if(a[i]<c[j]&&b[i]<d[j]){
                Ford_add_edge(i,j+N,1);
            }
        }
    }
    REP(j,N){
        Ford_add_edge(j+N,501,1);
    }
    
    Ans=FordFulkerson(500,501);
    
    cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 512
import bisect
A,B,Q=map(int,input().split())
s=[]
t=[]
for i in range(A):
  s.append(int(input()))
for i in range(B):
  t.append(int(input()))
for i in range(Q):
  x=int(input())
  j=bisect.bisect_left(s,x)
  if j==0:
    kouhoA=[s[j]]
  elif j==A:
    kouhoA=[s[j-1]]
  else:
    kouhoA=[s[j],s[j-1]]
  k=bisect.bisect_left(t,x)
  if k==0:
    kouhoB=[t[k]]
  elif k==B:
    kouhoB=[t[k-1]]
  else:
    kouhoB=[t[k],t[k-1]]
  if len(kouhoA)==1:
    
    if len(kouhoB)==1:
      a=abs(kouhoA[0]-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,abs(x-kouhoB[0])+a])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      ans=min([u+a,abs(x-kouhoB[0])+a,u+b,abs(x-kouhoB[1])+b])
  else:
    if len(kouhoB)==1:
      a=abs(kouhoA[0]-kouhoB[0])
      c=abs(kouhoB[0]-kouhoA[1])
      v=abs(x-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,v+a,abs(x-kouhoA[1])+c,v+c])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      c=abs(kouhoB[0]-kouhoA[1])
      d=abs(kouhoA[1]-kouhoB[1])
      v=abs(x-kouhoB[0])
      w=abs(x-kouhoA[1])
      y=abs(x-kouhoB[1])
      ans=min([u+a,v+a,w+d,y+d,w+c,v+c,u+b,y+b])
  print(ans)


Measured memory_bytes: 12112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> l(n), r(n);
    rep(i,0,n) cin >> l[i] >> r[i];
    int j=0, k=0;
    rep(i,1,n) {
        if(l[i]>l[j]) j = i;
        if(r[i]<r[k]) k = i;
    }
    ll left = max(l[j], l[k]), right = min(r[j],r[k]);
    ll widest = 0;
    rep(i,0,n) widest=max(widest,r[i]-l[i]+1);
    ll ans = max(0LL,right-left+1)+widest;
    if(j!=k) {
        vector<pair<ll,ll>> v;
        rep(i,0,n) if(i!=j && i!=k) {
            v.emplace_back(max(0LL,r[k]-l[i]+1),max(0LL,r[i]-l[j]+1));
        }
        sort(all(v));
        ll ba = r[k]-l[k]+1, bb = r[j]-l[j]+1;
        ll best=0;
        rep(i,0,n-1) {
            ll a = ba;
            if(i<n-2) a = min(a, v[i].first);
            if(i-1>=0) bb = min(bb, v[i-1].second);
            best=max(best,a+bb);
        }
        ans = max(ans,best);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3956
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
void inline swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void inline swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

bool col[8];
int n;
int m = 0;

void init()
{
	memset(col, false, sizeof col);
	cin >> n;

	REP(i, n)
	{
		int a; cin >> a;

		if (a < 3200)
			col[a / 400] = true;
		else
			++m;
	}
}

int main()
{
	init();

	int ans = 0;
	REP(i, 8)
		if (col[i])
			++ans;

	if (!ans)
		cout << 1 << " " <<  m << endl;
	else
		cout << ans << " "  << ans + m << endl;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int a, b;
  cin >> a;
  cin >> b;
  if (a < b) { cout << "a < b" << endl; }
  else if ( a > b) { cout << "a > b" << endl; }
  else { cout << "a == b" << endl; }
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  int N;
  cin>>N;
  vector<ll> a(N),rxor(N+1,0),rsum(N+1,0);
  ll ans=0;
  for(int i=0;i<N;i++){
    cin>>a[i];
    rxor[i+1]=rxor[i]^a[i];
    rsum[i+1]=rsum[i]+a[i];
  }
  int left=0,right=1;
  while(left<N){
    ans+=right-left-1;
    while((rxor[left]^rxor[right])==(rsum[right]-rsum[left])){
      ans++;
      if(right==N) break;
      right++;
    }
    left++;
  }
  cout<<ans<<endl;
  return 0;
}



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

int main() {
  int N;
  string S;
  int ans = 0;
  
  cin >> N >> S;
  
  if(N<3){
    cout << ans << endl;
  }else{
    for(int i=0;i<N-2;i++){
    if(S.at(i)=='A' && S.at(i+1)=='B'&& S.at(i+2)=='C'){
      ans++;
    }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int[] abc=new int[3];
		for(int i = 0; i<s.length(); i++){
			if(s.charAt(i)=='a'){
				abc[0]++;
			}else if(s.charAt(i)=='b'){
				abc[1]++;
			}else{
				abc[2]++;
			}
		}
		int ans=Math.max(Math.max(Math.abs(abc[0]-abc[1]),Math.abs(abc[0]-abc[2])),Math.abs(abc[1]-abc[2]));
		if(ans<2){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 25196
#include <cstdio>

int main (){
    int N;
    scanf("%d",&N);
    long long int a[N+1];
    for (int i = 0; i < N+1; i++){
        scanf("%lld",&a[i]);
    }
    long long int b[N];
    for (int i = 0; i < N; i++){
        scanf("%lld",&b[i]);
    }
    long long int bonus=0;
    long long int count=0;
    for (int i = 0; i < N; i++){
        if(a[i]>=b[i]+bonus){
            count+=b[i]+bonus;
            bonus=0;
        }
        else if(a[i]<=bonus){
            count+=a[i];
            bonus=b[i];
        }
        else{
            count+=a[i];
            bonus+=b[i]-a[i];
        }
    }
    if(a[N]>bonus) count+=bonus;
    else count+=a[N];
    printf("%lld",count);
}


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

int main(){
  int r, d, x;
  cin >> r >> d >> x;
  
  int a[11];
  a[0]=x;
  for(int i=0; i<10; i++){
  	a[i+1]=r*a[i]-d;
    cout << a[i+1] << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#ifdef local
	#include "debug/debug.h"
#endif


#ifndef local
	#define deb(x...) ;	
#endif

#define int long long  
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define vvi vector <vi>
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define M_PI 3.14159265358979323846 

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
///*X.find_by_order("index")
///X.order_of_key("key")

///----------------------------------------------------------------------------------

void solve()
{
	string s;
	cin >> s;
	if (s == "RRR") cout << "3\n";
	else if (s == "RRS" || s == "SRR") cout << "2\n";
	else if (s == "SSS") cout << "0\n";
	else cout << "1\n";
}
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	
	#ifdef local
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	clock_t TIMER = clock();
	#endif
	
	int t = 1;
	//cin >> t;
	rep(a,0,t)
	{
		//cout<<"Case #"<<a+1<<": ";
		solve();
		#ifdef local
		cout << "\n";
		#endif

	}
	
	#ifdef local
	{TIMER = clock() - TIMER;double time_taken = ((double)TIMER)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ld long double
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
// const ll INF = 1LL << 30;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////


int main() {
    ll d, g; cin >> d >> g;
    Vl p(d), c(d);
    rep(i, 0, d) cin >> p[i] >> c[i];
    ll ans = INF;
    for(int tmp = 0; tmp < (1 << d); tmp++){
        bitset<12> s(tmp);
        vector<bool> f(d, false);
        ll sum = 0;
        ll cnt = 0;
        rep(i, 0, 10){
            if(s.test(i)){
                f[i] = true;
                sum += p[i]*(i+1)*100 + c[i];
                cnt += p[i];
            }
        }
        if(sum >= g){
            chmin(ans, cnt);
            continue;
        }
        for(int i = d-1; i >= 0; i--){
            if(f[i]) continue;
            bool h = false;
            rep(j, 0, p[i]){
                sum += (i+1)*100;
                cnt ++;
                if(sum >= g){ 
                    h = true; 
                    chmin(ans, cnt);
                    break;
                }
            }
            if(h) break;
        }
    }
    co(ans);

    return 0;
}



Measured memory_bytes: 3624
n = int(input())
l = list(map(int, input().split()))
q = int(input())
for i in range(q):
    a = input().split()
    b = int(a[1])
    c = int(a[2])
    if a[0] == "0":
        print(min(l[b:c]))
    else:
        print(max(l[b:c]))


Measured memory_bytes: 5628
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<bool>> graph(N, vector<bool>(N));
    Rep(i, M) {
        int a, b;
        cin >> a >> b;
        graph[a - 1][b - 1] = graph[b - 1][a - 1] = true;
    }
    vector<int> perm(N - 1);
    Rep(i, N - 1) perm[i] = i + 1;
    int ans = 0;
    do {
        int v = 0;
        bool flag = true;
        Rep(i, N - 1) {
            if (graph[v][perm[i]]) {
                v = perm[i];
            }
            else {
                flag = false;
                break;
            }
        }
        if (flag) ans++;
    } while (Next_permutation(perm));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3576
n, m = map(int, input().split())
xyz = [list(map(int, input().split())) for _ in range(n)]
if m==0:
    print(0)
    exit()
t = [[0] * n for _ in range(4)]
i = 0
for x, y, z in xyz:
    t[0][i] = x + y + z
    t[1][i] = -x + y + z
    t[2][i] = x - y + z
    t[3][i] = x + y - z
    i += 1
ans = 0
for tk in t:
    tk.sort()
    ans = max(ans, -sum(tk[:m]),sum(tk[-m:]))
print(ans)


Measured memory_bytes: 3444
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    int check[60000] = {0};

    int flg = 0;
    for(int i = 3;i <= 60000; i+=2){
        flg = 1;
        for(int j = 2;j*j <= i; j++){
            if(i%j == 0){
                flg = 0;
                break;
            }
        }
        if(flg == 1)check[i] = 1;
    }
    check[2] = 1;

    int n;
    while(scanf("%d",&n) != EOF){
        for(int i = n-1;i > 0;i--){
            if(check[i] == 1){
                printf("%d ",i);
                break;
            }
        }
        for(int i = n+1;i <= 60000;i++){
            if(check[i] == 1){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1428
#include<algorithm>
#include<iostream>
#include<complex>
#include<vector>
using namespace std;
#define x second
#define y first
#define M st.size()
typedef complex<double> point;
pair<int,int> a[100000];
vector<int> st;
bool ccw(point a,point b,point c){
  b-=a,c-=a;
  c*=conj(b);
  if(c.imag()<=0)return true;  
  return false;
}

void check(int i){
  while(M>=2){
    int s=st[M-2];
    int e=st[M-1];
    point S=point(a[s].x,a[s].y);
    point E=point(a[e].x,a[e].y);
    point N=point(a[i].x,a[i].y);
    if(ccw(S,E,N))break;
    st.pop_back();
  }
  st.push_back(i);
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i].x>>a[i].y;
  sort(a,a+n);
  for(int i=0;i<n;i++)check(i);
  for(int i=n-2;i>=0;i--)check(i);
  cout<<M-1<<endl;
  for(int i=M-1;i>0;i--)cout<<a[st[i]].x<<' '<<a[st[i]].y<<endl;
  return 0;
}

Measured memory_bytes: 2460
#include <cstdio> #include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    ll n, p, ans = 1;
    scanf("%lld%lld", &n, &p);
    for(ll i = 2; i * i <= p; i++) if(p % i == 0) {
        int cnt = 0;
        while(p % i == 0) p /= i, cnt++;
        cnt /= n;
        while(cnt--) ans *= i;
    }
    if(n == 1 && p) ans *= p;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
A=list(input())
from collections import deque
que=deque()
for i in A:
   if i=="T":
      if que==deque():
         que.append("T")
      elif que[-1]=="T":
         que.append("T")
      else:
         que.pop()
   else:
      que.append("S")
print(len(que))

Measured memory_bytes: 6436
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Prelude hiding (readLn)

main :: IO ()
main = readLine >>= main'
    where
        main' [n, k] = replicateM n readLn >>= print . solve k . sort

solve :: Int -> [Int] -> Int
solve k hs = minimum . map mf . zip hs $ drop (k - 1) hs
    where
        mf (hmin, hmax) = hmax - hmin

readLn :: IO Int
readLn = head <$> readLine

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 30972
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char map[100][101];
    int x,y,i,j;
    char ch;
    scanf("%d %d",&y,&x);
    for(i=0;i<y;i++)
    {
        scanf("%s",map[i]);
    }
    
    for(i=0;i<x;i++)
    {
        for(j=0;j<y;j++)
        {
            if(map[j][i]=='#')    continue;
            else
            {
                int num=0;
                if(j!=0)
                {
                    if(map[j-1][i]=='#')    num++;
                }
                if(j!=y-1)
                {
                    if(map[j+1][i]=='#')    num++;
                }
                if(i!=0)
                {
                    if(map[j][i-1]=='#')    num++;
                }
                if(i!=x-1)
                {
                    if(map[j][i+1]=='#')    num++;
                }
                if((j!=0)&&(i!=0))
                {
                    if(map[j-1][i-1]=='#')    num++;
                }
                if((j!=y-1)&&(i!=0))
                {
                    if(map[j+1][i-1]=='#')    num++;
                }
                if((j!=0)&&(i!=x-1))
                {
                    if(map[j-1][i+1]=='#')    num++;
                }
                if((j!=y-1)&&(i!=x-1))
                {
                    if(map[j+1][i+1]=='#')    num++;
                }
                map[j][i]='0'+num;
            }
        }
    }
    
    for(i=0;i<y;i++)
    {
        printf("%s\n",map[i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int a[4][n + 2];
    rep(i, 4) a[i][0] = i % 2, a[i][1] = i / 2;

    rep(index, 4) {

        rep(si, n) {
            int ai = si + 1;
            if (s[si] == 'o' ^ a[index][ai] == 1) {
                a[index][ai + 1] = a[index][ai - 1];
            } else {
                a[index][ai + 1] = !a[index][ai - 1];
            }
        }
        if (a[index][0] == a[index][n] && a[index][1] == a[index][n + 1]) {
            for (int i = 1; i <= n; ++i) cout << (a[index][i] == 0 ? "S" : "W");
            cout << endl;
            return 0;
        }

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


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

int main() {
  int N, K;
  int INF=1000000000;
  cin >> N >> K;
  vector<int> h(N);
  vector<int> d(N);
  
  for (int i=0; i<N; i++) {
    cin >> h.at(i);
  }
  
  
  for (int i=0; i<N; i++) {
    d.at(i)=INF;
  }
  
  d.at(0)=0;
  
  for (int i=1; i<N; i++) {
    d.at(i)=min(d.at(i), d.at(i-1)+abs(h.at(i)-h.at(i-1)));
    for (int k=2; k<K+1; k++) {
      if (i>=k) {
        d.at(i)=min(d.at(i), d.at(i-k)+abs(h.at(i)-h.at(i-k)));
      }
    }
  }
  
  cout << d.at(N-1) << endl;
  
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
typedef unsigned long long ull;
#define vvi std::vector<std::vector<int> >
#define vvu std::vector<std::vector<ull> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;
int main(int argc, char const *argv[]) {
  int N;
  ull B = 10000007;
  ll ans = 0;
  string s, S, t, T="";
  std::cin >> N;
  std::cin >> s;
  S = s.substr(0, N);
  t = s.substr(N);
  for(int i=0;i<N;i++) T+=t[N-1-i];
  std::vector<int> num(26, 0);
  for(int i=0;i<N;i++) num[S[i]-'a']++, num[T[i]-'a']--;
  bool flag = true;
  for(int i=0;i<26;i++) if(num[i]!=0) flag = false;
  vvu hash = vv(0, 2, 0, ull);
  for(int i=0;i<(1<<N);i++){
    int n = i+(1<<20), count=0;
    ull ah = 0, bh = 0;
    while(count<N){
      if(n%2==1) ah = ah * B + T[count];
      if(n%2==0) bh = bh * B + T[count];
      count++;
      n/=2;
    }
    hash.push_back(std::vector<ull>{ah, bh});
  }
  sort(hash.begin(), hash.end());
  for(int i=0;i<(1<<N);i++){
    int n = i + (1<<20), count=0;
    ull ah = 0, bh = 0;
    while(count<N){
      if(n%2==1) ah = ah * B + S[count];
      if(n%2==0) bh = bh * B + S[count];
      count++;
      n/=2;
    }
    auto itr = lower_bound(hash.begin(), hash.end(), std::vector<ull> {ah, bh});
    auto itr2 = lower_bound(hash.begin(), hash.end(), std::vector<ull> {ah, bh+1});
    ans += itr2 - itr;
  }
  std::cout << (!flag?0:ans) << '\n';
  return 0;
}


Measured memory_bytes: 14636
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

template <class T>
class CuSum {
private:
	vector<T> cusum;

public:
	CuSum(vector<T> const& vec) : cusum(vec.size() + 1) {
		for (int i = 0; i < (int)vec.size(); i++) cusum[i + 1] = cusum[i] + vec[i];
	}
	CuSum(const int N) : cusum(N + 1) {}
	void add(const int i, const T& x) { cusum[i + 1] += x; }
	void build() { for (int i = 0; i < (int)cusum.size() - 1; i++) cusum[i + 1] += cusum[i]; }

	// partial sum of 0-indexed [l, r)
	T operator()(int l, int r) {
		if (r < l || r < 0) {
			assert(0);
			return T(0);
		}
		else return cusum[r] - cusum[l];
	}
	// 0-indexed
	const T& operator[](int i) { return cusum[i + 1]; }
	T back() { return cusum.back(); }
};

int main() {

	int N, Q;
	cin >> N >> Q;

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

	vector<lint> X(Q);
	for (int i = 0; i < Q; i++) cin >> X[i];

	// xが小さいとき青木君は下から、高橋君は上から取っていく
	// 青木君が先にN/2目をとれるようになるところから順番の入れ替わりが発生する
	// 入れ替わり後は交互にとることになる

	// 境界をさがしていく
	// lは最小、rはN/2をさしておく
	// (Al + Ar) / 2 < x なら Arを先にとれる可能性がある
	// r - l 番目にArをとることになるので、高橋君より早く取れるか判定
	// 早く取れるならl++, r++、そうでないなら次の境界を試したいのでl++

	int l = 0, r = N / 2;
	vector<lint> border;
	while (r != N - 1) {
		lint c = (A[l] + A[r] + 2) / 2;
		if (r - l < N - r) {
			border.emplace_back(c);
			l++, r++;
		}
		else l++;
	}
	DMP(border);

	// 境界がわかれば取り方は簡単あとは累積和と、奇数偶数番目の累積和を計算しておけば和は求まる
	vector<lint> odd((N + 1) / 2), even((N + 1) / 2);
	for (int i = 0; i < N; i+=2) {
		odd[i / 2] = A[i];
		even[i / 2] = A[i + 1];
	}
	DMP(odd, even);
	CuSum sumA(A), sumO(odd), sumE(even);

	// N/2以降のものが何個とれるかは2分探索できる
	for (int i = 0; i < Q; i++) {
		int cnt = upper_bound(border.begin(), border.end(), X[i]) - border.begin();
		DMP(cnt);
		lint ans = sumA(N / 2 + cnt, N);
		if (N & 1) ans += sumO(0, cnt);
		else ans += sumE(0, cnt);
		cout << ans << "\n";
	}

	return 0;
}


Measured memory_bytes: 7708
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    vll vec(3);
    REP(i, 3) {
        cin >> vec.at(i);
    }
    sort(ALL(vec));
    cout << vec.at(0) + vec.at(1) << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from collections import deque

inputline = list(map(int, sys.stdin.readline().split()))

rgb = inputline[0] * 100 + inputline[1] * 10 + inputline[2]

if rgb%4==0:
	print('YES')
else:
	print('NO')

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> counts(N);
  for (int i = 0; i < K; ++i) {
    int d;
    cin >> d;
    for (int j = 0; j < d; ++j) {
      int a;
      cin >> a;
      --a;
      counts[a]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (counts[i] == 0) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3172
import heapq


def main():
    N = int(input())
    A = list(map(int, input().split()))
    X = [0] * (N+1)
    X[0] = sum(A[:N])
    Y = [0] * (N+1)
    Y[0] = sum(A[2*N:])
    h = A[:N]
    heapq.heapify(h)
    for i in range(N):
        heapq.heappush(h, A[N + i])
        minimum = heapq.heappop(h)
        X[i+1] = X[i] + A[N + i] - minimum
    h = [-x for x in A[2*N:]]
    heapq.heapify(h)
    for i in range(N):
        heapq.heappush(h, -A[2*N-1 - i])
        maximum = -heapq.heappop(h)
        Y[i+1] = Y[i] + A[2*N-1 - i] - maximum
    ans = - float("inf")
    for i in range(N+1):
        ans = max(ans, X[i] - Y[N-i])
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

const int N = 101000 + 577 , SQ = 517 , TB = 202;
long long S[N][SQ] , res;
int n , a[N];
vector < int > D[N];

inline long long Calc(int x , int y , int td) {
   if(y < SQ)
      return S[x][y] - S[min(N - 1 , x + td * y)][y];
   long long rr = 0;
   while((td --) > 0 && x < n)
      rr += a[x] , x += y;
   return rr;
}
int main() {
   for(int i = 1;i < N;++ i)
      for(int j = i;j < N;j += i)
         D[j].push_back(i);
   scanf("%d" , & n);
   for(int i = 0;i < n;++ i)
      scanf("%d" , a + i);
   for(int i = n - 1;i >= 0;-- i)
      for(int j = 1;j < SQ;++ j)
         S[i][j] = S[i + j][j] + a[i];
   for(int A = 2;A < n - 1;++ A) {
      for(int x : D[n - A - 1]) {
         int na = A;
         int ndiff = x;
         int nb = A - ndiff;
         if(nb <= 0 || (na % ndiff == 0 && na + nb < n - 1))
            continue ;
         int tx = (n - 1 - na) / ndiff;

         res = max(res , Calc(na , ndiff , tx) + Calc(ndiff , ndiff , tx));//+ Calc(0 , ndiff));
      }

   }
   printf("%lld\n" , res);
   return 0;
}


Measured memory_bytes: 416000
gets
s=[0]*3
gets.split.map(&:to_i).map{|i|
  s[2] += 1 if (i%4)==0
  s[1] += 1 if (i%4)!=0 && (i%2)==0
  s[0] += 1 if i.odd?
}
puts (s[1].zero? && s[0]-1<=s[2]) || (0<s[1] && s[0]<=s[2]) ? :Yes : :No


Measured memory_bytes: 9220
#include<iostream>
#include<map>
#include<vector>
#include<cstring>
using namespace std;
const int BUF = 200005;
const int MOD = 1000000007;


int add(int a, int b) {
    return (a + b) % MOD;
}

int sub(int a, int b) {
    return (a + MOD - b) % MOD;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

int modpow(int p, long long n) {
    if (n == 0) return 1;
    int t = modpow(p, n / 2);
    return n % 2 == 0 ? mul(t, t) : mul(mul(t, t), p);
}


int nNode;
vector<int> adj[BUF];

void read() {
    for (int i = 0; i < BUF; ++i) adj[i].clear();

    cin >> nNode;
    for (int i = 0; i < nNode - 1; ++i) {
        int s, t;
        cin >> s >> t;
        --s, --t;
        adj[s].push_back(t);
        adj[t].push_back(s);
    }
}


int getNumSubtreeNode(int node, int node2nSubtreeNode[BUF], map<int, int> edge2nSubtreeNode[BUF]) {
    int &ret = node2nSubtreeNode[node];
    ret = 1;
    
    for (int i = 0; i < adj[node].size(); ++i) {
        int nex = adj[node][i];
        if (node2nSubtreeNode[nex] != -1) continue;
        
        int nexNumSubtreeNode = getNumSubtreeNode(nex, node2nSubtreeNode, edge2nSubtreeNode);
        edge2nSubtreeNode[node][nex] = nexNumSubtreeNode;
        edge2nSubtreeNode[nex][node] = nNode - nexNumSubtreeNode;
        
        ret += nexNumSubtreeNode;
    }
    
    return ret;
}


int rec(int node, int childIdx, int nChose, vector< vector<int> > &dp, map<int, int> edge2nSubtreeNode[BUF]) {
    if (childIdx == adj[node].size()) {
        return nChose == 2 ? 1 : 0;
    }

    int &ret = dp[childIdx][nChose];
    if (ret != -1) return ret;
    ret = 0;

    int nSubtreeNode = edge2nSubtreeNode[node][adj[node][childIdx]];

    // Choose at least one node from node's childIdx-th subtree
    ret = add(ret, mul(rec(node, childIdx + 1, min(nChose + 1, 2), dp, edge2nSubtreeNode),
                       mul(sub(modpow(2, nSubtreeNode), 1), modpow(2, 1LL * nSubtreeNode * (MOD - 2)))));
    
    // Choose noting
    ret = add(ret, mul(rec(node, childIdx + 1, nChose, dp, edge2nSubtreeNode), modpow(2, 1LL * nSubtreeNode * (MOD - 2))));

    return ret;
}


void work() {
    map<int, int> edge2nSubtreeNode[BUF];
    
    int node2nSubtreeNode[BUF];
    memset(node2nSubtreeNode, -1, sizeof(node2nSubtreeNode));
    getNumSubtreeNode(0, node2nSubtreeNode, edge2nSubtreeNode);

    int sum = 0;
    for (int i = 0; i < nNode; ++i) {
        vector<vector<int> > dp(adj[i].size(), vector<int>(3, -1));
        sum = add(sum, rec(i, 0, 0, dp, edge2nSubtreeNode));
    }
    sum = mul(sum, modpow(2, MOD - 2));
    
    cout << sum << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 68212