akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]


class BIT:
            
    def __init__(self, L):
        self.N = len(L)
        self.bit = [0]*self.N
        for i,l in enumerate(L):
            self.add(i,l)
        self.N0 = 1
        while self.N0*2 <= self.N:
            self.N0 *= 2

    def add(self, a, w):
        x = a + 1
        for i in range(1000):
            self.bit[x-1] += w
            x += x & -x
            if x > self.N:
                break

    def sum(self, a):
        x = a+1
        ret = 0
        for i in range(1000):
            ret += self.bit[x-1]
            x -= x & -x
            if x <= 0:
                break        
        return ret

    #you can use this function when the BIT has only non-negative values.
    def lower_bound(self, w):
        if w<=0:
            return 0
        x = 0
        k = self.N0
        while k>0:
            if x+k<=self.N:
                if self.bit[x+k-1]<w:
                    w-=self.bit[x+k-1]
                    x+=k
            k//=2
        return x

def main():
    N,Q = list(map(int,input().split()))
    c = list(map(int,input().split()))

    LR = []

    for i in range(Q):
        l,r = list(map(int,input().split()))
        LR.append((l-1,r-1,i))

    LR.sort(key=lambda x:x[1])


    bit = BIT([0]*N)
    ans = [0]*Q
    count = 0
    last_one = [-1]*N
    for l,r,i in LR:
        while count<=r:
            color = c[count]-1
            if last_one[color]==-1:
                last_one[color] = count
                bit.add(last_one[color],1)
            else:
                bit.add(last_one[color],-1)
                last_one[color] = count
                bit.add(last_one[color],1)
            count+=1
        if l==0:
            ans[i] = bit.sum(r)
        else:
            ans[i] = bit.sum(r) - bit.sum(l-1)
    print(*ans,sep="\n")

if __name__ == '__main__':
    main()



Measured memory_bytes: 242236
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	int n;
	int p[100];
	int rank[100];
	int sum = 0;
	int i, j, index = 0;
	int work;
	char s[100][20];
	char string[20];
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++) {
		scanf("%s%d", s[i], &p[i]);
		rank[i] = i + 1;
	}
	
	for(i = 0; i < n - 1; i++) {
		for(j = 0; j < n - 1 - i; j++) {
			if(strcmp(s[j], s[j + 1]) > 0) {
				strcpy(string, s[j]);
				strcpy(s[j], s[j + 1]);
				strcpy(s[j + 1], string);
				work = p[j];
				p[j] = p[j + 1];
				p[j + 1] = work;
				work = rank[j];
				rank[j] = rank[j + 1];
				rank[j + 1] = work;
			} else if( (strcmp(s[j], s[j + 1]) == 0) && (p[j] < p[j + 1]) ) {
				strcpy(string, s[j]);
				strcpy(s[j], s[j + 1]);
				strcpy(s[j + 1], string);
				work = p[j];
				p[j] = p[j + 1];
				p[j + 1] = work;
				work = rank[j];
				rank[j] = rank[j + 1];
				rank[j + 1] = work;
			}
		}
	}
	for(i = 0; i < n; i++) {
		printf("%d\n", rank[i]);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for(int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if(k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<mint> z(n);
  combination c(2 * n);
  z[0] = 1;
  rep2(i, 1, n) {
    z[i] = c(n, i);
    z[i] *= c(n - 1, i);
  }
  mint ans = 0;
  rep(i, min(k + 1, n)) ans += z[i];
  if(k == 1)
    cout << ans.x - 1 << endl;
  else
    cout << ans.x << endl;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define tp tuple<int,int,int>
#define mtp make_tuple
using namespace std;

const int N=55;
int n,m,q,a[N],b[N],c[N],d[N],res,now[N];

void backtrack(int i)
{
    if(i>n)
    {
        int cost=0;
        for(int j=1;j<=q;j++) if(now[b[j]]-now[a[j]]==c[j]) cost+=d[j];
        res=max(res,cost);
        return ;
    }
    for(int j=max(1ll,now[i-1]);j<=m;j++)
    {
        now[i]=j;
        backtrack(i+1);
    }
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m>>q;
    for(int i=1;i<=q;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
    backtrack(1);
    cout<<res;
}


Measured memory_bytes: 3656
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]


def main():
    n=inp()
    st = inpls()
    s = st[0]
    t = st[1]
    ans = []
    for i in range(n):
        ans.append(s[i])
        ans.append(t[i])
    print(''.join(ans))
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 39148
// Problem: B - Product Max
// Contest: AtCoder - AtCoder Beginner Contest 178
// URL: https://atcoder.jp/contests/abc178/tasks/abc178_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ll long long int
#define vi vector<int>
#define vii vector<int, int>
#define vc vector<char>
#define vl vector<ll>
#define mod 1000000007 
#define INF 1000000009
using namespace std;


int main()
{
     ios_base::sync_with_stdio(0);
     cin.tie(0);
     cout.tie(0);
     
     ll a, b, c, d;
     cin >> a >> b >> c >> d;
     
     
     
     cout << max(a*c, max(a*d, max(b*c, b*d))) << "\n";

     
     
     
     
     
return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e5 * 3 + 10;
vector <ll> vec;
ll q;

int main() {
	fastInp;

	ll k;
	cin >> k;

	string curN = "1";
	for (int i = 1; i < k; i++) {
		if (i == 9) {
			cout << "";
		}
		int i2 = curN.size() - 1;
		while (i2 >= 0 && (curN[i2] == '9' || (i2 > 0 && abs(curN[i2] + 1 - curN[i2 - 1]) > 1))) i2--;

		if (i2 == -1) {
			curN.insert(curN.begin(), '1');
			i2++;
		}
		else {
			curN[i2]++;
		}

		for (int j = i2 + 1; j < curN.size(); j++) {
			curN[j] = max(char(curN[j - 1] - 1), '0');
		}

	}

	cout << curN;
	return 0;
}

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

using namespace std;

void p(const vector<int> &v)
{
    for (size_t i = 0; i < v.size() - 1; ++i) {
        printf("%d ", v[i]);
    }
    printf("%d\n", v[v.size() - 1]);
}

int main()
{
    int N;
    scanf("%d", &N);
    vector<int> v;
    int t;
    for (int i = 0; i < N; ++i) {
        scanf("%d", &t);
        v.push_back(t);
    }
    int c = 0;
    for (size_t i = 0; i < v.size() - 1; ++i) {
        for (size_t j = v.size() - 1; j >= i + 1; --j) {
            if (v[j] < v[j - 1]) {
                int tmp = v[j - 1];
                v[j - 1] = v[j];
                v[j] = tmp;
                ++c;
            }
        }
    }
    p(v);
    printf("%d\n", c);
}

Measured memory_bytes: 2764
N=int(input())
s=[list(input()) for _ in range(N)]

ct_a=0
ct_b=0
ct_ab=0
ct_ba=0

for i in range(N):
    if s[i][0]=='B' and s[i][-1]=='A':
        ct_ba+=1
    elif s[i][0]=='B':
        ct_b+=1
    elif s[i][-1]=='A':
        ct_a+=1
    for j in range(len(s[i])-1):
        if s[i][j]=='A' and s[i][j+1]=='B':
            ct_ab+=1

if ct_ba==0:
    print(ct_ab+min(ct_a, ct_b))
elif ct_a+ct_b>0:
    print(ct_ab+ct_ba+min(ct_a,ct_b))
else:
    print(ct_ab+ct_ba-1)

Measured memory_bytes: 47960
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define has_str(s, c)	((s).find(c) != string::npos)
typedef long long ll;
int main() {
#ifdef online_judge
    freopen("input.txt", "rt", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#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 ALL(a) a.begin(),a.end()

bool prime(int a){
    int roota = ceil(sqrt(a));
    if(a==2)return true;
    else{
        FOR(i,2,roota+1){
            if(a%i==0){
                return false;
            }
        }
    }
    return true;
}

int main()
{
    int X;
    cin >> X;
    //cout << prime(X) << endl;
    bool found = false;
    while(!found){
        found = prime(X);
        //cout << X << " " << found << endl;
        if(!found)X ++;
    }
    cout << X << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
int main(int argc, char const *argv[]) {
  int a, b, c;
  cin >> a >> b >> c;
  int count = (a != b) + (b != c) + (c != a);
  cout << max(count, 1) << endl;
  return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

bool dp[85][85][13005];

void solve(){
    int h,w;
    cin>>h>>w;
    vector<vector<int>>a(h,vector<int>(w)),b(h,vector<int>(w));
    rep(i,h)rep(j,w)cin>>a[i][j];
    rep(i,h)rep(j,w)cin>>b[i][j];
    dp[0][0][abs(a[0][0]-b[0][0])]=true;
    rep(i,h){
      rep(j,w){
        rep(k,13001){
        if(i-1>=0){
          dp[i][j][abs(k+a[i][j]-b[i][j])]|=dp[i-1][j][k];
          dp[i][j][abs(k+b[i][j]-a[i][j])]|=dp[i-1][j][k];
        }
        if(j-1>=0){
          dp[i][j][abs(k+a[i][j]-b[i][j])]|=dp[i][j-1][k];
          dp[i][j][abs(k+b[i][j]-a[i][j])]|=dp[i][j-1][k];
    }
      }
      }
    }
    rep(i,13001){
      if(dp[h-1][w-1][i]){
        cout<<i<<"\n";
        return;
      }
    }
}
 
int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 88320
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out = "";
    while (scanner.hasNext()) {
      int a = scanner.nextInt();
      int c = 0;
      if (a == 0 || a > 36) {
        out += "0\n";
        continue;
      }
      if (a == 36) {
        out += "1\n";
        continue;
      }
      for (int ii = 0; ii < 10; ii++) {
        for (int jj = 0; jj < 10; jj++) {
          for (int mm = 0; mm < 10; mm++) {
            for (int nn = 0; nn < 10; nn++) {
              if (ii + jj + mm + nn == a) {
                c++;
              }
            }
          }
        }
      }
      out += c + "\n";
    }
    System.out.print(out);
  }
}

Measured memory_bytes: 19660
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> v;
    
    for(int i = 1; i <= min(100, max(A, B)); i++){
        if(A % i == 0 && B % i == 0)    v.push_back(i);
    }
    
    sort(v.begin(), v.end(), greater<int>());
    
    cout << v[K - 1] << endl;
}

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

int main()
{
    ll n,t,a,b,c,d,e,p,q,cnt=0;
    map<ll,ll>mp;
    vector<ll>vec;
    string s,s1,s2;
    ll ac=0,tle=0,wa=0,re=0;
     cin>>n;
     ll arr[n+5];
     for(ll i=0;i<n;i++){
        cin>>arr[i];
     }

    for(ll i=0;i<n-1;i++){
        if(arr[i]>arr[i+1]){
            ll p=arr[i]-arr[i+1];
            cnt+=p;
            arr[i+1]+=p;
        }
    }
   cout<<cnt<<endl;

}


Measured memory_bytes: 5144
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.range;
import std.functional;
import std.algorithm;

void main() {
    int n, q; readf("%d %d\n", &n, &q);
    auto c = stdin.readln.chomp.split(" ").map!(to!int).array.sort;
    foreach (_; 0 .. q) {
        int query; readf("%d\n", &query);
        auto a = c.assumeSorted;
        int m = 0;
        for (int x = query; x <= c.back + query; x += query) {
            auto lbound = a.lowerBound(x);
            if (lbound.empty) continue;
            //writeln(x, "\t", a.lowerBound(x).back);
            m = max(m, lbound.back % query);
            if (m == query - 1) break;
        }
        m.writeln;
    }
}

Measured memory_bytes: 11424
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
using namespace std;

template <typename T>
using V = vector<T>;
using ll = long long;

#define SIZE(v) (static_cast<ll>((v).size()))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))

const double PI = acos(-1);


// BITオブジェクト、Range Maximum Queryバージョン
class BIT {
public:
    explicit BIT(ll N, ll v) : V_NUM(N) {
        data.resize(N);
        fill(ALL(data), v);
    }

    ll query(ll i) {
        ll ret = 0;
        while (i > 0) {
            ret = max(ret, data[i]);
            i -= (i & -i);
        }
        return ret;
    }

    void update(ll i, ll v) {
        while (i < V_NUM) {
            data[i] = max(data[i], v);
            i += (i & -i);
        }
    }

    ll V_NUM;
    V<ll> data;
};

// 座標(coordinate)を保持する構造体
struct coo {
    coo(ll _x = 0, ll _y = 0) : x(_x), y(_y){};
    ll x;
    ll y;
    
    // ソートするために比較演算子をオーバーロードする
    bool operator<(const coo& r) const {
        return x == r.x ? y < r.y : x < r.x;
    }
};

// Y座標で座圧をする
map<ll, ll> compress(const V<coo>& a) {
    set<ll> sety;
    for (coo c : a) {
        sety.insert(c.y);
    }

    map<ll, ll> ret;
    ll idx = 1;
    for (ll y : sety) {
        ret[y] = idx;
        ++idx;
    }

    return ret;
}

int main() {
    cout << fixed << setprecision(12);
  
    // startとgoal
    coo s, g;
    cin >> s.x >> s.y >> g.x >> g.y;

    // startの方が下にくるようにする
    if (s.y > g.y) swap(s, g);

    ll N;
    cin >> N;
    V<coo> a;
    // 長方形領域内にある噴水のみを記録する
    
    for (ll i = 0; i < N; ++i) {
        ll x, y;
        cin >> x >> y;
        if (y < s.y || g.y < y) continue;

        if (s.x < g.x) {
            if (s.x <= x && x <= g.x) {
                a.push_back(coo(x - s.x, y - s.y));
            }
        } else {
            // startとgoalのX座標が逆の場合はこっちも左右反転する
            if (g.x <= x && x <= s.x) {
                a.push_back(coo(s.x - x, y - g.y));
            }
        }
    }

    SORT(a);
    map<ll, ll> com = compress(a);

    BIT bit(SIZE(com) + 1, 0);

    for (coo c : a) {
        ll y = com[c.y];
        bit.update(y, bit.query(y) + 1);
        // bit.query(y)でy以下の最大値を求める
        // それに1加えた値で更新
    }

    // BIT全体の最大値が答え
    ll turn = bit.query(SIZE(com));

    double ans = (abs(g.x - s.x) + abs(g.y - s.y)) * 100;
    // 噴水を無視した場合の距離
    ans -= (20 - PI * 5) * turn;
    // 曲がる分だけ削れる
    
    // コーナーケース
    if (turn == abs(g.y - s.y) + 1 || turn == abs(g.x - s.x) + 1) ans += PI * 5;

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

Measured memory_bytes: 26092
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
int main(){
    string S, T;
    cin >> S;
    cin >> T;
    for(int i=0; i<S.size(); i++){
        S.insert(S.begin(), S[S.size()-1]);
        S.erase(--S.end());
        if(S == T){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//ここまでテンプレ
int main(){
	int N,K;
	cin>>N>>K;
	vll A={0};
	for(int i=0;i<N;i++){
		ll a;
		cin>>a;
		A.pb(a);
	}
	for(int i=1;i<=N;i++)
		A[i]+=A[i-1];
	vll v;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(i>j)
				continue;
			v.pb(A[j+1]-A[i]);
		}
	}
	sort(v.begin(),v.end());
	ll now=INF;
	ll ans=0;
	while(1){
		int bits[70]={};
		for(ll i:v){
			for(int j=0;j<62;j++){
				bits[j]+=!!((i>>j)&1);
			}
		}
		ll temp=INF;
		//K以上あるbitを見る
		for(ll i=min(62LL,now-1);i>=0;i--)
			if(bits[i]>=K){
				ans+=(1LL<<i);
				temp=i;
				break;
			}
		if(temp==INF)
			break;
		vll w;
		for(ll i:v)
			if((i>>temp)&1LL)
				w.pb(i);
		v=w;
		now=temp;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6556
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, n; cin >>  x >> n;
    vector<int> p(n); rep (i, p.size()) cin >> p[i];
    int ans = 10000;
    vector<bool> cont(103); rep (i, p.size()) cont[p[i]] = true;
    reprev (i, x + 1) {
        if (!cont[i]) {
            ans = i;break;
        }
    }
    rep (i, x + 1, 103) {
        if (!cont[i]) {
            if (x - ans > i - x) {
                ans = i; 
                break;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>

int main()
{
    int N;
    int i;
    long int sum = 0;
    scanf("%d",&N);
    for (i=1;i<=N;i++) {
        sum += i;
    }
    for (i=1;i<=N/3;i++) {
        sum -= 3*i;
    }
    for (i=1;i<=N/5;i++) {
        sum -= 5*i;
    }
    for (i=1;i<=N/15;i++) {
        sum += 15*i;
    }
    printf("%ld\n",sum);
    return 0;
}

Measured memory_bytes: 1728
package main

import (
	"fmt"
	"math/big"
)

func main() {
	var N int
	fmt.Scan(&N)
	a := make([]int64, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
		if a[i] == 0 {
			fmt.Println(0)
			return
		}
	}
	MAX := big.NewInt(1e18)
	p := big.NewInt(1)
	for i := 0; i < N; i++ {
		p.Mul(p, big.NewInt(a[i]))
		if p.Cmp(MAX) == 1 {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(p)
	return
}


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

#define REP(i, n) for(int i=0;i<(int)n;i++)
int n, m, k, x, ud;
double u[1500], d[1500], t[1500], l, f, D, v;
int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	while(cin >> n >> m >> k, n){
		REP(i, k+205) u[i] = d[i] = t[i] = 0;
		REP(i, n){
			cin >> x >> l >> f >> D >> ud; x += 100;
			u[x] = l / f;
			d[x] = l / D;
			t[x] = -u[x] - d[x];
			if(ud){
				swap(u[x], d[x]);
				t[x] += d[x];
			}
		}
		REP(i, m){
			cin >> v;
			for(int x=100-i+1;x<=200+k;x++){
				t[x] = max({t[x]+u[x]+d[x], t[x+1], t[x-1]+u[x-1]+1./v});
			}
		}
		printf("%.11f\n", t[100+k]);
	}
	return 0;
}

Measured memory_bytes: 1300
import sys
L,R = map(int,input().split())
for i in range(L,R+1):
    if i%2019 == 0:
        print(0)
        sys.exit()
l = L%2019
r = R%2019
c = []
for i in range(l,r):
    for j in range(i+1,r+1):
            a = (i*j)%2019
            c.append(a)
print(min(c))


Measured memory_bytes: 75412
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int count = 0;
    char[] c = scanner.nextLine().toCharArray();
    
    for(int i = 0; i < c.length; i++){
      if(c[i] == '1'){
        count++;
      }
    }
    System.out.println(count);
    scanner.close();
  }
}

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

public class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		operateStack ost = new operateStack();
		String[] str;
		int len, top = 0;
		long op, cal;
		
		str = br.readLine().split(" ", 0);
		len = str.length;
		
		for(int i = 0; i < len; i++){
			
			if(str[i].equals("+")){
				ost.calc(1);
			}
			else if(str[i].equals("-")){
				ost.calc(2);
			}
			else if(str[i].equals("*")){
				ost.calc(3);
			}
			else{
				op = Long.parseLong(str[i]);
				ost.push(op);
			}
		}
		
		System.out.println(ost.pop());
	}
}

class operateStack{
	long[] stack = new long[100];
	int top;
	
	operateStack(){
		for(int i = 0; i < 100; i++){
			stack[i] = 0;
		}
		top = 0;
	}
	
	void push(long op){
		if(top == 0 && stack[top] == 0){
			stack[top] = op;
		}
		else{
			top ++;
			stack[top] = op;
		}
	}
	
	long pop(){
		long op = stack[top];
		stack[top] = 0;
		
		if(top > 0){
			top --;
		}
		return op;
	}
	
	void calc(int flag){
		long op, op2;
		long cal;
		
		op = pop();
		op2 = pop();
		
		switch(flag){
		case 1:
			cal = op2 + op;
			break;
		case 2:
			cal = op2 - op;
			break;
		default:
			cal = op2 * op;
			break;
		}
		
		push(cal);
	}
}

Measured memory_bytes: 24356
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1e18;

int n;
vector< vector<long long> > a(330, vector<long long>(330, 0));
vector< vector<long long> > dp(330, vector<long long>(330, INF));

int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> a.at(i).at(j);
        }
    }
    
    for(int k = 0; k < n; ++k) {
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                chmin(dp[i][j], a[i][k]+a[k][j]);
            }
        }
    }

    bool flg = true;
    long long ans = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = i+1; j < n; ++j) {
            if(a[i][j] > dp[i][j]) {
                flg = false;
                break;
            }else {
                long long alen = INF;
                for(int k = 0; k < n; ++k) {
                    if(i != k && j != k) {
                        chmin(alen, a[i][k]+a[k][j]);
                    }
                }
                if(alen > dp[i][j]) {
                    ans += dp[i][j];
                }
            }
        }
    }

    if(flg) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef pair<long long,long long> pll;
typedef long long ll;
const int inf   = 1<<29;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

vector<pll> v[100001];
bool used[100001];
ll d[100001];

void dfs(int x){
	rep(i,v[x].size()){
		if(!used[v[x][i].first]){
			used[v[x][i].first]=true;
			d[v[x][i].first]=d[x]+v[x][i].second;
			dfs(v[x][i].first);
		}

	}
}

int main(){
	int n,m;
	cin>>n>>m;
	int l[m],r[m],dist[m];
	rep(i,m){
		cin>>l[i]>>r[i]>>dist[i];
		v[l[i]].push_back(pll(r[i],dist[i]));
		v[r[i]].push_back(pll(l[i],-dist[i]));
	}
	rep(i,n)used[i+1]=false;
       rep(i,n)if(!used[i+1]){ used[i+1]=true;dfs(i+1);};
	bool ans=true;
	rep(i,m){
		if(d[r[i]]-d[l[i]]!=dist[i])ans=false;
	}
	if(ans)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;

	}


Measured memory_bytes: 18944
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x[3];cin>>x[0]>>x[1]>>x[2]; sort(x,x+3);
  cout<<(x[0]==x[2]||(x[0]!=x[1]&&x[1]!=x[2])?"No":"Yes");
}

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

int Prime[1000000];

int main() {
	for(int i=0;i<1000000;++i)Prime[i]=1;
	
	Prime[0]=0;
	Prime[1]=0;
	
	for(int i=2;i<1000000;++i){
		if(Prime[i]){
			for(int j=i*2;j<1000000;j+=i){
				Prime[j]=0;
			}
		}
	}
	
	int n,cnt;
	while(cin>>n){
		cnt = 0;
		for(int i=0;i<=n;++i){
			cnt+=Prime[i];
		}
		cout<<cnt<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 5064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

ll dp[110][2][5];

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s;
    int x;
    cin>>s>>x;
    int n=s.size();
    dp[0][0][0]=1;
    rep(i,n)rep(j,2)rep(k,x+1){
        int now=s[i]-'0';
        rep(ne,10){
            int ni=i+1,nj=j,nk=k;
            if(!j && ne>now) continue;
            if(k==x && ne) continue;
            if(ne<now) nj=1;
            if(ne) nk++;
            dp[ni][nj][nk]+=dp[i][j][k];
        }
    }
    cout<<dp[n][0][x]+dp[n][1][x]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int A, B;
  cin >> A >> B;
  cout << 6 - A - B << endl;
  return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int b=0,c=0,e=0,f=0;
  string a,d;
  cin>>a;
  d=a;
  fo(i,a.size()){
    if(a[i]=='A')
       a.erase(a.begin()+i);
  }
  if(a!="KIHBR")
    cout<<"NO"<<endl;
  else{
    a=d;
  for(int i=0;i<6;i=i){
    if(i==5&&i+b<a.size()){
      f++;
      b++;
      if(f>1)
        break;
      if(i+b==a.size()){
        e=1;
        break;
      }
    }
    else if(i+b==a.size()){
      e=1;
      break;
    }
    else{
    if(a[i+b]=='A'){
      b++;
      c++;
      if(i==1||i==2)
        break;
      if(c==2)
      break;
    }
    else{
      i++;
      c=0;
    }
    }
  }
    if(e)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
using namespace std;
typedef long long ll;
int main() {
  ll n, k;
  cin >> n >> k;
  ll mx = (n - 1) * (n - 2) / 2;
  if (mx < k) {
    cout << -1 << endl;
    return 0;
  }
  vector<pair<ll, ll>> ans;
  REP(i, n - 1) { ans.push_back(make_pair(i + 1, n)); }
  ll add = mx - k;
  vector<pair<ll, ll>> edge;
  REP(i, n - 1) REP(j, i) edge.push_back(make_pair(i + 1, j + 1));
  REP(i, add) ans.push_back(edge[i]);
  cout << ans.size() << endl;
  REP(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }

  return 0;
}

Measured memory_bytes: 512
<?php
class GoldenApple {
    var $N, $D;
    
    function __construct() {
        list($this->N, $this->D) = explode(" ", trim(fgets(STDIN)));
    }

    function __invoke() {
        return intdiv($this->N, $this->D * 2 + 1) + ($this->N % ($this->D * 2 + 1) !== 0);
    }
}

$GoldenApple = new GoldenApple;
echo $GoldenApple();


Measured memory_bytes: 4728
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> Graph;

int dfs(Graph& g, VI& ord, VI& low, int& k, int p, int u) {
  int bridge = 0;
  ord[u] = k++;
  low[u] = ord[u];
  for (int v : g[u]) {
    if (ord[v] < 0) {
      bridge += dfs(g, ord, low, k, u, v);
      low[u] = min(low[u], low[v]);
      if (ord[u] < low[v]) bridge++;
    }
    else if (v != p) {
      low[u] = min(low[u], ord[v]);
    }
  }
  return bridge;
}

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

  VI ord(N, -1), low(N);
  int k = 0;
  cout << dfs(g, ord, low, k, -1, 0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 300010;
int ans[N];
int main() {
	int n, m; scanf("%d%d",&n,&m);
	rep(i,1,n) {
		ans[1]++;
		int a, b; scanf("%d%d",&a,&b); a--;
		for(int l = 1, r; l <= a && l <= b; l = r + 1) {
			r = min(a / (a / l), b / (b / l));
			if (a / l == b / l) ans[l]--, ans[r + 1]++;
		}
		ans[b + 1]--;
	}
	rep(i,1,m) ans[i] += ans[i - 1];
	rep(i,1,m) printf("%d\n",ans[i]);
}

Measured memory_bytes: 1280
n = gets.to_s.to_i
edges = Array.new(n-1){ gets.to_s.split.map{|t|t.to_i} }

g = Array.new(n+1){ [] }
edges.each do |u, v, c|
  g[u] << [v, c]
  g[v] << [u, c]
end

ans = Array.new(n+1){ 0 }
used = Array.new(n+1){ false }

q = [1]
used[1] = true

while q.any?
  
  v = q.shift
  parent_color = ans[v]
  g[v].each do |(u, c)|
    next if used[u]
    used[u] = true
    ans[u] = ( c.even? ? parent_color : 1 - parent_color )
    q.push u
  end
end

puts ans[1, n]

Measured memory_bytes: 29436
#include<bits/stdc++.h>
using namespace std;
 
long long calc(int n, int c1, int c2, int s1, int s2, const vector<int>& options,
               int d, int nt, int ot) {
  int b1(d-1), a1(d+1), b2(d-1), a2(d+1);
  while (b1 >= 0 && options[b1] != nt) b1--;
  while (b2 >= 0 && options[b2] != ot) b2--;
  while (a1 < n && options[a1] != nt) a1++;
  while (a2 < n && options[a2] != ot) a2++;
  int x1(d-b1-1), y1(a1-d-1), z1(a1-b1-1), x2(d-b2-1), y2(a2-d-1), z2(a2-b2-1);
  int diff1 = z1*(z1+1)/2-x1*(x1+1)/2-y1*(y1+1)/2;
  int diff2 = z2*(z2+1)/2-x2*(x2+1)/2-y2*(y2+1)/2;
  return (long long) diff1 * c1 - (long long) diff2 * c2 + s1 - s2;
}
unsigned int myrand(){
	static unsigned int x=192047155,y=392751284,z=194681846,w=193571838;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return w=(w^(w>>19))^(t^(t>>8));
}
bool check(int diff, int time) {
  return diff >= 0 || myrand() >= (-diff) * (clock()-time) * 1.4;
}

int main() {
  int n;
  cin >> n;
  vector<int> c(26), last(26, -1);
  vector<array<int, 26>> s(n);
  
  for (int i = 0; i < 26; ++i) cin >> c[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 26; ++j)
      cin >> s[i][j];
  
  long long total(0);
  vector<int> options(n);
  
  for (int i = 0; i < n; ++i) {
    int neg(0), test(-1), max_score(-1e9);
    for (int j = 0; j < 26; ++j) neg -= c[j] * (i - last[j]);
    for (int j = 0; j < 26; ++j) {
      int ss = s[i][j] + neg + c[j] * (i - last[j]);
      if (ss > max_score) {
        max_score = ss;
        test = j;
      }
    }
    total += max_score;
    options[i] = test;
    last[test] = i;
  }
  
  // stochastic
  time_t time = clock();
  while ((clock()-time)<=1.91*CLOCKS_PER_SEC) {
    if (myrand() & 1) {
      int dd(myrand() % n), ot(options[dd]), tt;
      do { tt = myrand() % 26; } while (ot == tt);
      
      options[dd] = tt;
      long long ns = calc(n, c[tt], c[ot], s[dd][tt], s[dd][ot],
                          options, dd, tt, ot);
      
      if (check(ns,time)) {
        total += ns;
      } else {
        options[dd] = ot;
      }
    } else {
      int dd1 = myrand() % n;
      int ot1 = options[dd1];
      int dd2, ot2;
      do { dd2 = myrand() % n; ot2 = options[dd2]; } while (ot1 == ot2);
      
      options[dd1] = ot2;
      long long ns1 = calc(n, c[ot2], c[ot1], s[dd1][ot2], s[dd1][ot1],
                          options, dd1, ot2, ot1);
      options[dd2] = ot1;
      long long ns2 = calc(n, c[ot1], c[ot2], s[dd2][ot1], s[dd2][ot2],
                          options, dd2, ot1, ot2);
      
      if (check(ns1+ns2,time)) {
        total += ns1 + ns2;
      } else {
        options[dd1] = ot1;
        options[dd2] = ot2;
      }
    }
  }
  
  for (const int& i: options) cout << i + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 3708
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
#define N 300010
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int l[N],r[N],t[N],x[N],n,L; bool vis[N];
int main()
{
	n=read(),L=read(); ll ans=n;
	for(int i=1;i<=n;i++)	x[i]=read();
	for(int i=1;i<=n;i++)	t[i]=read();
	for(int i=1;i<=n;i++)
	{
		ans+=t[i]/(2*L),t[i]%=(2*L);
		if(!t[i])	ans--,vis[i]=1;
		else
		{
			r[i]=t[i]<=2*(L-x[i]),l[i]=t[i]<=2*x[i];
			if(!l[i]&&!r[i])	t[i]=0,vis[i]=1; 
		}
	}
	int pos=1;
	while(pos<n && !(l[pos]&&!r[pos]))	pos++;
	int tot=0,top=0;
	for(int i=1;i<pos;i++)	if(!vis[i])
	{
		if(!l[i]){if(top)	top--,ans--;}
		else	top++;
	}
	tot+=top,top=0;
	for(int i=n-1;i>=pos;i--) if(!vis[i])
	{
		if(!r[i]){if(top)	top--,ans--;}
		else	top++; 
	}
	tot+=top; ans-=tot>>1;
	if(!r[n])	ans++;
	printf("%lld\n",ans*2*L);
	return 0;
}

Measured memory_bytes: 5120
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    int N, K; cin >> N >> K;
    VD dsum(N+1);
    dsum[0] = 0;
    REP(i, N){
        int p; cin >> p;
        dsum[i+1] = dsum[i] + (double)(p+1) / 2;
    }
    double ans = 0;
    FORS(i, K, N){
        chmax(ans, dsum[i] - dsum[i-K]);
    }
    cout << fixed << setprecision(8) << ans << endl;
    return 0;
}


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

int main()
{
  int n;
  cin>>n;
  int a;
  int i;
  int disc=0;
  int k=1;
  for(i=0;i<n;i++)
  {
    cin>>a;
      if(a!=k)
        disc++;
      else k++;
  }
  if(disc>n-1)
    cout<<-1<<endl;
  else cout<<disc<<endl;
  return 0;
}

Measured memory_bytes: 256
A = input()

dp = [0]*len(A)
dp[0] = 1
dic = {chr(ord('a')+i):0 for i in range(26)}
dic[A[0]] += 1

for i in range(1,len(A)):
  dp[i] = dp[i-1] + i - dic[A[i]]
  dic[A[i]] += 1
  
print(dp[-1])

Measured memory_bytes: 75276
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#define INF 0X3F3F3F3F
#define N 1005
#define M 200005
#define LL long long
#define ULL unsigned long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mid + 1, r
#define VI vector<int>
#define db double
#define PII pair<int, int>
#define PLL pair<unsigned long long, unsigned long long>
#define MP make_pair
#define PB push_back
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
LL n, m, s;
int main(){
   // IN;
    cin >> n >> m;
    if(n == 1){
        if(m == 1) s = 1;
        else s = m - 2;
    }else {
        if(m == 1) s = n - 2;
        else s = (n - 2) * (m - 2);
    }
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int dp[45];
  int n;
  dp[1]=1;
  dp[0]=1;
  for(int i=2;i<45;i++){
    dp[i]=dp[i-1]+dp[i-2];
  }
  cin>>n;
  cout<<dp[n]<<endl;
  return 0;
}



Measured memory_bytes: 3096
def solve():
    n = int(input())
    s = []
    ans = 0
    acnt = 0
    bcnt = 0
    bacnt = 0
    for i in range(n):
        s_i = input()
        ans += s_i.count('AB')
        s_i.replace('AB', '')
        if s_i[0] == 'B' and s_i[-1] == 'A':
            bacnt += 1
        elif s_i[0] == 'B':
            bcnt += 1
        elif s_i[-1] == 'A':
            acnt += 1

    # bacntをa,bに変換
    if bacnt == 0:
        ans += min(acnt, bcnt)
    elif acnt == 0 and bcnt == 0:
        ans += bacnt-1
    else:
        ans += bacnt + min(acnt, bcnt)

    print(ans)

solve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 10;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
  COMinit();
  int x,y;
  cin>>x>>y;
  if((x+y)%3!=0)
  {
      cout<<0<<endl;
      return 0;
  }

  long long n,m;
  n=(2*y-x)/3;
  m=(2*x-y)/3;

  if(n<0 || m<0)
  {
      cout<<0<<endl;
      return 0;
  }
  else
  {
      long long count = COM(n+m,m);
      cout<<count<<endl;
  }
    

    
  return 0;
}

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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int N, c=0, c2 = 0 , tmp;
	cin >> N;
	REP(i, 0, N){
		cin >> tmp;
		if(tmp % 4 == 0) ++c;
		else if(tmp % 2 == 0) ++c2;
	}
	cout << (c+1 >= N-c-(c2 > 0?c2-1:0)?"Yes":"No");
	/*if(c2 == 0) cout << (c+1 >= N-c-c2+1?"Yes":"No");
	else if(c >= N-c+c2) cout << "Yes";
	else cout << "No";*/

}


Measured memory_bytes: 256