akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define iii tuple<int, int, int>
#define ii pair<int, int>
#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int n, p = 0, q;
    cin >> n;
    int nn = n + n + 7;
    vector<vector<double>> dp(2, vector<double>(nn));
    dp[0][n] = dp[1][n] = 1.0;
    for (int t = 0; t < n; ++t) {
        double pi;
        cin >> pi;
        p = 1 - p, q = 1 - p;

        for (int i = 0; i < nn; ++i) dp[q][i] = 0;
        for (int i = 0; i < nn; ++i) {
            if (i) dp[q][i - 1] += (-pi + 1.0) * dp[p][i];
            if (i < nn - 1) dp[q][i + 1] += pi * dp[p][i];
        }
        // for (int i = 0; i < nn; ++i) cout << dp[q][i] << " \n"[i == nn - 1];
    }
    double res = 0;
    for (int i = n + 1; i < nn; ++i) res += dp[q][i];
    cout << fixed << setprecision(18) << res << '\n';

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	char d,x;
	char out;
	char q=' ';
	int co=0;
	int ma=0;
	bool h=true;
	while(cin>>d){
		if(d=='c')rep(i,6)cin>>x;
		if(d=='e')rep(i,2)cin>>x;
		if(q!=d){
			if(h)out=d;
			co++;
		}else{
			if(ma<co){ma=co;co=1;out=d;}
			else co=1;
			h=false;
		}		
		q=d;
	}
	if(ma<co)out=d;
	if(out=='c')cout<<"chicken"<<endl;
	else cout<<"egg"<<endl;
}

Measured memory_bytes: 1140
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d%d%d", &a, &b, &c);
  int ispoor= 0;
  if(a==b&&b!=c)ispoor= 1;
  if(b==c&&c!=a)ispoor= 1;
  if(c==a&&a!=b)ispoor= 1;
  if(ispoor) {
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define MAXN 1005

int N, M, D;
int d[MAXN];
char m[] = { 'R', 'Y', 'G', 'B' };

int main(){
	scanf( "%d%d%d", &N, &M, &D );
	for ( int i = D, I(max( N << 1, M << 1 )); i <= I; ++i ) d[i] = d[i - D] + 1;
	for ( int i = 1; i <= N; ++i, putchar('\n') )
		for ( int j = 1; j <= M; ++j ){
			int x( i + j ), y( i - j + M );
			putchar( m[( d[x] & 1 ) << 1 | ( d[y] & 1 )] );
		}
	return 0;
}

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

typedef long long ll;

int main()
{
    int n;
    vector<int> d;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        d.push_back(tmp);
    }

    int ans = 0;
    for (int i = 1; i < n - 1; i++)
    {
        if ((d[i] > d[i - 1] && d[i] < d[i + 1]) ||
        (d[i] < d[i - 1] && d[i] > d[i + 1]))
        {
            ans++;
        }
    }
    cout << ans << endl;    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    long long H;
    cin >> H;

    long long ans = 0;
    long long c = 0;
    while(H > 0){
        if(H == 1){
            H = 0;
        }else{
            H = ceil(H / 2);
            
        }
        ans += pow(2, c);
        c += 1;
    }

    cout << ans << endl;            
}

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

int main(void) {
  int N;
  cin >> N;
  vector<int> a(N);
  int r = 0;
  int t = 1;
  for(int i = 0; i < N; i++) {
    cin >> a[i];
    if(!t) t = 1;
    else if(a[i] == a[i - 1] && t) {
      r++;
      t--;
    }
  }
  cout << r << endl;
}

Measured memory_bytes: 256
module Main where

import           Control.Monad
import           Data.List
import           Data.Ord
import           Data.List.Split
import qualified Data.Vector.Unboxed as V

solve [] = "YES"
solve s
  | "maerd" `isPrefixOf` s = (solve . drop 5) s
  | "remaerd" `isPrefixOf` s = (solve . drop 7) s
  | "esare" `isPrefixOf` s = (solve . drop 5) s
  | "resare" `isPrefixOf` s = (solve . drop 6) s
  | otherwise = "NO"

main :: IO ()
main = do
  s <- reverse <$> getLine
  putStrLn $ solve s


Measured memory_bytes: 7548
N = int(input())
a = list(map(int, input().split()))
a.sort()

if a[N -1] == 0:
    print("Yes")
    exit(0)

if N % 3 == 0:
    i = N // 3
    if a[0] ^ a[i] == a[2 * i]:
        if a[0] == a[i -1] and a[i] == a[2 * i - 1] and a[2 * i] == a[N -1]:
            print("Yes")
            exit(0)

print("No")

Measured memory_bytes: 14116
import math

N, K = map(int, input().split())

ans = float(0)
logK = math.log(K, 2)

for n in range(1, N + 1):
    if n >= K:
        ans = ans + float(1 / N)
    else:
        prob_n = 1.0 / math.pow(2, math.ceil(logK - math.log(n, 2)))
        ans = ans + float(1 / N * prob_n)

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

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;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main(){
    ll x;
    cin>>x;
    ll cnt = 0;
    ll mo = 100;
    while(mo<x){
        cnt++;
        mo += mo / 100;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
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;}
typedef pair<ll,ll> P;


int main(){
    int n;
    cin >> n;
    vector<P> a(n);
    rep(i,n)cin >> a[i].second >> a[i].first;
    ll time = 0;
    sort(a.begin(),a.end());

    rep(i,n){
        time+=a[i].second;
        //cout << a[i].first<<" "<<a[i].second << endl;
        if(time > a[i].first){
            cout << "No" << endl;
            return 0;
        }
        
    }
    cout <<"Yes" << endl;
    return 0;
}

Measured memory_bytes: 3328
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000


vector<int> colors, check;

int main()
{
    string S,T,U;
    int A,B;
    cin >> S >> T >> A >> B >> U;
    if(S==U){
        A--;
    } else{
        B--;
    }
    cout << A << " " << B << endl;
    
    return 0;
}


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


#define long long long int

using namespace std;


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

    int a, b, c;
    cin >> a >> b >> c;
    swap(a,b);
    swap(a,c);

    cout << a << " " <<  b << " " << c;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
const int N=1e6;
int c[N],w[N];
struct P{ int c,w,id; }p[N];
int fa[N],tag[N];inline int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]); }
inline bool cmpc(const P &a,const P &b) { return a.c==b.c?a.w<b.w:a.c<b.c; }
inline bool cmpw(const P &a,const P &b) { return a.w<b.w; }
inline void merge(int x,int y) { fa[find(x)]=find(y); }
map<int,int>mp[N];
int fac[N],inv[N];
bool o[N];
const int mod=1e9+7;
int main()
{
	int n=gi(),i,k,l,r,x=gi(),y=gi();
	for (i=1;i<=n;i++) c[i]=p[i].c=gi(),w[i]=p[i].w=gi(),p[i].id=i,fa[i]=i;
	sort(p+1,p+1+n,cmpc);
	for (l=1;l<=n;l=r) {
		for (r=l;p[l].c==p[r].c;r++);
		for (i=l;i<r;i++) if (p[i].w+p[l].w<=x) merge(p[l].id,p[i].id);
	}
	sort(p+1,p+1+n,cmpw);
	for (i=2;i<=n;i++) if (p[i].c!=p[1].c&&p[i].w+p[1].w<=y) merge(p[1].id,p[i].id);
	for (i=2;i<=n;i++) if (p[i].c!=p[1].c) break;
	if (i<=n)
		for (k=1;k<=n;k++) if (p[k].c==p[1].c&&p[k].w+p[i].w<=y) merge(p[k].id,p[i].id);

	for (i=fac[0]=1;i<=n;i++) fac[i]=1LL*fac[i-1]*i%mod;
	for (i=2,inv[0]=inv[1]=1;i<=n;i++) inv[i]=-1LL*(mod/i)*inv[mod%i]%mod;
	for (i=3;i<=n;i++) inv[i]=1LL*inv[i]*inv[i-1]%mod;
	for (i=1;i<=n;i++) mp[find(i)][c[i]]++;
	int ans=1;
	for (i=1;i<=n;i++)
		if (fa[i]==i) {
			k=0;
			for (auto pr:mp[i])
				ans=1LL*ans*inv[pr.second]%mod,k+=pr.second;
			ans=1LL*ans*fac[k]%mod;
		}
	printf("%d\n",(ans+mod)%mod);
	return 0;
}


Measured memory_bytes: 76160
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    x = max(A)
    y = B[A.index(x)]
    ans = x + y

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10868
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

ll x, y;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    II now = II(0, 0);
    int tnow = 0;
    FOR(i,1,n) {
        int t, x, y;
        cin >> t >> x >> y;
        int dist = abs(now.FI - x) + abs(now.SE - y);
        if (t - tnow < dist) {
            cout << "No";
            return 0;
        }
        if ((t-tnow) % 2 != dist % 2) {
            cout << "No";
            return 0;
        }
        now = II(x, y);
        tnow = t;
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let dfs vs n =
  let d = Array.make n (-1) in
  let rec doit i id =
    d.(i) <- id;
    List.iter (fun v -> if d.(v) = (-1) then doit v id) vs.(i) in
  Array.iteri (fun i e -> if e = (-1) then doit i i) d;
  d

let read_ns () =
  match read_line () |> split_on_char ' ' |> List.map int_of_string with
  | [x; y] -> (x, y)
  | _ -> assert false

let () =
  let (n, m) = read_ns () in
  let vs = Array.make n [] in
  for _ = 0 to m - 1 do
    let (s, t) = read_ns () in
    vs.(s) <- t :: vs.(s);
    vs.(t) <- s :: vs.(t);
  done;
  let d = dfs vs n in
  let q = read_int () in
  for _ = 0 to q - 1 do
    let (s, t) = read_ns () in
    Printf.printf (if d.(s) = d.(t) then "yes\n" else "no\n")
  done

Measured memory_bytes: 18744
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s;
	int countr = 0;
	
	cin >> s;
	

	if (s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR")
		countr = 1;
	else if (s == "SRR" || s == "RRS")
		countr = 2;
	else if (s == "RRR")
		countr = 3;
	
	cout << countr << endl;
	return 0;
}

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

main() {
    int a,b,c; cin >> a >> b >> c;
    if(a+b==c || a+c==b || b+c==a)
    cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
# coding:UTF-8


def calc_gcd(num1, num2):
    """
    最大公約数算出
    :param num1: 対象の値1
    :param num2: 対象の値2
    :return:最大公約数
    """
    if num1 < num2:
        num1, num2 = num2, num1

    while num2 > 0:
        remainder = num1 % num2

        num1 = num2
        num2 = remainder

    return num1


# 値の個数を取得
num_count = int(input())

# 最大公約数を求める対象の値群を取得
target_num = list(map(int, input().split()))

# 累積GCDリスト(可変で扱うと処理速度が遅くなるため、あらかじめ領域を確保)
left_gcd = [0] * num_count  # +1は0用の領域(1番目を除外する場合に使用)
right_gcd = [0] * num_count  # 同上

for i in range(num_count-1):
    left_gcd[i+1] = calc_gcd(left_gcd[i], target_num[i])
    right_gcd[num_count-2-i] = calc_gcd(right_gcd[num_count-1-i], target_num[num_count-1-i])

# print(left_gcd)
# print(right_gcd)

gcd = 0

for i in range(num_count):
    result = calc_gcd(left_gcd[i], right_gcd[i])
    if gcd < result:
        gcd = result

print(gcd)


Measured memory_bytes: 14488
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 16;

int n;
int a[N][N];
ll pre[1 << N], dp[1 << N];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      scanf("%d", &a[i][j]);
  for (int s = 1; s < 1 << n; ++s) {
    int i = __builtin_ctz(s);
    pre[s] = pre[s ^ 1 << i];
    for (int j = 0; j < n; ++j)
      if (s >> j & 1)
        pre[s] += a[i][j];
  }
  for (int s = 1; s < 1 << n; ++s) {
    dp[s] = numeric_limits<ll>::min();
    for (int t = s; t; t = (t - 1) & s)
      dp[s] = max(dp[s], pre[t] + dp[s ^ t]);
  }
  printf("%lld\n", dp[(1 << n) - 1]);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
void dfs(vector< vector< int > > &G, vector< int > &done, int x, int k) {
	rep(i, N) if (i != x) {
		if (G[x][i] != 0)
			continue;
		if (done[i] == -1) {
			done[i] = 1 - done[x];
			G[i][x] = G[x][i] = k;
			dfs(G, done, i, k);
		} else {
			if (done[i] != done[x]) {
				G[i][x] = G[x][i] = k;
			}
		}
	}
}
signed main() {
	cin >> N;
	vector< vector< int > > G(N, vector< int >(N, 0));
	int k = 1;
	while (1) {
		vector< int > done(N, -1);
		rep(i, N) if (done[i] == -1) {
			bool f = false;
			rep(j, N) if (j != i && G[i][j] == 0) {
				f = true;
				break;
			}
			if (f) {
				done[i] = 0;
				dfs(G, done, i, k);
			}
		}
		//cout << done;
		bool f = true;
		rep(i, N) rep(j, N) if (i != j) if (G[i][j] >= k) f = false;
		if (f)
			break;
		k++;
	}
	rep(i, N - 1) {
		for (int j = i + 1; j < N; j++) {
			cout << G[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2560
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(self.power_func(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(self.power_func(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

    def power_func(self,a,n,p):
        bi=str(format(n,"b"))#2進表現に
        res=1
        for i in range(len(bi)):
            res=(res*res) %p
            if bi[i]=="1":
                res=(res*a) %p
        return res
#グローバル変数MODを決めてあげてください

#グローバル変数MODを決めてあげてください
MOD = 10**9 + 7

N,K=[int(hoge) for hoge in input().split()]
Kazus = [0]*(K+1)
for x in range(K,0,-1):
    Dmax = K//x
    MoDmax = ModInt(Dmax)
    kazu = MoDmax ** N
    for d in range(Dmax,1,-1):
        kazu -= Kazus[d*x]
    Kazus[x] = kazu

print(sum([x*k for x,k in enumerate(Kazus) ]))


Measured memory_bytes: 90504
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int long long
const int N = 105;
const ll mod = 1e9+7;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 10000000;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
//1. Ends here

//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}

void solve()
{
    int n;
    cin>>n;

    int cur=1000;

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

    for(int i=1;i<n;i++){
        if(a[i]>a[i-1]){
            int hm = cur/a[i-1];

            int growth = hm*(a[i]-a[i-1]);

            cur+=growth;
        }
    }

    cout<<cur;

    return;
}
// how r u bro

Measured memory_bytes: 3680
#include <iostream>
using namespace std;
int main(void){
    string a,b;
    cin >>a>>b;
    string s=a+b;
    int x=0;
    for(int i=0;i<s.length();i++){
        x=x*10+(s[i]-'0');
    }
    for(int i=0;i<1000;i++){
        if(x==i*i){
            cout <<"Yes"<<endl;
            return 0;
        }
    }
    cout <<"No"<<endl;
    return 0;
}

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

int sumOfDigits(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int N;
    cin >> N;
    int fn = sumOfDigits(N);
    if(N%fn == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

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

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n,x,sum=0;
  int m[105];
  cin>>n>>x;
  rep(i,n){
    cin>>m[i];
    sum+=m[i];
  }
  sort(m,m+n);
  while(sum+m[0]<=x){
    sum+=m[0];
    n++;
  }
  cout<<n<<endl;
  return 0;
}


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

using namespace std;



int main(void) {
    int n,m;
    int ans=0;
    cin >> n >> m;

    vector< vector<int> > ss(m);
    vector<int> p(m);

    for (int i=0; i<m; i++) {
        int k;
        cin >> k;
        for (int j=0; j<k; j++) {
            int s;
            cin >> s;
            s--;
            ss[i].push_back(s);
        }
    }

    for (int i=0; i<m; i++) {
        cin >> p[i];
    }

    int stop = pow(2,n)-1;
    for (int i=0; i<=stop; i++) {
        vector<bool> sw(n);
        bool f = true;
        for (int j=0; j<n; j++) {
            sw[j] = (i>>j&1);
        }

        for (int j=0; j<m; j++) {
            int sum = 0;
            for(auto k : ss[j]) {
                sum += sw[k];
            }
            f = (sum%2 == p[j]);
            if(!f) break;
        }
        if(f) ans++;
    }
    cout << ans << endl;
}


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

def find_good( list , x ):
    #if ok : return 1 , not ok : return 0
    flag = 1
    for i in list:
        if i < x:
            flag = 0
            break
    return flag

def main():
    n,m,x = map( int , input().split() )
    a = []
    c = []
    for i in range(n):
        I = list( map( int , input().split() ) )
        c.append( I[0] )
        a.append( I[1:] )
    
    ans_min = sum(c)

    flag_ = 0

    #print(a)

    for i in range( 2 ** n ):
        z = i
        book_i = 0
        ans_list = [ 0 for j in range(m) ]
        ans_cost = 0

        while( z != 0 ):
            y = z % 2

            z = z // 2

            if y:
                for j in range( m ):
                    ans_list[j] += a[book_i][j]
                ans_cost += c[book_i]
            book_i += 1
        

        if find_good( ans_list , x ) and ans_min >= ans_cost:
            ans_min = ans_cost
            flag_ = 1
    
    if flag_:
        print(ans_min)
    else:
        print(-1)
    
main()

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main(){
  cin>>a>>b>>c;
  vector<int> e(a);
  for(int j=0;j<a;j++)e.at(j)=b-c;
  for(int i=0;i<c;i++){
    cin>>d;
    e.at(d-1)++;
  }
  for(int k=0;k<a;k++){
    int f=e.at(k);
    if(f>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

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

int main(void) {
  int n;
  double x[12], ans = 0;;
  char u[12][12];

  if(scanf("%d", &n) == 1);

  for(int i = 0; i < n; i++) {
      if(scanf("%lf %s", &x[i], u[i]) == 1);
      if(strcmp(u[i],"BTC") == 0) {
        ans += (x[i] * 380000.0);
      } else {
        ans += (double)x[i];
      }
  }

  printf("%lf", ans);

  return 0;
}


Measured memory_bytes: 128
use std::io::stdin;fn main(){let mut st = String::new();stdin().read_line(&mut st).unwrap();let n:Vec<i32>=st.trim().split(" ").map(|x| x.parse().unwrap()).collect();println!("{}",(n[0]+n[1])*(n[0]+n[1]-1)/2-(n[0]*n[1]))}

Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    N = int(input())
    tx_list = [list(map(int,input().split())) for _ in range(N)]

    pre_ti, pre_x, pre_y = 0,0,0
    for tx in tx_list:
        ti,x,y = tx[0],tx[1],tx[2]
        tmp_ti,tmp_x,tmp_y = ti-pre_ti,x-pre_x,y-pre_y
        pre_ti,pre_x,pre_y = ti,x,y
        for i in range(tmp_ti+1):
            if ((tmp_ti-i)-i) == (abs(tmp_x)+abs(tmp_y)):
                break
        else:
            print("No")
            exit()
    print("Yes")

main()

Measured memory_bytes: 27372
from collections import defaultdict

def dfs(i, used, g, ng):
    for n in g[i]:
        if n not in used and (i, n) != ng and (n, i) != ng:
            used.add(n)
            dfs(n, used, g, ng)
 
 
def main():
    N, M = map(int, input().split())
    g = defaultdict(list)
    k = []
    for _ in range(M):
        a, b = map(int, input().split())
        g[a].append(b)
        g[b].append(a)
        k.append((a, b))
 
    ans = 0
    for a, b in k:
        used = set()
        dfs(1, used, g, (a, b))
        if len(used) != N:
            ans += 1
    print(ans)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var P = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var min = int.MaxValue;
        var ans = 0;

        for (int i = 0; i < N; i++)
        {
            if(P[i] <= min)
            {
                ans++;
                min = P[i];
            }
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 43016
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
const ll INF = -1;

int solve(void);

int main(void)
{

	while (solve())
	{
	}

	return 0;
}

int solve(void)
{
	ll N;
	cin >> N;

	const int K = 3;

	vector<vector<ll>> act(K, vector<ll>(N,0));
	for(int i = 0; i < N; i++)
		for(int j = 0; j < K; j++)
			cin >> act[j][i];

	// dp[i][j] := 最後にiの行動をしたときの j　日目の幸福度の総和の最大値
	vector<vector<ll>> dp(K, vector<ll>(N, INF));

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < K; j++)
		{
			for (int k = 0; k < K; k++)
			{
				if( j == k ) { continue; }
				const ll prev  = (i > 0) ? dp[j][i-1] : 0;
				const ll delta = act[k][i];
				dp[k][i] = (dp[k][i] == INF) ? prev + delta :
					max(dp[k][i], prev + delta);
			}
		}
	}

	ll ans = dp[0][N-1];
	for(int i = 0; i < K; i++)
		if(dp[i][N-1] != INF)
			ans = max(dp[i][N-1], ans);

	cout << ans << endl;

	return 0;
}

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

#define int             long long
#define	ll				long long

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";
long long prime[1000000];

void sieve()
{
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;i++)
		prime[i]=1;

	for(int i=2;i*i<1000000;i++)
		if(prime[i]==1)
			for(int j=i*i;j<1000000;j+=i)
				prime[j]=0;
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i <= floor(sqrt(n)); i++)
        if (n % i == 0)
            return false;

    return true;
}

int factorial(int n)
{
    int f=1;
    for(int i = 1;i<=n ; i++)
        f = (f*i)%mod;
    return f;
}

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

int lcm(int a, int b)
{
	return (a / gcd(a, b)) * b;
}

int fastExponentiation(int n, int x, int modulo)
{
	int res = 1;
	while(x > 0)
       {
          if(x & 1)
          res = (res*n) % modulo;
          x = x >> 1;
          n = (n * n) % modulo;
       }
       return res;
}

int power(int n , int p )
{
	if(p==0)
	   return 1;

	 int res = power((n*n)%mod,p/2);
	 if(p%2==1)
	   res = (n*res)%mod;

	   	 return res;
}

bool isPowerOfTwo(int n)
{
   	return n && (!(n&(n-1)));
}

bool isSet(int n,int i)
{
	// To check if ith bit is set or not in binary representation of n
   	return n & (1 << i);
}

bool valid_coordinate(ll x,ll y,ll n,ll m)
{
    if(x<0 || y<0)
       return false;

   	else if(x>=n || y>=m)
       return false;

   	else
   		return true;
}

int sod(int n)
{
	int sum=0;
	while(n)
	{
		sum+=(n%10);
		n/=10;
	}
	return sum;
}

int SIZE = 1<<20;
map<int,int>m;

void solve()
{
	int n,ans=0;
	cin>>n;
	for(int i =0;i<n;i++){
		int x;
		cin>>x;
		m[x]++;
		ans+=x;
	}
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int a,b;
		cin>>a>>b;
		ans-=m[a]*a;
		ans+=m[a]*b;
		m[b]+=m[a];
		m[a]=0;
		cout<<ans<<endl;
	}
}

int32_t main()
{

	//int t; cin>>t; while(t--)
	solve();

	return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;


int H, N;
int init[20][2][2];
int blk[8][2][2];

void fall(vector<VVI>& fd, vector<VVI>& bl){
  int y;
  for(y=H+6;y>0;--y){
	bool done = false;
	REP(dy,2) REP(d,2) REP(x,2){
	  if(bl[dy][d][x] && fd[y+dy-1][d][x])
		done = true;
	}
	if(done) break;
  }
  bool f = true;
  REP(d,2) REP(x,2)
	if(bl[0][d][x]) f = false;
  if(f && y == 0){
	--y;
  }
  
  REP(dy,2) REP(d,2) REP(x,2){
	if(bl[dy][d][x])
	  fd[y+dy][d][x] = 1;
  }
}
int del(vector<VVI>& fd){
  int res = 0;
  for(int y=19;y>=0;--y){
	bool fill = true;
	REP(d,2) REP(x,2) if(!fd[y][d][x]) fill = false;
	if(fill){
	  ++res;
	  FOR(ty,y,19) REP(d,2) REP(x,2)
		fd[ty][d][x] = fd[ty+1][d][x];
	  REP(d,2) REP(x,2)
		fd[19][d][x] = 0;
	}
  }
  return res;
}
int check(const vector<PII>& ps){
  vector<VVI> fd(20, VVI(2, VI(2)));
  REP(y,20) REP(d,2) REP(x,2) fd[y][d][x] = init[y][d][x];
  int res = 0;
  REP(i,N){
	vector<VVI> vblk(2, VVI(2, VI(2)));
	REP(y,2) REP(d,2) REP(x,2)
	  if(blk[i*2+y][d][x]){
		vblk[y][d+ps[i].FF][x+ps[i].SS] = 1;
	  }
	fall(fd, vblk);
	res += del(fd);
  }
  return res;
}

int dfs(int i, vector<PII>& ps){
  if(i == N) return check(ps);
  int res = 0;
  FOR(dd,-1,2) FOR(dx,-1,2){
	bool ok = true;
	REP(y,2) REP(d,2) REP(x,2){
	  if(blk[i*2+y][d][x]){
		int td = d + dd, tx = x + dx;
		if(td < 0 || 2 <= td || tx < 0 || 2 <= tx)
		  ok = false;
	  }
	}
	if(!ok) continue;
	ps.EB(dd, dx);
	maxi(res, dfs(i+1, ps));
	ps.pop_back();
  }
  return res;
}

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

  while(cin>>H>>N,H){
	fill((int*)init, (int*)init+20*2*2,0);
	fill((int*)blk, (int*)blk+8*2*2,0);
	REP(y,H) REP(d,2) REP(x,2){
	  char c; cin >> c;
	  init[y][d][x] = c == '#';
	}
	REP(i,N*2) REP(d,2) REP(x,2){
	  char c; cin >> c;
	  blk[i][d][x] = c == '#';
	}
	vector<PII> ps;
	cout << dfs(0,ps) << endl;
  }

  return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define mem0(x) memset(x, 0, sizeof(x))
#define mem1(x) memset(x, -1, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define de(x) cout << #x << " = " << x << ", "
#define dl(x) cout << #x << " = " << x << endl
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i > b; i--)
#define setI freopen("input.txt", "r", stdin);
#define setIO freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout);
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---------------------------------------------------------//
const int N = 2e5 + 5;

int n, m, ans[55][55];
char g[55][55];
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main()
{
	#ifdef LOCAL
//		setI;
	#endif
//	ios::sync_with_stdio(false);
	scanf("%d%d", &n, &m);
	rep(i, 1, n + 1)  scanf("%s", g[i] + 1);
	rep(i, 1, n + 1)
	{
		rep(j, 1, m + 1)
		{
			if (g[i][j] == '#')
			{
				rep(p, 0, 8)
				{
					int x = i + dx[p], y = j + dy[p];
					ans[x][y]++;
				}
			}
		}
	}
	rep(i, 1, n + 1)
	{
		rep(j, 1, m + 1)
		{
			if (g[i][j] == '#')  printf("#");
			else  printf("%d", ans[i][j]);
		}
		puts("");
	}

	return 0;
}


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

const int MOD = 10007;
int n;
string s;
int dp[1010][8];

int f(char ch) {
	return ch == 'J' ? 0 : ch == 'O' ? 1 : 2;
}

int main() {
	cin >> n >> s;
    for (int i = 0; i < 8; i++) {
		if ((i & 1) && (i & (1 << f(s[0])))) dp[0][i] = 1;
	}
	for (int i = 1; i < n; i++) {
		int cur = f(s[i]), prv = f(s[i - 1]);
		for (int j = 0; j < 8; j++) {
			if (!(j & (1 << prv))) continue;
			for (int k = 0; k < 8; k++) {
				if (!(k & (1 << cur))) continue;
				if ((j & k) == 0) continue;
				(dp[i][k] += dp[i - 1][j]) %= MOD;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 8; i++) (ans += dp[n - 1][i]) %= MOD;
	cout << ans << endl;
}



Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000007
int main(){
  int h,w;
  cin>>h>>w;
  vector<string> v;
  for(int i=0;i<h;i++){
    string s;
    cin>>s;
    v.push_back(s);
  }
  int dp[h][w];
 	memset(dp,0,sizeof dp);
  dp[0][0]=1;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
     if(i==0 && j==0) dp[i][j]=1;
      else if(v[i][j]=='#') dp[i][j]=0;
      else if(i==0 && j>0) dp[i][j]+=dp[i][j-1];
      else if(i>0 && j==0) dp[i][j]+=dp[i-1][j];
      else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MAX;
    }
  }
 cout<<dp[h-1][w-1]%MAX;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=2e5;
const int inf=1e9;
int main(){
	vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;cin>>K;
	cout<<v[K-1]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    map<string, ll> m;
    rep(i, n){
        string s;
        cin >> s;
        sort(all(s));
        m[s]++;
    }

    ll ans = 0;
    for(auto p: m){
        ans += p.second * (p.second - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
N, Q = map(int, input().split())

def init(N): #セグ木の初期化
    n = 1
    while n < N: n *= 2
    return n

def Update(i, x, n, L): #aiをxに変更する
    K = n - 1 + i
    L[K] = x
    while K > 0:
        K = (K - 1)//2
        L[K] = min(L[2 * K + 1], L[2 * K + 2])

def Find(s, t, k, l, r, L): #[s:t)の最小値を出力する
    if r <= s or t <= l: return 2**31-1
    elif s <= l and r <= t: return L[k]
    else:
        vl = Find(s, t, 2*k+1, l, (l+r)//2, L)
        vr = Find(s, t, 2*k+2, (l+r)//2, r, L)
        return min(vl, vr)

n = init(N)
SegTree = [2**31-1] * (2 * n - 1)
for i in range(Q):
    com, x, y = map(int, input().split())
    if com == 0:
        Update(x, y, n, SegTree)
    elif com == 1:
        print(Find(x, y+1, 0, 0, n, SegTree))


Measured memory_bytes: 8696
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int a, b, x;
  cin >> a >> b >> x;
  if (a + b >= x && a <= x) YES;
  else NO;


  return 0;
}



Measured memory_bytes: 256
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    a = S.find('A')
    z = S.rfind('Z')
    print(z - a + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int L;
  cin >> L;
  double ma2 = pow((double)L/3,3);
  printf("%.8lf\n",ma2);

  return 0;
}


Measured memory_bytes: 256
//In the name of Allah
//#ISART
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2010, mod = 1e9 + 7;
ll dp[N][N], n, m, k;

ll _dp(ll x, ll y){
	if(dp[x][y] != -1)
		return dp[x][y];
	dp[x][y] = 0;
	for(int i = 0; i <= min(k - 1, x); i ++)
		if(y - (k - 1 - i) >= 0)
			dp[x][y] = (dp[x][y] + _dp(x - i, y - (k - 1 - i))) % mod;
	return dp[x][y];
}

int main(){
	cin >> n >> m >> k;
	for(int i = 0; i <= n; i ++)
		for(int j = 0; j <= m; j ++)
			dp[i][j] = -1;
	dp[0][0] = 1;
	_dp(n - 1, m);
	ll ans = 0;
	for(int i = m; i >= 1; i -= k - 1)
		ans = (ans + dp[n - 1][i]) % mod;
	cout << ans;
	return 0;
}


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

int data[2005],dp[2005][2005];

int main()
{
  int n,x;
  long long ans=LLONG_MAX;

  scanf("%d%d",&n,&x);
  for(int c=0;c<n;c++)
    scanf("%d",&data[c]),dp[0][c]=data[c];
  for(int c=1;c<n;c++)
  for(int c2=0;c2<n;c2++)
  {
    dp[c][c2]=std::min(dp[c-1][c2],dp[c-1][((c2-1)+n)%n]);
  }
  for(int c=0;c<n;c++)
  {
    long long tmp=(long long)x*c;

    for(int c2=0;c2<n;c2++)tmp+=dp[c][c2];
    ans=std::min(ans,tmp);
  }
  printf("%lld\n",ans);
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int n,k,x,ans=0,sz,now;
unordered_map<int,int>mp;
unordered_map<int,int>::iterator it;
vector<int>v;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        cin>>x;
        mp[x]++;
    }
    for(it=mp.begin(); it!=mp.end(); it++)
        v.push_back(it->second);
    sort(v.begin(),v.end());
    sz=v.size();
    now=sz;
    for(int i=0; i<sz; i++)
    {
        if(now<=k)
            break;
        ans+=v[i];
        now--;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 10312
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n, edge(4)
    integer(int32):: x,y,a,i

    edge(:) = 0
    read*, edge(2), edge(4), n

    do i = 1, n
        read*, x,y,a
        select case (a)
            case(1)
                edge(1) = max(edge(1),x)
            case(2)
                edge(2) = min(edge(2),x)
            case(3)
                edge(3) = max(edge(3),y)
            case(4)
                edge(4) = min(edge(4),y)
        end select
    end do

    if (edge(2) >= edge(1) .and. edge(4) >= edge(3)) then
        print'(i0)', (edge(2)-edge(1))*(edge(4)-edge(3))
    else
        print'(i0)', 0
    end if
end program name

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>

#define LL unsigned long long
LL ans;
int N;
std::vector<int> A, B, C;
LL bb[100010];
int main(){
	std::cin >> N;
	for (int i = 1; i <= N; i++) {
		int tmp;
		std::cin >> tmp;
		A.push_back(tmp);
	}
	for (int i = 1; i <= N; i++) {
		int tmp;
		std::cin >> tmp;
		B.push_back(tmp);
	}
	for (int i = 1; i <= N; i++) {
		int tmp;
		std::cin >> tmp;
		C.push_back(tmp);
	}
	std::sort(A.begin(), A.end());
	std::sort(B.begin(), B.end());
	std::sort(C.begin(), C.end());
	int ub, lb;
	ub = N - 1;
	lb = 0;
	for (int i = 0; i < N; i++) {
		int ub, lb;
		ub = N - 1;
		lb = 0;
		while(ub - lb > 1) {
			int mid = (ub + lb) / 2;
			if (A[mid] >= B[i]) {
				ub = mid;
			}
			else {
				lb = mid;
			}
		}
		if (A[lb] >= B[i]) {
			continue;
		}
		if (A[ub] < B[i])lb = ub;
		bb[i + 1] = bb[i] + (LL)lb + 1;
	}
	for (int i = 0; i < N; i++) {
		int ub, lb;
		ub = N - 1;
		lb = 0;
		while (ub - lb > 1) {
			int mid = (ub + lb) / 2;
			if (B[mid] >= C[i]) {
				ub = mid;
			}
			else {
				lb = mid;
			}
		}
		if (B[lb] >= C[i]) {
			continue;
		}
		if (B[ub] < C[i])lb = ub;
		ans += (LL)bb[lb + 1];
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 2296