akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n];
    int dp[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        dp[i]=INT_MAX;
    }
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+2;j++){
            if(j<n){
                dp[j] = min(dp[j], dp[i] + abs(arr[i] - arr[j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  string s;
  cin>>s;
  map<char,int> map1;
  for(char c:s)
  {
    map1[c]++;
  }
  int a=min(map1['0'],map1['1']);
  cout<<2*a<<endl;


  return 0;

}


Measured memory_bytes: 512
import sys

SUITS = ['S', 'H', 'C', 'D']
exist_cards = {suit:[] for suit in SUITS}

n = input()

for line in sys.stdin:
    suit, number = line.split()
    exist_cards[suit].append(int(number))


for suit in SUITS:
    for i in range(1, 14):
        if i not in exist_cards[suit]:
            print(suit, i)

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

int main() {

    int n , u , k , s;
    cin>> n ;
    vector<vector<int> > v(n,vector<int>(n,0));
    for(int i=0;i<n;i++){
    cin >> u >> k;
    for(int r=0;r<k;r++){
        cin >> s;
        v[u-1][s-1] = 1;

    }
    }
    for(int i=0;i<n;i++){

        for(int r=0;r<n;r++){
            cout << v[i][r] ; 
            if(r==n-1){}
            else {cout << " " ;}
        }
        cout << endl;
    }
}



Measured memory_bytes: 3152
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n, k;
    cin >> n >> k;
    string s; cin >> s;
    s[k-1] = tolower(s[k-1]);
    cout << s << endl;
    return 0;
}




























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 998244353

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

long long bipow(long long n, int m) {
    if (m == 0) return 1;
    if (m % 2 == 0) {
        n = (n * n) % MOD;
        return bipow(n, m / 2) % MOD;
    } else
        return (n * bipow(n, m - 1)) % MOD;
}

// 1-indexed
template <class X>
class FenwickTree {
    int n;
    vector<X> a;
public:
    FenwickTree(int n) : n(n), a(n+1, 0) {}
    X get(int i) {
        X sm = 0;
        for(; i > 0; i -= i&-i) sm += a[i];
        return sm;
    }
    void add(int i, X x) {
        for(; i <= n; i += i&-i) a[i] += x;
    }
    X at(int i){return get(i) - get(i-1);}
};

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> xy(N);
    vector<int> ys(N);
    REP(i, N){
        int x, y;
        cin >> x >> y;
        xy[i] = make_pair(x, y);
        ys[i] = y;
    }
    map<int, int> mp;
    sort(ys.begin(), ys.end());
    for(int y : ys) mp[y] = mp.size() + 1;
    for(auto &z : xy){
        z = make_pair(z.first, mp[z.second]);
    }
    sort(xy.begin(), xy.end());

    FenwickTree<int> A(N+10), B(N+10);
    A.add(xy[0].second, 1);
    REP(i, 1, N) B.add(xy[i].second, 1);
    long long ans = 0;
    for(int i=1; i<N-1; i++){
        int y = xy[i].second;
        B.add(y, -1);

        int a0 = A.get(y);
        int b0 = A.get(N+10) - a0;
        int b1 = B.get(y);
        int a1 = B.get(N+10) - b1;
        long long a0pow = bipow(2, a0);
        long long a1pow = bipow(2, a1);
        long long b0pow = bipow(2, b0);
        long long b1pow = bipow(2, b1);
        long long tmp0 = ((a0pow-1)*(a1pow-1))%MOD;
        long long tmp1 = ((b0pow-1)*(b1pow-1))%MOD;
        long long tmp2 = (tmp0 * tmp1) % MOD;
        tmp0 = (tmp0 * b0pow) % MOD;
        tmp0 = (tmp0 * b1pow) % MOD;
        tmp1 = (tmp1 * a0pow) % MOD;
        tmp1 = (tmp1 * a1pow) % MOD;
        long long tmp4 = (tmp0 + tmp1) % MOD;
        tmp4 += MOD - tmp2;
        tmp4 %= MOD;
        ans = (ans + tmp4) % MOD;

        A.add(y, 1);
    }
    ans += (N * bipow(2, N-1)) % MOD;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13568
#include "bits/stdc++.h"

using namespace std;

#define Rep(b, e, i) for (ll i = b; i <= e; i++)
#define Repr(e, b, i) for (ll i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T, vector<T>, greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false) std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<vec> mat;
typedef vector<vecll> matll;
typedef vector<vecd> matd;

template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
	o << "{";
	for (int i = 0; i < (int)v.size(); i++)
		o << (i > 0 ? ", " : "") << v[i];
	o << "}";
	return o;
}

const int MAX = 1000010;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const ll INFL = 1e15;
const ll MOD = 1e9+7;

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

//********************************template END****************************************//

const int MAX_V = 2525;
const int MAX_E = 5252;

struct edge {int from, to; ll cost;};

edge es[MAX_E];

int go[MAX_V];
ll dis[MAX_V];
ll V, E, P;
//ゴールに続く負の閉路が存在すればtrueを返す
bool bellmanford(int s) {
	rep(V, v) dis[v] = INFL;
	dis[s] = 0LL;
	rep(V, i) {
		rep(E, e) {
			const edge &ne = es[e];
			if (dis[ne.from] == INFL) continue;
			if (dis[ne.to] > dis[ne.from] + ne.cost + P) {
				dis[ne.to] = dis[ne.from] + ne.cost + P;
				if (i == V-1 && go[ne.to] == 1) return true;
			}
		}
	}
	return false;
}

void solve(void){
    cin >> V >> E >> P;
    rep(E, e){
        int a, b;ll c;
        scanf("%d %d %lld\n", &a, &b, &c);
        a--; b--;
        es[e] = edge {a, b, -c};
    }
	queue<int> q;
	q.push(V-1);
	memset(go, -1, sizeof(go));
	go[V-1] = 1;
	while(!q.empty())
	{
		int v = q.front();
		q.pop();
		rep(E, e) {
			const edge &ne = es[e];
			if (go[ne.from] == -1 && ne.to == v)
			{
				go[ne.from] = 1;
				q.push(ne.from);
			}
		}
	}
    if (bellmanford(0)) cout << "-1" << endl;
    else cout << max(0LL, -dis[V-1]) << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)    for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define rrep(i, n)   for(int i=(n-1); i>=0; --i)
#define all(v)       v.begin(), v.end()
#define rall(v)      v.rbegin(), v.rend()
#define int          long long
template<typename T>
using vv  = vector<vector<T>>;
using vi  = vector<int>;
using vvi = vector<vector<int>>;
using P   = pair<int, int>;
using ll  = long long;
constexpr ll INF = 1LL << 60;

signed main(){

    int a, v;
    int b, w;
    int t;

    cin >> a >> v >> b >> w >> t;
    
    if(a == b){
        cout << "YES" << endl;
    }
    else if(a < b){
        int x = a + v * t;
        int y = b + w * t;
        if(x >= y){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    else{
        int x = a - v * t;
        int y = b - w * t;
        if(x <= y){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define REP(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define REPS(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define RREP(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define RREPS(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define BIT(n) ((int)(1) << (n))
#define ALL(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
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;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n, m, k;
    cin >> n >> m >> k;
    std::vector<int> a(n);
    std::vector<int> b(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    std::vector<int> suma(n + 1, 0);
    int out = 0;

    for (int i = 1; i <= n; i++) {
        suma[i] = suma[i - 1] + a[i - 1];
    }
    int sumb = 0;
    int idx = 0;

    for (int i = 0; i <= n; i++) {
        if (suma[n - i] + sumb > k) {
            continue;
        }
        while (idx < m && suma[n - i] + sumb + b[idx] <= k) {
            sumb += b[idx];
            idx++;
        }

        if (chmax(out, idx + n - i)) {
        }
    }

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

Measured memory_bytes: 7940
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

int main() {
    int n, m;
    cin >> n >> m;
    vi k(m);
    vvi s(m);
    for (int i = 0; i < m; ++i) {
        cin >> k[i];
        s[i].resize(k[i]);
        for (int j = 0; j < k[i]; ++j) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vi p(m);
    for (int i = 0; i < m; ++i) {
        cin >> p[i];
        p[i] %= 2;
    }
    ll ret = 0;
    for (int i = 0; i < (1 << n); ++i) {
        int ok = 0;
        for (int j = 0; j < m; ++j) {
            int on = 0;
            for (auto ss : s[j]) {
                if ((1 << ss) & i)
                    on++;
            }
            if (on % 2 == p[j])
                ok++;
        }
        if (ok == m)
            ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
N,M=list(map(int,input().strip().split(' ')))
graph=[[] for i in range(N)]
for _ in range(M):
    a,b=list(map(int,input().strip().split(' ')))
    a-=1
    b-=1
    graph[a]+=[b]
    graph[b]+=[a]
from collections import deque

q=deque([0])

visit=[0]*N
level=[0 for i in range(N)]
level[N-1]=3
parent=[-1]*N
while q:
    v=q.popleft()
    visit[v]=1
    for adj in graph[v]:
        if adj!=parent[v] and visit[adj]==0:
            parent[adj]=v
            visit[adj]=1
            q+=[adj]
            level[adj]=level[v]+1
if level[N-1]<=2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
    

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll x, y; cin >> x >> y;
  ll cnt = 1;
  while (x * 2 <= y) {
    cnt++;
    x *= 2;
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3608
n,k=map(int,input().split())
nohave=[True]*n
for i in range(k):
    d=int(input())
    A=list(map(int,input().split()))
    for a in A:
        nohave[a-1]=False

ans = 0
for i in range(n):
    if nohave[i]==True:
        ans +=1

print(ans)



Measured memory_bytes: 9180
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


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

	ll a, b;
	cin >> a >> b;
	if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
		cout << a * b << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

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

int main()
{
    float n,k;
    float l = 0;
    double ans=0;
    cin>>n>>k;

    cout<<setprecision(60);

    for(int i=1;i<=n;i++)
    {

        double h = k/i;
        double m = ceil(log2(h));
        if(m<=0)
        {

            m=1;
        }
        //cout<<h<<" "<<m<<endl;
        double j = 1/pow(2,m);
        if(k<=i)
        {

            j=1;
        }
        //cout<<j<<endl;


        ans+=j;
    }
    cout<<ans/n;

}


Measured memory_bytes: 256
program management;
var
    n, i, x : longint;
    list : array[1..200000] of longint;

begin
    readln(n);
    for i in list do
        list[i] := 0;
    for i := 2 to n do begin
        read(x);
        list[x] += 1;
    end;
    for i := 1 to n do begin
        writeln(list[i]);
    end;
end.

Measured memory_bytes: 1396
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int N,M; char S[1010]; int D[1010][1010];
const int mod = 1000000007;

int main()
{
	scanf ("%d %d",&N,&M);
	D[0][0] = 1;
	for (int i=0;i<N;i++){
		scanf ("%s",S);
		for (int j=0;j<M;j++) if (S[j] == '.'){
			if (i) D[i][j] = (D[i-1][j] + D[i][j]) % mod;
			if (j) D[i][j] = (D[i][j-1] + D[i][j]) % mod;
		}
	}
	printf ("%d\n",D[N-1][M-1]);

	return 0;
}

Measured memory_bytes: 4096
#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()
#define rall(x) (x).rbegin(), (x).rend()
#define itn long long

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  vector<int> v(3, 0);
  cin >> v[0] >> v[1] >> v[2];
  sort(all(v));
  if(v[0] + v[1] == v[2]) cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int temp=0,mix=99999,p=1,m;
	for(int i=0;i<a.size()-2;i++)
	{
		for(int j=i+2;j>=i;j--)
		{
			m=(a[j]-'0')*p;
			temp+=m;
			p*=10;
		}
		p=1;
		if(mix>abs(temp-753))
		{
			mix=abs(temp-753);
		}
		temp=0;
	}
	cout<<mix;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
template<typename T>
struct SegmentTree{
private:
    int n;
    vector<T> node;
public:
    T merge(T x,T y){
        return max(x,y);
    }
    SegmentTree(vector<T> v){
        int sz=(int)v.size();
        n=1; while(n<sz)n*=2;
        node.resize(2*n-1,0);
        for(int i=0;i<sz;i++) node[i+n-1]=v[i];
        for(int i=n-2;i>=0;i--){
            node[i]=merge(node[2*i+1],node[2*i+2]);
        }
    }
    void update(int x,T val){
        x+=(n-1);
        node[x]=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=merge(node[2*x+1],node[2*x+2]);
        }
    }
    T query(int a,int b,int idx=0,int l=0,int r=-1){ /* get [a,b) */
        if(r<0) r=n;
        if(r<=a||b<=l) return 0;
        if(a<=l&&r<=b) return node[idx];
        T vl=query(a,b,2*idx+1,l,(l+r)/2);
        T vr=query(a,b,2*idx+2,(l+r)/2,r);
        return merge(vl,vr);
    };
    int operator[](int k){return node[k+n-1];}
};
signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n,query; cin >> n >> query;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    SegmentTree<ll> seg(a);
    while(query--){
        int t; cin >> t;
        if(t==1){
            int x; ll v;
            cin >> x >> v;
            seg.update(x-1,v);
        }else if(t==2){
            int l,r; cin >> l >> r;
            cout << seg.query(l-1,r) << "\n";
        }else{
            int x; ll v;
            cin >> x >> v;
            if(seg.query(x-1,n)<v){
                cout << n+1 << "\n";
                continue;
            }
            if(v<=seg[x-1]){
                cout << x << "\n";
                continue;
            }
            int l=x-1,r=n;
            while(r-l>1){
                int mid=(l+r)/2;
                if(v<=seg.query(x-1,mid+1)) r=mid;
                else l=mid;
            }
            cout << r+1 << "\n";
        }
    }
}




Measured memory_bytes: 10292
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *parent;
  struct node *right;
  struct node *left;

  int key;
};
typedef struct node * Node;

Node root;

Node Minimum(Node x);
Node Search(Node u, int k);
Node Successor(Node x);
void Delete(Node z);
void insert(int k);
void inorder(Node u);
void preorder(Node u);

 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = Search(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      Delete(Search(root, x));
    }
  }
 
  return 0;
}

Node Minimum(Node x){
 
  while(x->left!=NIL){
    x=x->left;
  }
 
  return x;
 
}

Node Search(Node u, int k){
 
  if(u==NIL || k==u->key) return u;
  if(k<u->key) return Search(u->left,k);
    else return Search(u->right,k);
}

Node Successor(Node x){
 
  if (x->right!=NIL) return Minimum(x->right);
     
  root=x->parent;
 
  while(root!=NIL && x==root->right){
    x=root;
    root=root->parent;
  }
  return root;
}

void Delete(Node z){
  Node y; 
  Node x;
 
  if(z->left==NIL || z->right==NIL){ y=z;
   }
  else y=Successor(z);
  
  if(y->left!=NIL) {x=y->left;
   }
  else x=y->right;
 
  if(x!=NIL) {x->parent=y->parent;
    }
  if(y->parent==NIL){ root=x;
    }
  else if(y==y->parent->left) {y->parent->left=x;
    }
  else y->parent->right=x;
 
  if(y!=z) {z->key=y->key;
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x!=NIL){
    y=x;
    if(z->key<x->key) x=x->left;
    else x=x->right;
    z->parent=y;
  }
 
    if(y==NIL) root=z;
    else if (z->key<y->key)
         y->left=z;
    else y->right=z;
 
}

void inorder(Node u){
 
  if(u!=NIL) {
 
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
 
  }
 
}


void preorder(Node u){
 
  if(u!=NIL){
 
  printf(" %d",u->key);
 preorder(u->left);
 preorder(u->right);
 
  }
 
}
 



Measured memory_bytes: 20456
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE




void solve(void)
{
  int N,A,B;
  cin>>N>>A>>B;
  int Q = N/(A+B);
  int R = N%(A+B);
  cout<<Q*A + min(A,R)<<endl;;
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
X = [int(x) for x in input().split()]
ans = 0
for x,y in zip(X[:N-1],X[1:]):
    if (y-x) * A < B:
        ans += (y-x) * A
    else:
        ans += B
print(ans) 

Measured memory_bytes: 19920
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
  int n,a;
  double ans = 0.0;
  cin >> n;
  rep(i,n){
    cin >> a;
    ans += (double)(1) / (double)(a);
  }
  cout << setprecision(10) << (double)(1) / (double)(ans) << endl;
}








































//以下、ライブラリ
//ユークリッドの互除法

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
}



Measured memory_bytes: 256
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    A = [0] * N
    for i in range(N):
        A[i] = int(input())

    c = Counter(A)
    ans = 0
    for v in c.values():
        if v % 2 == 1:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16624
r, c = map(int, input().split())
mathlist = []
for x in range(r):
    mathlist.append(list(map(int, input().split())))

mathlist_change = list(map(list, zip(*mathlist)))
mathlist_last = 0

for y in mathlist:
    for z in y:
        print('{a} '.format(a=z), end='')
    print(sum(y))

for i in mathlist_change:
    print('{b} '.format(b=sum(i)), end='')
    mathlist_last += sum(i)

print(mathlist_last)



Measured memory_bytes: 6260
//Bismillah
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n,c=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {

     for(int j=i+1;j<n;j++)
     {

         for(int k=j+1;k<n;k++)
         {
             if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
             {
                 int m=max(a[i],max(a[j],a[k]));
                 if(a[i]==m&&a[i]<a[j]+a[k])
                    c++;
                 else if(a[j]==m&&a[j]<a[i]+a[k])
                    c++;
                else if(a[k]==m&&a[k]<a[j]+a[i])
                    c++;
             }



         }
     }





    }
    cout<<c<<endl;


}
//Alhamdulillah






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

int main() {
	string s;
	while (cin >> s, s != "0") {
		int a = 0, b = 0;
		for (int i = 1; i < s.size(); i++) {
			if (s[i] == 'A')a++;
			else b++;
		}
		if (a > b)a++; else b++;
		cout << a << ' ' << b << endl;
	}
}

Measured memory_bytes: 3044
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
	uint N;
	cin >> N;
	
	bool all_match = true;
	vector<uint> A(N);
	
	for(int i=1; i<=N; i++) {
		cin >> A[i-1];
		all_match &= (A[i-1] == i);
	}
	
	if(all_match) {
		cout << 0;
		return 0;
	}
	
	int ans = 0;
	int k = 1;
	
	for(int i=0; i<N; i++) {
		if(A[i] != k) {
			ans++;
		} else {
			k++;
		}
	}
	

	if(k == 1) {
		cout << -1;
	} else {
		cout << ans;
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){

    int i, j, k, n, x, sum = 0, count = 0;

    while(1) {

        count = 0;
        
        scanf("%d %d", &n, &x); 
        if (n == 0 && x == 0) {
            break;
        }

        for(i = 1; i <= n-2; i++){
            for(j = i+1; j <= n-1; j++){
                for(k = j+1; k <= n; k++){
                    sum = i+j+k;
                    if (sum == x) {
                        count++;
                    }

                }
            }
        }

        printf("%d\n", count);
    }

    return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int inout(int n){
  cout << n << endl;
  string res;
  cin >> res;
  if(res == "Male") return 1;
  if(res == "Female") return -1;
  return 0;
}

int main(){
  int n;
  cin >> n;
  int li = 0;
  int lv = inout(li);
  if(lv == 0) return 0;
  int ri = n-1;
  int rv = inout(ri);
  if(rv == 0) return 0;
  rep(i, 18){
    int mid = (li+ri)/2;
    int res = inout(mid);
    if(res == 0) break;
    int d = mid - li;
    if(((d % 2 == 1) ^ (res == lv)) == true){
      li = mid; lv = res;
    }else{
      ri = mid; rv = res;
    }
  }
  return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

Int a, b, c;
Int x;
Int ans = 0;
Int dfs(Int i, Int k, Int s, Int t){
  if(s > a) return -1;
  if(t == x) return -1;
  if(i == 41 && k == 0) {
    Min(ans, a - s);
    return 0;
  }
  //pr(a, b, c, x, i, k, s, t);
  if((c>>i&1) == 0){//00 or 11
    if(k != (x>>i&1)) return -1;
    dfs(i + 1, 1, s + (1LL<<i), t + (1LL<<i));
    dfs(i + 1, 0, s, t);
  }
  else{//01 or 10
    if(k == (x>>i&1)) return -1;
    dfs(i + 1, (k + 1)/2, s + (1LL<<i), t);
    dfs(i + 1, (k + 1)/2, s, t + (1LL<<i));
  }
  return -1;
}


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  vector<Int> A(N);
  cin>>A;

  a = A[0];
  b = A[1];
  c = 0;
  for(Int i=2;i<N;i++) c ^= A[i];
  x = a + b;
  ans = INF;
  dfs(0, 0, 0, 0);
  if(ans == INF) ans = -1;
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 3640
from collections import deque
n,m=map(int,input().split())
r=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    r[a].append(b)
    r[b].append(a)
dep=[-1]*(n+1)
dep[0]=0
dep[1]=0
data=deque([1])
d=0
while len(data)>0:
    p=data.popleft()
    for i in r[p]:
        if dep[i]==-1:
            dep[i]=dep[p]+1
            data.append(i)

if not all(dep[i+1]>=0 for i in range(n)):
    print("No")
else:
    print("Yes")
    for i in range(2,n+1):
        for j in r[i]:
            if dep[j]==dep[i]-1:
                print(j)
                break



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

typedef pair<int, int> p;
typedef long long ll;

const int mod = 1000000007;

const int inf = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> ok(n + 1);
  vector<int> dp(n + 1);
  rep(i, m) {
    cin >> a[i];
    ok[a[i]]++;
  }
  dp[0] = 1;
  if (ok[1])
    dp[1] = 0;
  else
    dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (ok[i])
      dp[i] = 0;
    else
      dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 4556
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a > b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        if (b > c) {
            int tmp = b;
            b = c;
            c = tmp;
        }
        if (a > b) {
            int tmp = a;
            a = b;
            b = tmp;
        }

        System.out.println(String.format("%d %d %d", a, b, c));
    }
}


Measured memory_bytes: 26336
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 1e5+2;

int main(){
      int n, a, b; 
      cin >> n >> a >> b;
      if(n == a && a == b)return cout<<a<<" "<<b<<"\n",0;
      int mn = 0 , mx = min(a,b);
      if(a+b > n)mn = abs(n-(a+b));
      cout << mx <<" "<<mn<<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
    int a,b;
    char op;
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if(op == '?'){
            break;
        }
        else if(op == '+'){
            printf("%d\n",a+b);//加算
        }
        else if(op == '-') {
            printf("%d\n",a-b);  //減算
        }
        else if(op == '*'){
            printf("%d\n",a*b);  //乗算
        }
        else if(op == '/'){
            printf("%d\n",a/b);  //除算
        }
    }
     
    return 0;
}



Measured memory_bytes: 2072
num = int(input())
deck = {}
for _ in range(num):
    c, n = input().split()
    n = int(n)
    if c in deck:
        deck[c].add(n)
    else:
        deck[c] = set([n])

cs = ['S', 'H', 'C', 'D']
alln = set(range(1, 14))
for c in cs:
    remain = sorted(list(alln - deck[c]))
    for r in remain:
        print(c, r)


Measured memory_bytes: 5600
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define fo(n) for(int i = 0;i < int(n);i++)
#define foo(a,b) for(int i = int(a);i <= int(b);i++)
#define mk make_pair
#define pb push_back
#define MAXN (int)1e6
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define fastio ios_base:: sync_with_stdio(false)
#define inf (int)1e9

int main(){

	
	fastio;
	int p,q,r;
	cin >> p >> q >> r;

	int ans = inf;

	ans = min(ans, p+q);
	ans = min(ans, q+r);
	ans = min(ans, r+p);

	cout << ans << endl;

	return 0;
 }	

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

void pop(string& s)
{
    s.pop_back();
    s.pop_back();
}

int is_even(string& s)
{
    assert(s.size() % 2 == 0);

    int n = s.size();
    int h = n / 2;

    for(int i = 0, j = h; i < h && j < n; i++, j++)
        if(s[i] != s[j]) return 0;

    return 1;
}

int main()
{
    string s; cin >> s;

    assert(s.size() % 2 == 0);

    pop(s);

    while(!is_even(s)) pop(s);

    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

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

const int INF = 1 << 24;
const int N = 5;
const string perm = "12345678910111213110111213";

int main(void){
    string res;
    for(vi in(N); cin >> in[0]; cout << res << endl){
        COUNT(i, N - 1){ char c; cin >> c >> in[i]; }
        set<int> u; rep(i, N) u.insert(in[i]);

        vi cnt;
        each(u, it) cnt.pb(count(ALL(in), *it));
        sort(ALL(cnt), greater<int>());

        switch(*cnt.begin()){
            case 4: 
                res = "four card";
                break;
            case 3:
                if(*(cnt.begin() + 1) == 2) res = "full house";
                else res = "three card";
                break;
            case 2:
                if(*(cnt.begin() + 1) == 2) res = "two pair";
                else res = "one pair";
                break;
            default:
                stringstream ss;
                sort(ALL(in));
                rep(i, N) ss << in[i];
                if(~perm.find(ss.str())) res = "straight";
                else res = "null";
                break;
        }
    }
 
    return 0;
}

Measured memory_bytes: 1252
import numpy as np

n, m, c = map(int, input().split())
b = np.array(list(map(int, input().split()))).reshape(-1, 1)

a = np.array(list(map(int, input().split()))).reshape(1,-1)
for i in range(n-1):
    a = np.vstack([a, np.array(list(map(int, input().split()))).reshape(1, -1)])

res = np.dot(a, b).reshape(-1) + c
print(np.sum(res > 0))


Measured memory_bytes: 12396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <typename T>
class SparseTable {
	int n;
	vector<vector<T>> t;
	T merge(const T& l, const T& r) {
		return min(l, r);
	}
public:
	SparseTable(const vector<T>& b) {
		n = b.size();
		t.push_back(b);
		for (int i = 2, j = 1; i <= n; i <<= 1, j++) {
			t.push_back(vector<T>());
			for (int k = 0; k + i <= n; k++) {
				t[j].push_back(merge(t[j - 1][k], t[j - 1][k + i / 2]));
			}
		}
	}
	T find(int l, int r) {
		r++;
		assert(0 <= l && l < r && r <= n);
		unsigned int w = r - l;
		int i = 31 - __builtin_clz(w);
		return merge(t[i][l], t[i][r - (1 << i)]);
	}
	T operator[](int id) {
		return t[0][id];
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	ll res = 0;
	SparseTable<int> st(a);
	for (int i = 0; i < N; i++) {
		ll l = 0, r = 0;
		{
			int lb = -1, ub = i;
			while (ub - lb > 1) {
				int m = (lb + ub) / 2;
				if (st.find(m, i) == a[i]) {
					ub = m;
				}
				else {
					lb = m;
				}
			}
			l = ub;
		}
		{
			int lb = i, ub = N;
			while (ub - lb > 1) {
				int m = (lb + ub) / 2;
				if (st.find(i, m) == a[i]) {
					lb = m;
				}
				else {
					ub = m;
				}
			}
			r = lb;
		}
		res += (i - l + 1) * (r - i + 1) * a[i];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 14836
#ABC166
n,k=map(int,input().split())
cnt=[0]*(n+1)
for j in range(k):
  tmp = int(input())
  arr=list(map(int,input().split()))
  for val in arr:
    cnt[val]+=1
ans=0
for i in range(1,n+1):
  if cnt[i]==0:
    ans+=1
print(ans)

Measured memory_bytes: 9156
// D - 11

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 1e9 + 7;

class Comb {
private:
	int MOD;
	long long* fac;
	long long* finv;
	long long* inv;
public:
	// 事前にテーブルを作成
	Comb(int MAX, int MOD) {
		this->MOD = MOD;

		fac = new long long[MAX + 1];
		finv = new long long[MAX + 1];
		inv = new long long[MAX + 1];

		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;
		}
	}

	~Comb() {
		delete[] fac, finv, inv;
	}

	// 二項係数計算
	long long calc(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 a[100000];

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

	map<int, int> cnt;
	int dup, dup1_idx, dup2_idx;
	for (int i=0; i<n+1; i++) {
		cin >> a[i];
		cnt[a[i]]++;
		if (cnt[a[i]] == 2) {
			dup2_idx = i;
			dup = a[i];
		}
	}

	for (int i=0; i<n+1; i++) {
		if (a[i] == dup) {
			dup1_idx = i;
			break;
		}
	}

	int inter_dup = dup2_idx - dup1_idx - 1; // 重複する要素の間の数
	//cout << "inter dup: " << inter_dup << endl; // **** debug ****

	Comb comb = Comb(n+1, MOD);

	// k = 1
	cout << n << endl;

	for (int k=2; k <= n+1; k++) {
		// ---- 全ての選び方 ---- //
		ll c_all = comb.calc(n+1, k);

		// ---- 重複要素を片方選び、重複要素の間を選ばない場合が重複する ----
		ll c_dup = comb.calc((n+1) - inter_dup - 2, k-1);

		//cout << "c_all=" << c_all << " c_dup=" << c_dup << endl; // **** debug ****

		cout << (c_all - c_dup + MOD) % MOD << endl;
	}

	return 0;
}

Measured memory_bytes: 8576
import bisect
import numpy as np
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
ans = 0
for i in range(n):
     s = bisect.bisect_left(a,b[i])
     t = n - bisect.bisect_right(c,b[i])
     ans += s*t

print(ans)

Measured memory_bytes: 31476
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1);
namespace {
  template <typename T> inline void read(T &x) {
    x = 0; T f = 1;char s = getchar();
    for(; !isdigit(s); s = getchar()) if(s == '-') f = -1;
    for(;  isdigit(s); s = getchar()) x = (x << 3) + (x << 1) + (s ^ 48);
    x *= f;
  }
}
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lowbit(x) x & (-x)
#define pii pair<int,int>
#define fi first
#define se second
int main() {
  int n; string s;
  cin >> n >> s;
  int res = 1;
  char tmp = s[0];
  for(int i = 1; i < n; ++i) {
    if(s[i] != tmp) res++;
    tmp = s[i];
  }
  cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
n = int(input())
s_p_list = list()
for i in range(n):
    input_ = input().split()
    input_[1] = int(input_[1])
    input_.append(i + 1)
    s_p_list.append(input_)


s_p_list.sort(key=lambda x: (x[0], -x[1]))

# print(s_p_list)

for s, p, i in s_p_list:
    print(i)


Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
  long int a,b,d,r;
  double f;
  scanf("%ld%ld",&a,&b);
  d = a/b;
  r = a%b;
  f = (double)a/b;
  printf("%ld %ld %f\n",d,r,f);
  return 0;
}

Measured memory_bytes: 636
while True:
	h, w = map(int, input().split())
	if h == w == 0:
		break
	for i in range(h):
		A = ""
		if i % 2 == 0:
			for u in range(w):
				if u % 2 == 0:
					A += "#"
				else:
					A += "."
		else:
			for u in range(w):
				if u % 2 == 0:
					A += "."
				else:
					A += "#"
		print(A)
	print()


Measured memory_bytes: 5608
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()

    println(abc126c(n, k))
}

fun abc126c(n: Int, k: Int): Double {
    var ans = 0.0
    for (i in 1..n) {
        ans += calc(i, k) / n
    }

    return ans
}

private fun calc(i: Int, k: Int): Double {
    var score = i
    if (score >= k) return 1.0

    var count = 0.0
    while (score < k) {
        score *= 2
        count++
    }

    return Math.pow(0.5, count)
}

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

int main()
{
  int r,g,b;
  cin >> r >> g >> b;
  
  int mul = r * 100 + g * 10 + b;
  
  if(mul % 4 == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    vec<ll> A(N);
    ll ans  = 1;
    ll before = 1;
    bool flag = true;
    rep(i, N) {
        ll A;
        cin >> A;
        ans *= A;

        if (ans > (ll)1e18) flag = false;
        if (ans < before) flag = false;
        if (A == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (flag ? (ll)ans : -1) << endl;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
long long INF = 1e10;
/************************  DEFINE  ****************************/

/************************ FUNCTION ****************************/

/************************   MAIN   ****************************/
int main(void){
    ll n;cin>>n;
  	if(n%2==0)cout<<n<<endl;
  	else cout<<2*n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double 
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define inf  1e18
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fi first
#define se second 
int main()
{
    fastIO;
    ll a,b;
    cin>>a>>b;
    string str,str1;
    for(int i=0;i<b;i++)
    {
        str+=to_string(a);
    }
    for(int i=0;i<a;i++)
    {
        str1+=to_string(b);
    }
    if(str>=str1)
    {
        cout<<str1<<'\n';
    }
    else
    {
        cout<<str<<'\n';
    }
    return 0;
}

Measured memory_bytes: 256
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
 
n = int(input())
 
for _ in range(n):
    (b,f,r,v) = [int(i) for i in input().split()]
    data[b - 1][f - 1][r - 1] += v
 
for b in range(4):
    for f in range(3):
        for r in range(10):
            print('',data[b][f][r], end='')
        print()
    if b < 3:
        print('#' * 20)

Measured memory_bytes: 7796