akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

void solve(long long N, std::vector<long long> H) {
  LL ans=0;
  REP(i,N){
    bool flag=false;
    REP(j,i){
      if(H[j]>H[i])flag=true;
    }
    if(flag==false)ans++;
  }
  cout<<ans<<endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  solve(N, std::move(H));
  return 0;
}


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

int main() {
	int H, W, A, B, ans = 0;
	size_t N;
	cin >> N >> H >> W;
	for (size_t i = 0; i < N; ++i) {
		cin >> A >> B;
		if (A >= H && B >= W) ++ans;
	}
	cout << ans;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Math;


namespace _20180502_pra
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var K = int.Parse(Console.ReadLine());
            var X = int.Parse(Console.ReadLine());
            var Y = int.Parse(Console.ReadLine());
            if(N<=K)
                Console.WriteLine(N*X);
            else
                Console.WriteLine(K*X+(N-K)*Y);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long 
#define MAX 100001
using namespace std;

int main(){
	int n;
	cin >> n;
	ll a[n];
	ll prev = 0;
	for (int i=0;i<n;i++){
		cin >> a[i];
		if (i) a[i]+=a[i-1];
	}
	ll res = 0;
	ll temp = 0;
	for (int i=0;i<n;i++){
		if (i%2==0 && (a[i]+temp)<=0){
			res+=(1-(a[i]+temp));
			temp+=(1-(a[i]+temp));
		}
		else if (i%2==1 && (a[i]+temp)>=0){
			res+=(a[i]+temp+1);
			temp-=(a[i]+temp+1);
		}
	}
	ll tm = 0;
	temp = 0;
	for (int i=0;i<n;i++){
		if (i%2==1 && (a[i]+temp)<=0){
			tm+=(1-(a[i]+temp));
			temp+=(1-(a[i]+temp));
		}
		else if (i%2==0 && (a[i]+temp)>=0){
			tm+=(a[i]+temp+1);
			temp-=(a[i]+temp+1);
		}
	}
	cout << min(res,tm);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define vel vector<long long>
#define vech vector<char>
#define veb vector<bool>
#define vvel vector<vel>
#define int long long
#define pin pair<int,int>
#define ppin pair<int,pin>
#define mkp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define maxel(vec, j) *max_element(vec.begin(), vec.begin()+j)
using namespace std;
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
int hamming_distance(string a, string b){
    int res = 0;
    rep(i, a.size()){
        if(a[i]!=b[i]){res++;}
    }
    return res;
}
signed main() {
    int pr = 1000;
    pr *= pr * pr; pr += 7;
    string s;
    cin >> s;
    vech b1(s.size());
    vech b2(s.size());
    rep(i, s.size()){
        if(i%2 == 0){
            b1[i] = '0';
            b2[i] = '1';
        }else{
            b1[i] = '1';
            b2[i] = '0';
        }
    }
    string b1s(b1.begin(), b1.end());
    string b2s(b2.begin(), b2.end());
    cout<<min(hamming_distance(s, b1s), hamming_distance(s,b2s))<<endl;
    return 0;
}



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

int main()
{
	int n;
	cin >> n;
	if (n == 1)
		cout << "2" << endl;
	else if(n == 0 || n == 2)
		cout << "1" << endl;
	else
		cout << "0" << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<atcoder/math>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int T;cin>>T;
	while(T--){
		int N,M,A,B;cin>>N>>M>>A>>B;
		cout<<atcoder::floor_sum(N,M,A,B)<<"\n";
	}
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    int ans = 0;
    ll r = 0;
    for(ll i = 2; i * i <= n; i++){
        ll m = n;
        while(m % i == 0) m /= i;
        m %= i;
        if(m == 1) ans++;
        r = i;
    }
    for(ll i = 1; i * i <= n * 2; i++){
        if((n - 1) % i == 0){
            ll l = (n - 1) / i;
            if(l > r) ans++;
        }
    }
    if(n == 2) cout << 1 << endl;
    else cout << ans + 1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 3005
#define LL long long
using namespace std;
int n,m,a[maxn][maxn],ans,s[maxn],pre[maxn],q[maxn],tp;
char c[maxn];
int main()
{
    int k,x;
    cin>>k>>x;
    for(int i=x-k+1;i<x+k;i++)
        cout<<i<<" ";
}


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

def solve():
    total = 0

    if 10%p == 0:
        for i in range(n):
            if s[i] % p == 0: total += i + 1
        return total

    cnt = [0]*p
    r = 0
    ten = 1
    for i in range(n-1, 0-1, -1):
        cnt[r] += 1
        r = (r + s[i]*ten) % p
        total += cnt[r]
        ten = ten * 10 % p
    return total

print(solve())

Measured memory_bytes: 6560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int n , m;
    cin>>n>>m;
    int arr[m];
    int sum = 0;
    for(int i = 0;i<m;i++)
    {
        cin>>arr[i];
        sum = sum + arr[i];
    }
    if(sum>n)
    cout<<"-1";
    else{
        cout<<n - sum;
    }
    return 0;
}

Measured memory_bytes: 3640
/**
 *    author:  Mohamad Milhem
 *    created: 2020-04-04-18.04.41
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;
#define decimalpoint cout << std::fixed << setprecision(5)


int main(){

    FAST;

    int m , n;

    cin >> n >> m;

    long long sum = 0;
    vector<int> v(n);

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

//    debug(sum);

    double noless = (sum*1.0)/(4*m);


//    debug(noless);


    sort(v.rbegin(), v.rend());
    int ok = true;

    for (int i = 0 ; i < m ; i++){
//        debug(v[i]);
        if (v[i] < noless){ok = false;  break;}
    }

    if (ok) puts("Yes");
    else puts("No");

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define vsort(v) sort((v).begin(),(v).end())
#define vrsort(v) sort((v).rbegin(),(v).rend())
#define vreverse(v) reverse((v).begin(),(v).end())
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define INF 1998021900
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  string s;cin>>s;ll i,n;n=s.size();i=0;
  vll ans(n,0);
  while(i<n){
    ll t=0;
    while(s[i] =='R'){i++;t++;}
    if(t%2){ans[i-1]+=((t/2)+1);ans[i]+=(t/2);}else{ans[i]+=(t/2);ans[i-1]+=(t/2);}
    t=0;ll k=i;
    while((s[i] =='L')&&(i<n)){i++;t++;}
    if(t%2){ans[k]+=((t/2)+1);ans[k-1]+=(t/2);}else{ans[k]+=(t/2);ans[k-1]+=(t/2);}
    
  }
  //output
  aout(i,n,ans);
}

Measured memory_bytes: 1488
n, k = list(map(int, input().split()))

mod = 10**9 + 7
k = min(k, n-1)

def choose(n, r):
    x = 1
    y = 1
    for i in range(1, r+1):
        x = (x * (n-i+1)) % mod
        y = (y * i) % mod
    return (x * pow(y, mod-2, mod)) % mod

kaijo = [1]
for i in range(1,n+1): 
  kaijo.append(kaijo[i-1]*i % mod)

ans = 0
for i in range(k+1):
#    ans += (choose(n, min(i,n-i)) * choose(n-1, min(i,n-1-i))) % mod
    ans += kaijo[n] * pow(kaijo[i]*kaijo[n-i], mod-2,mod) * kaijo[n-1]*pow(kaijo[i]*kaijo[n-1-i],mod-2,mod)
    ans = ans % mod
print(ans % mod)


Measured memory_bytes: 13076
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		String s = sc.next();
		if (s.length() <= k) {
			System.out.println(s);
		} else {
			String S = s.substring(0, k);
			System.out.println(S + "...");
		}

	}

}


Measured memory_bytes: 27088
#include<stdio.h>
#include<stdio.h>
int main(){
  int L,N,i,j;
  scanf("%d %d",&N,&L);
  char S[N][L+1];
  char tmp[N];
  for(i=0;i<N;i++){
      scanf("%s",S[i]);
  }
  for(i=0;i<N-1;i++){
for(j=N-1;j>i;j--){
if(strcmp(S[j-1],S[j])>0){
strcpy(tmp,S[j-1]);
strcpy(S[j-1],S[j]);
strcpy(S[j],tmp);
} } }
for(i=0;i<N;i++)
printf("%s",S[i]);
return 0;
}

Measured memory_bytes: 128
# %%
a,b = map(int,input().split())
#a>b
if a > b :
    c = a
    d = b
else:
    c = b
    d = a

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
#a>b
def lcm(a,b):
    return a*b // gcd(a,b)
print(lcm(c,d))

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

int main() {
  int a;
  int b;
  cin >> a >> b;
  
  if (a * b % 2 == 0) {
    cout << "Even" << endl;
  }
  else if (a * b % 2 != 0) {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func init() {
	sc = bufio.NewScanner(os.Stdin)
	buffsize := 1000000
	buff := make([]byte, buffsize)
	sc.Buffer(buff, buffsize)
	sc.Split(bufio.ScanWords)
}

func loadint() (result int) {
	sc.Scan()
	result, _ = strconv.Atoi(sc.Text())
	return
}

func factorize(m int) map[int]int {
	result := map[int]int{}
	i := 2
	x := m
	for i*i <= m {
		n := 0
		for x%i == 0 {
			n++
			x /= i
		}
		if n > 0 {
			result[i] = n
		}
		i++
	}
	if x > 1 {
		result[x] = 1
	}
	return result
}

func pow(x, n, m int) int {
	r := 1
	for n > 1 {
		if n&1 == 1 {
			r = r * x % m
		}
		x = x * x % m
		n >>= 1
	}
	return r * x % m
}

const M int = 1000000007

func calcFactorial(size, M int) []int {
	fs := make([]int, size)
	fs[0] = 1
	for i := 1; i < size; i++ {
		fs[i] = fs[i-1] * i % M
	}
	return fs
}

var fs = calcFactorial(200000, M)

func combination(x, y, M int) int {
	return (fs[x] * pow(fs[y], M-2, M) % M) * pow(fs[x-y], M-2, M) % M
}

func main() {
	n := loadint()
	m := loadint()
	fs := factorize(m)
	result := 1
	for _, y := range fs {
		result = result * combination(n+y-1, y, M) % M
	}
	fmt.Println(result)
}


Measured memory_bytes: 2304
# frozen_string_literal: true

class Node
  attr_accessor :key, :parent, :left, :right

  def initialize(key)
    @key = key
  end

  def root?
    parent ? false : true
  end
end

class Tree < Array
  def insert(node)
    y = nil
    x = root_node

    until x.nil?
      y = x
      x = if node.key < x.key
            x.left
          else
            x.right
      end
    end
    node.parent = y

    if y.nil?
      push node
    elsif node.key < y.key
      y.left = node
    else
      y.right = node
    end
  end

  def find_node(key)
    node = root_node
    while node && node.key != key
      node = if key < node.key
               node.left
             else
               node.right
             end
    end

    node
  end

  def root_node
    find(&:root?)
  end
end

def print_order_by_preorder(node)
  return unless node

  print ' '
  print node.key
  print_order_by_preorder(node.left)
  print_order_by_preorder(node.right)
end

def print_order_by_inorder(node)
  return unless node

  print_order_by_inorder(node.left)
  print ' '
  print node.key
  print_order_by_inorder(node.right)
end

n = gets.to_i
array = readlines.map(&:chomp!).map do |line|
  if line == 'print'
    { print: 0}
  elsif line.include?('find')
    { find: line.split[1].to_i }
  elsif line.include?('insert')
    { insert: line.split[1].to_i }
  end
end

tree = Tree.new

array.each do |e|
  if e[:insert]
    tree.insert(Node.new(e[:insert]))
  elsif e[:find]
    tree.find_node(e[:find]) ? puts('yes') : puts('no')
  elsif e[:print]
    print_order_by_inorder(tree.root_node)
    print "\n"
    print_order_by_preorder(tree.root_node)
    print "\n"
  end
end




Measured memory_bytes: 184764
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    LL ans=0;
    for(int i=1; i<=n; i++) {
        if ( i%3==0 || i%5==0 ) continue;
        ans+=i;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
fun main() {
    val (n,k) = readLine()!!.split(" ").map { it.toInt() }
    val arr = readLine()!!.split(" ").map { it.toInt() }.sorted()

    fun isNecessary(idx:Int): Boolean {
        if(arr[idx] >= k)
            return true
        val dp = Array(2){BooleanArray(k+1){false} }
        var cur = 0
        var next = 1
        dp[cur][0] = true
        dp[next][0] = true

        for(i in arr.indices) {
            if(i == idx) continue
            val v = arr[i]
            for(j in 1..k) {
                dp[next][j] = dp[cur][j]
            }
            for(j in 1..k) {
                if(j - v < 0) continue
                dp[next][j] =  dp[next][j] or dp[cur][j-v]
                if(j >= k - arr[idx] && j <= k - 1 && dp[next][j])
                    return true
            }
            cur = (cur + 1) % 2
            next = (next + 1) % 2
        }
        return false
    }
    var ans = n
    var l = 0
    var r = n - 1
    while(l <= r) {
        val mid = (l + r) / 2
        if(isNecessary(mid)) {
            r = mid - 1
            ans = mid
        } else {
            l = mid + 1
        }
    }
    print(ans)
    // 2 3 4 10 10 25
    // 0 1 2 3 4 5
}

Measured memory_bytes: 43372
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    ll n, k; cin >> n >> k;

    pair<int, int> ab[n];
    for(int i=0; i<n; i++){
        int t1, t2; cin >> t1 >> t2;
        ab[i] = make_pair(t1, t2);
    }

    sort(ab, ab+n);

    ll index = 0;
    while(true){

        k -= ab[index].second;
        if(k <= 0){
            cout << ab[index].first;
            break;
        }
        else{
            index++;
            if(index >= n){
                break;
            }
        }
    }



    return 0;
}

Measured memory_bytes: 1152
package main

import (
  "fmt"
)

func main() {
  var N, X , min int
  fmt.Scan(&N, &X)
  // Mを入力する
  M := make([]int, N)
  for i, _ := range M {
    fmt.Scan(&M[i])
  }
  // TODO: 最小値を求める
  min = M[0]
  for _, v := range M {
    if (v < min) {
      min = v
    }
  }
  // 1つずつ足していった場合
  var sum int
  for _, i := range M {
    sum = sum + i
  }

  // ドーナツの粉の残りを求める = amari
  amari := X - sum
  count := amari / min
  fmt.Println(count + N)

}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int h,w,n;
int res[10];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> h >> w >> n;
  map<PII,int> mapa;
  R(i,n){
    int a,b;
    cin >> a >> b;
    for(int x = -1;x <= 1; x++)
      for(int y = -1;y <= 1; y++)
        mapa[{a+x,b+y}]++;
  }
  res[0] = (h-2) * (w-2);
  for(auto x:mapa){
    if(x.FI.FI > 1 && x.FI.FI <= h-1)
    if(x.FI.SE > 1 && x.FI.SE <= w-1){
      res[x.SE]++;
      res[0]--;
    }
  }
  R(i,10)
    cout << res[i] << "\n";
}


Measured memory_bytes: 56576
#include <iostream>
#include <vector>
#include <cstdlib>
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; }

const long long INF = 1LL << 60;

int main() {
    int N; cin >> N;
    int a[1000000];
    int b[1000000];
    int c[1000000];
    for (int i = 0;i < N;i++) {
        cin >> a[i];
        cin >> b[i];
        cin >> c[i];
    }
    long long bp[1000000][3];
    for (int i = 0;i<N;i++) {
        for (int j = 0;j<3;j++) {
            bp[i][j] = 0;
        }
    }
    bp[0][0] = a[0];
    bp[0][1] = b[0];
    bp[0][2] = c[0];
    for (int i = 1;i < N;i++) {
        chmax(bp[i][0],bp[i-1][1] + a[i]);
        chmax(bp[i][0],bp[i-1][2] + a[i]);
        chmax(bp[i][1],bp[i-1][0] + b[i]);
        chmax(bp[i][1],bp[i-1][2] + b[i]);
        chmax(bp[i][2],bp[i-1][0] + c[i]);
        chmax(bp[i][2],bp[i-1][1] + c[i]);
    }
    cout << max(max(bp[N-1][0],bp[N-1][1]),bp[N-1][2]) << endl;
}

Measured memory_bytes: 12928
N = int(input())
A = list(map(int, input().split()))

if 0 in A:
    print(0)
    exit()

A.sort(reverse=True)

result = A[0]
for a in A[1:]:
    if result * a > 10**18:
        print(-1)
        exit()
    else:
        result = result * a

print(result)

Measured memory_bytes: 21640
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int h, w;
char grid[1000][1000];
int inf = -1;
int dx[] = { 1,-1,0,0 };
int dy[] = { 0,0,1,-1 };
int d[1000][1000];

void bfs() {
	int r = h, c = w;
	queue<pair<int, int>>que;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			if (grid[i][j] == '#') {
				d[i][j] = 0;
				que.push(P(i, j));
			}
			else {
				d[i][j] = inf;
			}
		}
	}
	while (!que.empty()) {
		pair<int, int>p = que.front();
		que.pop();
		for (int i = 0; i < 4; i++) {
			int ny = p.first + dy[i], nx = p.second + dx[i];
			if (0 <= ny && ny < r && 0 <= nx && nx < c &&
				d[ny][nx] == inf) {
				que.push(pair<int, int>(ny, nx));
				d[ny][nx] = d[p.first][p.second] + 1;
			}
		}
	}
}

int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> grid[i][j];
		}
	}
	int ans = 0;
	bfs();
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			ans = max(d[i][j], ans);
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;
}

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


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

const long INF = 1123456789012345678;

long q;

bool like[100005];
long sum[100005];

bool is_prime(long n){
	for(int i = 2; i*i <= n; i++){
		if(n % i == 0){
			return false;
		}
	}
	return true;
}

void solve(){
	long l, r;
	scanf("%ld %ld", &l, &r);
	printf("%ld\n", sum[r] - sum[l-1]);
	return;
}

int main(){
	like[1] = false;
	for(int i = 3; i <= 100000; i += 2){
		like[i] = (is_prime(i) && is_prime((i+1)/2));
	}
	for(int i = 1; i <= 100000; i++){
		if(like[i]){
			sum[i] = sum[i-1] + 1;
		}else{
			sum[i] = sum[i-1];
		}
	}
	scanf("%ld", &q);
	for(int i = 0; i < q; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 1536
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
ans=sum(a)
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    ans+=(c-b)*cnt[b]
    cnt[c]+=cnt[b]
    cnt[b]=0
    print(ans)

Measured memory_bytes: 24188
import sys

def bubbleSort(x_list, y):
  a = 0
  flag = 1
  while flag:
    flag = 0
    for i in range(1, y):
      j = y - i
      if x_list[j] < x_list[j - 1]:
        x_list[j], x_list[j - 1] = x_list[j - 1], x_list[j]
        flag = 1
        a += 1
  return a

y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()
x_list = x.split(" ")

for i in range(y):
  x_list[i] = int(x_list[i])

a = bubbleSort(x_list, y)

for k in range(0, y):
  print x_list[k],
print
print a

Measured memory_bytes: 6364
# coding: utf-8
# Your code here!

H, W = map(int, input().split())

# print(H)
# print(W)

ah = 0
aw = 0

alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

for i in range(H):
    # print(0)
    
    s = list(input().split(" "))
    for j in range(W):
        # print(s[j])
        
        if s[j] == 'snuke':
            # print('〇')
            ah = i
            aw = j

# print(alp[aw])
# print(ah + 1)


print(str(alp[aw]) + str(ah + 1))
            

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
    int n,sum=0,x,y,i;
    cin>>n;
    while(n--)
    {
        sum+=1;
        cin>>x>>y;
        if(x<=y)
        {
            sum+=(y-x);
        }
        else
        {
            sum+=(x-y);
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

//count inside [sy,ey) [sx,ex)
int count_inside(VVI &sum, int sy, int sx, int ey, int ex)
{
    if (sy == ey || sx == ex)
        return 0;
    return sum[ey][ex] - sum[sy][ex] - sum[ey][sx] + sum[sy][sx];
}

int main()
{
    int n, k;
    cin >> n >> k;
    VVI piece(2 * k, VI(2 * k, 0));
    rep(i, n)
    {
        int x, y;
        char c;
        cin >> x >> y >> c;
        if (c == 'B')
        {
            x += k;
        }
        x %= 2 * k;
        y %= 2 * k;
        piece[y][x]++;
    }
    VVI sum(2 * k + 1, VI(2 * k + 1, 0));
    rep(i, 2 * k)
    {
        rep(j, 2 * k)
        {
            sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + piece[i][j];
        }
    }
    int ans = -1;
    rep(i, k)
    {
        rep(j, k)
        {
            int num = count_inside(sum, 0, j, i, j + k) + count_inside(sum, i, j + k, i + k, 2 * k) + count_inside(sum, i, 0, i + k, j) + count_inside(sum, i + k, j, 2 * k, j + k);
            chmax(ans, num);
            num = count_inside(sum, 0, 0, i, j) + count_inside(sum, i, j, i + k, j + k) + count_inside(sum, i + k, j + k, 2 * k, 2 * k) + count_inside(sum, i + k, 0, 2 * k, j) + count_inside(sum, 0, j + k, i, 2 * k);
            chmax(ans, num);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 34580
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

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

int main() {

  int n;
  int a[MAX_N];

  cin >> n;
  rep(i, n) cin >> a[i];

  int m = 1;  //現在の添え字
  int cnt = 0;

  rep(i, n) {
    if(a[i]==m) ++m;
    else ++cnt;
  }

  cout << ((m==1) ? -1 : cnt) << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define fori(j,n) for(int i=j ; i<n ; i++)
#define forj(i,n) for(int j=i ; j<n ; j++)
#define fork(i,n) for(int k=i ; k<n ; k++)
#define ppb pop_back()
#define umap unordered_map
#define uset unordered_set
#define lli long long int

using namespace std;

void solve()
{
	lli k;cin>>k;
	if(k%2==0 or k%5==0) {cout<<-1;return;}
	lli ans=0;
	int cnt=0;
	while(1)
	{
		cnt++;
		ans = (ans*10+7)%k;
		if(ans==0) break;
	}
	cout<<cnt;

	
}

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

	// int t;cin>>t;
	// while(t--)
	// {
		solve();
		// cout<<endl;
	// }


	return 0;

}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  ll ans = 0;
  int n;
  cin >> n;
  int neg = 0;
  int min_abs = MOD;
  rep(i,n){
    int buf;
    int abs_buf;
    cin >> buf;
    abs_buf = max(-buf,buf);
    if (buf < 0) neg++;
    if (min_abs > abs_buf) min_abs = abs_buf;
    ans += abs_buf;
  }
  
  ans = (neg%2 == 0) ? ans : ans - 2*min_abs;
  cout <<ans<< endl;
}



Measured memory_bytes: 256
n = int(input())
for i in range(1, n+1):
    if i % 3 == 0:
        print(' '+str(i), end = '')
    elif i % 10 ==3:
        print(' '+str(i), end = '')
    else:
        x = i
        while x != 0:
            x = x // 10
            if x % 10 == 3:
                print(' '+str(i), end = '')
                break
print('')



Measured memory_bytes: 5876
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;
 
#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)
 
typedef long long ll;
typedef int inte;
#define int ll
 
const int N=2e5+50;
 
struct Tuple { 
	int v,c0,c1;
	bool operator<(const Tuple &r)const{
		return c0*r.c1<r.c0*c1;
	}
};
priority_queue<Tuple> q;
 
int n,col[N],ufP[N],trP[N],c0[N],c1[N]; 
vector<int> g[N]; 
long long ans;
 
int find(int x){ return ufP[x]==x?x:ufP[x]=find(ufP[x]); }
 
inte main(inte argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
//	freopen("my.out","w",stdout);
#endif
	scanf("%lld",&n);
	rep(i,2,n){
		scanf("%lld",trP+i); 
		g[trP[i]].pb(i); 
	}
	rep(i,1,n){
		scanf("%lld",col+i); 
		c0[i]=col[i]==0;
		c1[i]=col[i]==1;
		ufP[i]=i;
		if(i>1)q.push((Tuple){i,c0[i],c1[i]});
	}
	rep(k,1,n-1){
		Tuple t;
		for(t=q.top();t.c0!=c0[t.v]||t.c1!=c1[t.v];q.pop(),t=q.top());	
		assert(find(t.v)==t.v);
		int f=find(trP[t.v]);
		ans+=1ll*c1[f]*c0[t.v];
		c0[f]+=c0[t.v];
		c1[f]+=c1[t.v];
		if(f>1)q.push((Tuple){f,c0[f],c1[f]});
		ufP[t.v]=f;
		c0[t.v]=c1[t.v]=-1;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 26864
#include <bits/stdc++.h>
 
#define ll long long
#define loop(a) for(long long i=0; i<a; i++)
 
using namespace std;

int main(){
	int n,x;
	cin >> n;
	ll ans=0;
	int a[n];
	loop(n) cin >> a[i];
	sort(a,a+n);
	loop(n-2){
		x=i+1;
		for(int j=i+2; j<n; j++){
			while(1){
				if(a[j]<a[i]+a[x]){
					ans=ans+j-x;
					break;
				}
				x++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
X, Y = map(int, input().split())
X, Y = min(X, Y), max(X, Y)

if (X + Y) % 3 != 0:
    print(0)
    exit()
if Y > 2 * X:
    print(0)
    exit()


class Combination:
    """
    SIZEが10^6程度以下の二項係数を何回も呼び出したいときに使う
    使い方:
    comb = Combination(SIZE, MOD)
    comb(10, 3) => 120
    """

    def __init__(self, N, MOD=10 ** 9 + 7):
        self.MOD = MOD
        self.fact, self.inv = self._make_factorial_list(N)

    def __call__(self, n, k):
        if k < 0 or k > n:
            return 0
        res = self.fact[n] * self.inv[k] % self.MOD
        res = res * self.inv[n - k] % self.MOD
        return res

    def _make_factorial_list(self, N):
        fact = [1] * (N + 1)
        inv = [1] * (N + 1)
        MOD = self.MOD
        for i in range(1, N + 1):
            fact[i] = (fact[i - 1] * i) % MOD
        inv[N] = pow(fact[N], MOD - 2, MOD)
        for i in range(N, 0, -1):
            inv[i - 1] = (inv[i] * i) % MOD
        return fact, inv


move = (X + Y) // 3
yoko = (move - (Y - X)) // 2
tate = move - yoko

comb = Combination(10**6+10, 10**9+7)
ans = comb(tate+yoko, yoko)
print(ans)


Measured memory_bytes: 82164
#include<stdio.h>
int main(void)
{
    int N,i,j=0,k=0,l=0,m=0;
    char S[100001];
  
    scanf("%d",&N);
  
    for(i=0;i<N;i++){
      scanf("%s",S);
      if(S[0]=='A') j++;
      else if(S[0]=='W') k++;
      else if(S[0]=='T') l++;
      else m++;
    }
  
    printf("AC x %d\n",j);
    printf("WA x %d\n",k);
    printf("TLE x %d\n",l);
    printf("RE x %d\n",m);
  
    return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,x,y;cin>>n>>x>>y;
    int ans[n];
    fill(ans,ans+n,0);
    rep(i,1,n){
        rep(j,i+1,n+1){
            int dis=min(j-i,abs(x-i)+1+abs(j-y));
            ans[dis]++;
            //if(dis==1)cout<<i<<" "<<j<<endl;
        }
    }
    rep(i,1,n)cout<<ans[i]<<endl;
}







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

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  int x, y;
 
  while(true) {
    cin >> x >> y;
 
    if(!x && !y) {
      break;
    }
 
    for (int i = 0; i < x; ++i) {
      for (int j = 0; j < y; ++j) {
        if(i % 2 == 0 && j % 2 == 0 || j % 2 == 1 && i % 2 == 1) {
          cout << "#";
        } else {
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int x,y;
  cin >> x >> y;
  for(int i=2*x; i<=4*x; i+=2){
    if(i==y){
      cout << "Yes" << ln; return 0;
    }
  }
  cout << "No" << ln;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
#include <iomanip>
using namespace std;
typedef long long ll;
#define rep(i,k) for(i=0;i<k;i++)
#define P pair<ll,ll>
int t[2005],u[200];

ll i, a, b, c,k,n,m, z=0;
char s[100005];
int main() {
	cin >> n>>k;
	cin >> s;
	a = 0;
	rep(i, n-1) {
		if (s[i] != s[i + 1]) {
			a++;
			if (k > 0) {
				z++;
				if (a == 2) {
					k--;
					a = 0;
				}
			}
		}
		else z++;

	}



	cout << z;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }


//---------- セグ木 ----------
const int  SEG_MAX = (1 << 20); //1<<17 = 2^17 = 131072
int seg1[SEG_MAX * 2] = { 0 };

//[a,b]にxを加算 (節点kをベースに[l,r]に足す)
void add1(int a, int b, int x, int k = 0, int l = 0, int r = SEG_MAX - 1)
{
	if (a <= l && r <= b)
	{
		seg1[k] = min(x, seg1[k]);
	}
	else
	{
		int l0 = l;
		int r0 = l + (r - l) / 2;
		int l1 = r0 + 1;
		int r1 = r;
		if (a <= r0)
		{
			int kk = 2 * k + 1;
			add1(a, b, x, kk, l0, r0);
		}
		if (l1 <= b)
		{
			int kk = 2 * k + 2;
			add1(a, b, x, kk, l1, r1);
		}
	}
}

int get1(int index)
{
	int m = INT_MAX;
	int k = SEG_MAX - 1 + index; //根
	while (true)
	{
		m = min(m, seg1[k]);
		if (k == 0) break;
		k = (k - 1) / 2;
	}
	return m;
}

int seg2[SEG_MAX * 2] = { 0 };
//[a,b]にxを加算 (節点kをベースに[l,r]に足す)
void add2(int a, int b, int x, int k = 0, int l = 0, int r = SEG_MAX - 1)
{
	if (a <= l && r <= b)
	{
		seg2[k] = min(x, seg2[k]);
	}
	else
	{
		int l0 = l;
		int r0 = l + (r - l) / 2;
		int l1 = r0 + 1;
		int r1 = r;
		if (a <= r0)
		{
			int kk = 2 * k + 1;
			add2(a, b, x, kk, l0, r0);
		}
		if (l1 <= b)
		{
			int kk = 2 * k + 2;
			add2(a, b, x, kk, l1, r1);
		}
	}
}

int get2(int index)
{
	int m = INT_MAX;
	int k = SEG_MAX - 1 + index; //根
	while (true)
	{
		m = min(m, seg2[k]);
		if (k == 0) break;
		k = (k - 1) / 2;
	}
	return m;
}


int N, Q;

void print()
{
	for (int y = 1; y < N; y++)
	{
		cout << get2(y) << endl;
	}
	cout << endl;

	for (int x = 1; x < N; x++)
	{
		cout << get1(x) << " ";
	}
	cout << endl;
	cout << endl;
}




signed main()
{
	REP(i, SEG_MAX * 2)
	{
		seg1[i] = INT_MAX;
		seg2[i] = INT_MAX;
	}

	cin >> N >> Q;

	add1(0, N, N);
	add2(0, N, N);

	int sum = 0;
	REP(q, Q)
	{
		int t, a;
		cin >> t >> a;

		if (t == 1)
		{
			int n = get1(a);
			sum += (n - 2);
			add2(0, n, a);
		}
		if (t == 2)
		{
			int n = get2(a);
			sum += (n - 2);
			add1(0, n, a);
		}
	}
	cout << ((N - 2) * (N - 2) - sum) << endl;
}



Measured memory_bytes: 36388
import sys
input = sys.stdin.readline
import random
import copy
d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(d)]
ans = []
now = [0]*26
for i in range(d):
    no = -1
    score = -10**10
    for j in range(26):
        count = s[i][j]
        for k in range(26):
            if j == k:
                continue
            count -= (i+1-now[k])*c[k]
        if count > score:
            no = j
            score = count
    ans.append(no+1)
    now[no] = i+1
score = [0]*26
for i in range(d):
    
    now[ans[i]-1] = i+1
    ind = ans[i]-1
    for j in range(26):
        if j == ind:
            score[j] += s[i][ind]
        else:
            x = (i+1-now[j])*c[j]
            score[j]-= x
SUM = sum(score)
roop = 0
while roop < 50000:
    x = random.randint(1,d)
    y = random.randint(1,26)
    if ans[x-1] == y:
        continue
    be = ans[x-1]
    be -= 1
    now1 =  0
    now2 = 0
    nex = copy.deepcopy(ans)
    nex[x-1] = y
    y -= 1
    count1 = 0
    count2 = 0
    for j in range(d):
        if be == nex[j]-1:
            now1 = j+1
            count1 +=s[j][be]
        else:
            count1 -= (j+1-now1)*c[be]
        if y == nex[j]-1:
            now2 = j+1
            count2 +=s[j][y]
        else:
            count2 -= (j+1-now2)*c[y]
 
    count = SUM + count1+count2-score[be]-score[y]
    
    if count > SUM:
        score[be] = count1
        score[y] = count2
        ans = nex
        SUM = count
    roop += 1
for i in ans:
    print(i)


Measured memory_bytes: 93032
N,M = map(int,input().split())
s = [0 for i in range(N)]

s_list = []
for i in range(M):
    x_in = list(map(int,input().split()))
    s = x_in[1:]
    s_list.append(s)

p = list(map(int,input().split()))

ok = 0
for i in range(2**N):
    s = format(i,'010b')
    s = s[-N:]
    s = [int(s[i]) for i in range(len(s))]

    
    for j in range(M):
        l = s_list[j]
        cnt = 0
        for ll in l:
            if s[ll-1] == 1:
                cnt += 1
        if cnt % 2 != p[j]:
            break
        if j == M-1:
            ok += 1

print(ok)



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

typedef long long lint;
#define fint register int
#define flint register lint

namespace ae86
{
	const int bufl = 1<<15;
	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		fint a=0,b=1,c=getchar();
		while(!isdigit(c))b^=c=='-',c=getchar();
		while(isdigit(c))a=a*10+c-48,c=getchar();
		return b?a:-a;
	}
}

using ae86::ty;

const int _ = 100007 , __ = _<<1;

inline void failure(int x)
{
	if(x){puts("-1");exit(0);}
}
inline void failure()
{
	puts("-1");exit(0);
}

int to[__],ne[__],he[_]={0},ecnt=1;
void adde(int a,int b)
{
	to[++ecnt]=b,ne[ecnt]=he[a],he[a]=ecnt;
}
void addde(int a,int b)
{
	adde(a,b),adde(b,a);
}

int n,m,dep[_]={0},ed[_]={0};
int ca=0,cb=0,ouc=0;

void dfs(int x,int ff)
{
	ed[x]=1;
	for(int i=he[x];i;i=ne[i])
	{
		int b=to[i];
		if(b==ff)continue;
		if(ed[b])
		{
			ca=x,cb=b;
			if(dep[ca]==dep[cb])ouc=1;
		}
		else dep[b]=dep[x]^1,dfs(b,x);
	}
}

int val[_]={0},tag[_]={0},temp[_]={0},ltemp=0,sval=0;

void dfs2(int x,int ff)
{
	for(int i=he[x];i;i=ne[i])
	{
		int b=to[i];
		if(b==ff)continue;
		if((x==ca && b==cb) || (x==cb && b==ca))continue;
		dfs2(b,x);
		val[x]+=val[b],tag[x]+=tag[b];
	}
}

int main()
{
	flint ans=0;
	
	n=ty(),m=ty();
	for(fint i=1;i<=m;i++)
	{
		fint a=ty(),b=ty();
		addde(a,b);
	}

	dep[1]=1,dfs(1,0);

	for(fint i=1;i<=n;i++)
	{
		if(dep[i])val[i]=1;
		else val[i]=-1;
		sval+=val[i];
	}

	if(m==n-1)failure(sval);
	else
	{
		if(ouc)failure(sval&1),val[ca]-=sval/2,val[cb]-=sval/2,ans+=abs(sval/2);
		else failure(sval),tag[ca]++,tag[cb]--;
	}

	dfs2(1,0);

	for(fint i=1;i<=n;i++)
	{
		if(!tag[i])ans+=abs(val[i]);
		else
		{
			if(tag[i])val[i]=-val[i];
			temp[++ltemp]=val[i];
		}
	}
	temp[++ltemp]=0,sort(temp+1,temp+ltemp+1);
	for(fint i=1,a=temp[(ltemp+1)/2];i<=ltemp;i++)ans+=abs(temp[i]-a);

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


Measured memory_bytes: 8832
from bisect import *
n,m = map(int,input().split())
S = input()
ok = []
for i,s in enumerate(S[::-1]):
    if s == '0':
        ok.append(i)

now = 0
ans = []
while now != n:
    nxt = ok[bisect_right(ok, now + m) - 1]
    if nxt == now:
        ans = [str(-1)]
        break
    else:
        ans.append(str(nxt - now))
        now = nxt
print(' '.join(ans[::-1]))


Measured memory_bytes: 53040
import java.util.Scanner;
import java.util.Stack;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] values = scanner.nextLine().split(" ");
        System.out.println(calcurate(values));
    }

    private static long calcurate(String[] values) {
        Stack<Long> stack = new Stack<>();

        for (int i = 0; i < values.length; i++) {

            switch (values[i]) {
            case "+":
                stack.push(Long.valueOf(
                        stack.pop().longValue() + stack.pop().longValue()
                        ));
                break;
            case "-":
                long b = stack.pop().longValue();
                long a = stack.pop().longValue();
                stack.push(Long.valueOf(a - b));
                break;
            case "*":
                stack.push(Long.valueOf(
                        stack.pop().longValue() * stack.pop().longValue()
                        ));
                break;
            default:
                stack.push(Long.parseLong(values[i]));
            }
        }

        return stack.pop().longValue();
    }
}



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



int main() 
{
  ll N; cin>>N;
  map<ll,ll> mapa;
  rep(i,N)
  {
    ll a; cin>>a;
    if(mapa.count(a)) {mapa.at(a)++; continue;}
    mapa[a]=1;
  }
  ll count=0;
  for(auto p:mapa)
  {
    if(p.first<p.second) {count+=p.second-p.first; continue;}
    if(p.first>p.second) {count+=p.second;}
  } 
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 6272
using System;

public class AtCoder
{
    public static void Main()
    {
        string[] s;
        s = Console.ReadLine().Trim().Split(' ');
        int n, k;
        n = int.Parse(s[0]);
        k = int.Parse(s[1]);
        s = Console.ReadLine().Trim().Split(' ');
        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = long.Parse(s[i]);
       
        }
        b[0] = a[0];
        for (int i = 1; i < n; i++)
        {
            b[i] = b[i - 1] + a[i];

        }

        int c = 0;
        long[] x = new long[n * (n + 1) / 2];
        long[] y = new long[n * (n + 1) / 2];
        for (int i=0; i<n; i++)
        {
            for (int j=-1; j<i; j++)
            {
                if (j == -1) x[c] = b[i];
                else x[c] = b[i] - b[j];
                y[c] = 1;
                c++;
            }
        }
        long p = 0;
        int d = 0;
        long[] z = new long[60];
        for (int i = 59; i > -1; i--)
        {
            d = 0;
            p = (long)Math.Pow(2, i);
            for (int j = 0; j < c; j++)
            {
                if(y[j] == 1) if (x[j] - p >= 0) d++;
                
            }
            if (d >= k)
            {
                z[i] = 1;
                for (int j = 0; j < c; j++)
                {
                    x[j] -= p;
                    if (x[j]< 0) y[j] = 0;
                }
            }
            else
            {
                for (int j = 0; j < c; j++)
                {
                    if (x[j] >= p) x[j] -= p;
                }
            }
        }
        long ans = 0;
        for (int i = 59; i > -1; i--)
        {
            ans += (long)Math.Pow(2, i)*z[i];
        }
        //for(int i = 0; i<z.Length; i++)
            Console.WriteLine(ans);
    }
}


Measured memory_bytes: 18784