akhauriyash/Code-Regression huggingface dataset:
#参考URL:http://lethe2211.hatenablog.com/entry/2014/12/30/011030
import heapq
n,m,s,t=map(int,input().split())
s-=1
t-=1
Gyen=[dict() for i in range(n)]
Gsnu=[dict() for i in range(n)]
for i in range(m):
    u,v,a,b=map(int,input().split())
    u-=1
    v-=1
    Gyen[u][v]=a
    Gyen[v][u]=a
    Gsnu[u][v]=b
    Gsnu[v][u]=b
def dijkstra(adj, start):
    num = n          # グラフのノード数
    dist = [10**15 for i in range(num)] # 始点から各頂点までの最短距離を格納する
   
    dist[start] = 0
    q = []                  # プライオリティキュー．各要素は，(startからある頂点vまでの仮の距離, 頂点vのID)からなるタプル
    heapq.heappush(q, (0, start)) # 始点をpush
    while (len(q) != 0):
        prov_cost, src = heapq.heappop(q) # pop
        # プライオリティキューに格納されている最短距離が，現在計算できている最短距離より大きければ，distの更新をする必要はない
        if dist[src] < prov_cost:
            continue
        # 他の頂点の探索
        for dest in adj[src]:
            cost = adj[src][dest]
            if dist[dest] > dist[src] + cost:
                dist[dest] = dist[src] + cost # distの更新
                heapq.heappush(q, (dist[dest], dest)) # キューに新たな仮の距離の情報をpush                  
    return dist
CostYen=dijkstra(Gyen,s)
CostSnu=dijkstra(Gsnu,t)
Cost=[0 for i in range(n)]
for i in range(n):
    Cost[i]=CostYen[i]+CostSnu[i]
ans=[0 for i in range(n)]
ans[-1]=Cost[-1]
for i in list(range(n-1))[::-1]:
    ans[i]=min(ans[i+1],Cost[i])
for i in range(n):
    print(10**15-ans[i])


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

int main()
{	
	int n;
	cin >> n;
	int a[n];
	for(int i = 0;i < n;i++) cin >> a[i];
	
	int f = 1;
	for(int i = n - 1;i >= 1;i--){
		if(a[i] < a[i - 1]) a[i - 1]--;
		if(a[i] < a[i - 1]){
			f = 0;
			break;
		}
	}
	if(f) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 640
import math
import numpy as np

a, b, h, m = map(int, input().split())

x = ((h * 60 + m) * 360 /(720))
y = (m * 6)
num = abs(x - y)

print(math.sqrt(a * a + b * b - 2 * a * b * np.cos(np.radians(min(num, 360 - num)))))


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

const int INF = 1e9;
int main() {
    int n, m, l, k, a, h;
    while (cin >> n >> m >> l >> k >> a >> h) {
        if (n == 0) break;
        int frz[110] = {};
        frz[a] = frz[h] = 1;
        for (int i = 0; i < l; i++) {
            int x;
            cin >> x;
            frz[x] = 1;
        }
        vector<vector<int> > dp(110, vector<int>(110, INF));
        for (int i = 0; i < k; i++) {
            int x, y, t;
            cin >> x >> y >> t;
            dp[x][y] = dp[y][x] = t;
        }
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (dp[i][j] > m || !frz[i] || !frz[j]) {
                    dp[i][j] = INF;
                }
            }
        }
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                }
            }
        }
        if (dp[a][h] >= INF) {
            cout << "Help!" << endl;
        } else if (dp[a][h] < m) {
            cout << dp[a][h] << endl;
        } else {
            cout << dp[a][h] * 2 - m << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3204
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;


namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();
            var r = cin.nextInt();
            

            Console.WriteLine(3 * r * r );
        }
    }

    

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

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

int main(){
    int x,y;
    cin >> x >> y;
    
    int first[7] = {1,3,5,7,8,10,12};
    int second[4] = {4,6,9,11};
    
    bool a = false;
    bool b = false;
    rep(i,7){
        if(x==first[i]) a = true;
        if(y==first[i]) b = true;
    }
    
    if(!(a&&b)){
        a = false;
        b = false;
    }
    
    rep(i,4){
        if(x==second[i]) a = true;
        if(y==second[i]) b = true;
    }
    
    if(!(a&&b)){
        a = false;
        b = false;
    }
    
    if(x==2&&y==2){
        a = true;
        b = true;
    }
    
    if(a&&b) cout << "Yes";
    else cout << "No";
}


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

const int mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

int main() {
    ll n, k;
    cin >> n >> k;
    combination nck(n);
    mint ans(0);
    for (ll m = 0; m <= min(n - 1ll, k); m++) {
        ans += nck(n, m) * nck(n - 1, n - m - 1);
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

typedef pair<int, int> pairint;

bool pairCompair(const pairint& firstPI, const pairint& secondPI){
    return firstPI.second < secondPI.second;
}

int main(void){
    int N;
    vector<pairint> AB;
    int Abuf, Bbuf;

    cin >> N;

    for(int i=0; i<N; i++){
        cin >> Abuf >> Bbuf;
        AB.push_back(make_pair(Abuf, Bbuf));
    }

    sort(AB.begin(), AB.end(), pairCompair);

    bool completable = true;
    int time = 0;

    for(int i=0; i<N; i++){
        time += AB[i].first;
        if(time > AB[i].second){
            completable = false;
            break;
        }
    }

    if(completable){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 2420
import java.util.*;

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 < c && b > c) || (a > c && b < c)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> s(H), c(H, string (W, '.'));
  for (auto&& in : s) cin >> in;
  
  vector<int> dy {1, 0, -1, 0}, dx {0, 1, 0, -1};
  
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if (s[y][x] == '#') {
        for (int direction = 0; direction < 4; direction++) {
          int new_y = y + dy[direction], new_x = x + dx[direction];
          if (new_y < 0 || new_x < 0 || H <= new_y || W <= new_x
             || s[new_y][new_x] == '.') continue;
          c[y][x] = c[new_y][new_x] = '#';
        }
      }
    } 
  }
  
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if (s[y][x] != c[y][x]) {
        cout << "No\n";
        return 0;
      }
    }
  }
  
  cout << "Yes\n";
  return 0;
}

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

bool is_palindromic(int num)
{
	if ((num / 10000 == num % 10) &&
			((num/1000)%10 == (num%100)/10))
		return true;


	return false;
}

int main(void)
{
	int a, b;
	cin >> a >> b;

	int count = 0;
	for (int i = a; i <= b; i++) {
		if (is_palindromic(i))
			count++;
	}

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


Measured memory_bytes: 384
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int;  // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n) {
  int ret = 1;
  for (int i = 1; i < n + 1; ++i) {
    ret = ret * i;
  }
  return ret;
}

/* 最大公約数 */
template <typename T>
T gcd(T x, T y) { return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>
T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>
T lcm_n(vector<T>& numbers) {
  T l;
  l = numbers[0];
  for (int i = 1; i < numbers.size(); ++i) {
    l = lcm(l, numbers[i]);
  }
  return l;
}

/**
 * @brief 素因数分解する。2, 3,..., √Nまでの整数をNで割っていき、割り切れる数と割った回数を保存することで、素因数分解を行う。
 *        O(√N)
 * @param N 素因数分解する整数
 * @param result N = 2^3 * 3^2の場合、{{2, 3}, {3, 2}}のような形式のvectorが生成される
*/
void prime_factorize(ll N, vector<pair<ll, ll>>& result) {
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    ll ex = 0;  // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    result.emplace_back(pair<ll, ll>{a, ex});
  }

  // 最後に残った数
  if (N != 1) result.emplace_back(pair<ll, ll>{N, 1});
}

bool is_ok(vector<pair<ll, ll>>& result) {
  ll n = 1;
  for (auto v : result) {
    n *= (v.second + 1);
  }

  return n == 8;
}

int main() {
  ll N;
  cin >> N;

  ll ans = 0;

  for (ll i = 3; i <= N; i += 2) {
    vector<pair<ll, ll>> result;
    prime_factorize(i, result);
    if (is_ok(result)) ++ans;
  }

  cout << ans << endl;

  return 0;
}


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

#define LL long long
#define RG register

using namespace std;
template<class T> inline void read(T &x) {
	x = 0; RG char c = getchar(); bool f = 0;
	while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
	while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
	x = f ? -x : x;
	return ;
}
template<class T> inline void write(T x) {
	if (!x) {putchar(48);return ;}
	if (x < 0) x = -x, putchar('-');
	int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;
	for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ;
}
const int N = 45, Mod = 1e9 + 7;
int n, x, y, z, f[N][262144];
unsigned long long g[262144][11];
void pls(int &x, int y) {
	x += y;
	if (x >= Mod) x -= Mod;
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n, x, y, z, limit;
	read(n), read(x), read(y), read(z);
	scanf("%d%d%d%d", &n, &x, &y, &z);
	limit = (1 << (x + y + z - 1)) | (1 << (y + z - 1)) | (1 << (z - 1));
	for (int S = 0; S < (1 << 18); S++)
		for (int i = 1; i <= 10; i++)
			if ((S & limit) == limit) g[S][i] = S;
			else g[S][i] = (((LL)S << i) | (1 << (i - 1))) & ((1 << 18) - 1);
	f[0][0] = 1;
	for (int i = 0; i < n; i++)
			for (int k = 1; k <= 10; k++)
		for (int S = 0; S < (1 << 18); S++)
				pls(f[i + 1][g[S][k]], f[i][S]);
	int ans = 0;
	for (int i = limit; i < (1 << 18); i++)
		if ((i & limit) == limit) pls(ans, f[n][i]);
	write(ans);
	return 0;
}


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

int main() {
	int A, B, Q;
	cin >> A >> B >> Q;
	vector<long long> S(A), T(B), X(Q);
	for (int i = 0; i < A; i++) cin >> S[i];
	for (int i = 0; i < B; i++) cin >> T[i];
	for (int i = 0; i < Q; i++) cin >> X[i];
	for (long long x : X) {
		auto it = lower_bound(S.begin(), S.end(), x);
		long long y1 = (it == S.end() ? *(it - 1) : *it);
		long long y2 = (it == S.begin() || it == S.end() ? y1 : *(it - 1));
		auto it2 = lower_bound(T.begin(), T.end(), x);
		long long z1 = (it2 == T.end() ? *(it2 - 1) : *it2);
		long long z2 = (it2 == T.begin() || it2 == T.end() ? z1 : *(it2 - 1));

		cout << min({ abs(y1 - x) + abs(y1 - z1), abs(y1 - x) + abs(y1 - z2),
			abs(y2 - x) + abs(y2 - z1), abs(y2 - x) + abs(y2 - z2),
			abs(z1 - x) + abs(z1 - y1), abs(z1 - x) + abs(z1 - y2),
			abs(z2 - x) + abs(z2 - y1), abs(z2 - x) + abs(z2 - y2) }) << endl;
	}
}

Measured memory_bytes: 3712
s = input()
ans = 0

if s[0] == 'R':
    if s[1] == 'R':
        if s[2] == 'R':
            ans = 3
        else:
            ans = 2
    else:
        ans = 1

elif s[1] == 'R':
    if s[2] == 'R':
        ans = 2
    else:
        ans =1

elif s[2] == 'R':
    ans = 1

print(ans)

Measured memory_bytes: 9128
import qualified Data.ByteString.Char8 as C
import Data.List

mdl :: Num a => a
mdl = 10^9 + 7

t a b = a * b `mod` mdl

positivize x = if x < 0 then x + mdl else x

main :: IO ()
main = do
    [n,a,b] <- unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine
    print $ positivize $ (powMod 2 n - 1 - chooseOpt n a - chooseOpt n b) `mod` mdl

powMod :: Int -> Int -> Int
powMod cur 0 = 1
powMod cur n
    | even n = powMod (t cur cur) (div n 2)
    | odd n  = (t cur) $! powMod (t cur cur) (div n 2)

chooseOpt n i = choose n (min (n-i) i)
    where
    choose n i = t (prod' [n-i+1..n] ) $ (prod' [1..i]) `powMod` (mdl-2)
    prod' = foldr t 1


Measured memory_bytes: 8204
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;
const int N = 6e5 + 500;
const int LN = 21;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;

long long n, m, u, v, k, t, q, a, x, d, b;

long long arr[N];
long long sol[N];
long long diff[N];

int main() {
   ios::sync_with_stdio(false);cin.tie(0);
   cin >> n;
   for (int i = 0; i < n; ++i) cin >> arr[i];
   int cur = 0;
   long long pVal = 0;
   
   for (int i = 1; i <= n; ++i) {
      long long dist = arr[cur] - arr[(cur + 1) % n];
      dist *= 2;
      pVal += dist;
      diff[(cur + 2) % n] = pVal;
      cur = (cur + 2) % n;
   }
   
   
   long long val = (2 * arr[0] + diff[1]) / 2;
   for (int i = 0; i < n; ++i) {
      sol[i] = val - diff[i];
      cout << sol[i] << " ";
   }
   cout << endl;
}







Measured memory_bytes: 6272
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder st = new StringBuilder();
         
        int i = 1;
         
        while(true){
            int line = Integer.parseInt(br.readLine());
            if(line == 0){
                break;
            }
             
            st.append("Case ").append(i).append(": ").append(line).append("\n");
            i++;
        }
         
        System.out.print(st);
    }
}

Measured memory_bytes: 29716
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>



int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	int* b = new int[N + 1];
	for (int i = 0; i < N + 1; i++) {
		b[i] = 1;
	}
	for (int i = 0; i < M; i++) {
		int a;
		scanf("%d", &a);
		b[a] = 0;
	}
	long long* n = new long long[N + 1];
	n[0] = 1;
	n[1] = b[1];
	for (int i = 2; i < N + 1; i++) {
		n[i] = (b[i] * (n[i - 1] + n[i - 2])) % 1000000007;
	}
	int res = n[N] % 1000000007;
	printf("%d", res);
}



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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

    vector<int> A(N);
    rep(i,0,N) cin >> A[i];

    auto B=A;
    sort(begin(B),end(B));

    map<int,int> pos;
    rep(i,0,N) pos[B[i]]=i;

    int cnt=0;
    rep(i,0,N){
        if(i%2!=pos[A[i]]%2) ++cnt;
    }

    cout << cnt/2 << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define EACH(e,v) for(auto& e:v)

/*
・セグメント木
  >         build O(N)
  > query, update O(logN)
[備考] 結合律, 単位元を持つ二項演算を, 任意の区間に関してlogNで行うデータ構造
[使用例]
SegmentTree<int> seg_sum(N, [](int a, int b){ return a+b; }, 0 );       // 区間和
SegmentTree<int> seg_min(N, [](int a, int b){ return min(a,b); }, INF); // 区間min
seg_min.set(k,x);     // 要素kに値xを設定
seg_min.build();      // 上のセグメントに値を設定
seg_min.update(k,x);  // 要素kを値xに変更
seg_min.add(k,x);     // 要素kに値xを加算
seg_min.query(l,r);   // 区間[l,r)に対する二項演算の結果を返す
*/

template<typename T> struct SegmentTree {

  using F = function< T(T,T) >;

  vector< T > seg;

  int size;       // データの数以上の最小の2冪, 最下段のデータの個数
  const F func;
  const T M1;

  SegmentTree(int n, const F f, const T &M) : func(f), M1(M) {
    size = 1; while (size < n) size *= 2;
    seg.resize(2 * size - 1, 0);
  }

  void set(int k, T x) {
    seg[k + size - 1] = x;
  }

  void build() {
    for (int i = size - 2; i >= 0; --i) {
      // iの子は, (2*i+1, 2*i+2)
      seg[i] = func(seg[2*i+1], seg[2*i+2]);
    }
  }

  void update(int k, T x) {
    // kをseg内の添字に対応させる <- (size - 1)を足す
    k += size - 1;
    seg[k] = x;
    while (k > 0) {
      k = (k - 1) / 2;
      seg[k] = func(seg[2*k+1], seg[2*k+2]);
    }
  }

  void add(int k, T x) {
    // kをseg内の添字に対応させる <- (size - 1)を足す
    k += size - 1;
    seg[k] += x;
    while (k > 0) {
      k = (k - 1) / 2;
      seg[k] = func(seg[2*k+1], seg[2*k+2]);
    }
  }

  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = size;
    if (r <= a || l >= b) return M1;
    if (l >= a && r <= b) return seg[k];
    T f_l = query(a, b, 2*k+1, l, (l+r)/2);
    T f_r = query(a, b, 2*k+2, (l+r)/2, r);
    return func(f_l, f_r);
  }

  void debug() {
    for (int i = 0; i < 2 * size - 1; ++i) {
      cerr << seg[i] << " \n"[i==2*size-2];
    }
  }

};

// 低い花から順に植えていく
// dp[i] := i番目の花が一番高いときの美しさの最大値
// dp[i] = max(k=0..i-1){dp[k]} + A[i]
// 区間maxをセグ木で取得してO(NlogN)

const int INF = 1 << 30;

int N;
vector<pair<int,int>> H;
vector<int> A;

signed main() {

  cin >> N;

  H.resize(N);
  REP(i, N) {
    cin >> H[i].first;
    H[i].second = i;
  }
  sort(H.begin(), H.end());

  A.resize(N);
  REP(i, N) cin >> A[i];

  SegmentTree<ll> dp(N, [](ll a, ll b){ return max(a,b); }, 0);

  EACH(h, H) {
    int i = h.second;
    ll q = dp.query(0, i);
    dp.update(i, q + A[i]);
  }

  ll res = 0;
  REP(i, N) res = max(res, dp.query(i, i + 1));
  cout << res << endl;

}


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

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

  int64_t nFact = 1;
  for (int n = 1; n <= nNum; n++)
  {
    nFact *= n;
    nFact %= 1000000007;
  }

  cout << nFact << endl;

  return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
void print_int(int n)
{
    printf("%d\n",n);
}

void swap(int * a, int * b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

void sort(int a[], int n)
{
    for(int i = 1; i < n; i++)
    {
        int j = i-1;
        while(j >= 0 && a[j+1] > a[j])
        {
            swap(&a[j+1],&a[j]);
            j--;
        }
        
    }
    
}

void print_list(int a[], int n)
{
    for(int i = 0; i < n; i++)
    {
        print_int(a[i]);
    }
    
}



int main(void)
{
    int n,k;
    char s[10];

    scanf("%d", &n);
    scanf("%s", s);
    scanf("%d", &k);

    char a = s[k-1];
    for(int i = 0; i < strlen(s); i++)
    {
        if(s[i] != a)
            s[i] = '*';
    }
    printf("%s\n",s);

    
    
    return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,c,ans=0;
int a[100010],b[100010];
int f[100010],rf[100010];
signed main(){
	cin>>n>>c;
	a[n+1]=c;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		f[i]=f[i-1]+b[i]-(a[i]-a[i-1]);
	}
	for(int i=n;i>=1;i--)
		rf[i]=rf[i+1]+b[i]-(a[i+1]-a[i]);
	for(int i=2;i<=n;i++){
		f[i]=max(f[i-1],f[i]);
	}
	for(int i=n-1;i>=1;i--){
		rf[i]=max(rf[i+1],rf[i]);
	}
	for(int i=1;i<=n;i++){
		ans=max(ans,f[i]-a[i]+rf[i+1]);
		ans=max(ans,rf[i]-(c-a[i])+f[i-1]);
		ans=max(ans,f[i]);
		ans=max(ans,rf[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;

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

  ll dp[100005][2]; //dp[n][i] 上位1~n桁目でL以下であることが下の位に関わらず確定している場合(i=0)と一致しているため確定していない場合(i=1)の個数

  dp[0][1]=1;
  dp[0][0]=0;
  for(int i=0;i<L.length();i++){
    dp[i+1][1]=0;
    dp[i+1][0]=(dp[i][0]*3)%mod; //既に確定しているならば，(0,0)(1,0)(0,1)の3パターン
    if(L[i]=='0'){
      dp[i+1][1]=dp[i][1]%mod; //(0,0)以外ではLを超えてしまう
    }else{
      //a[i]+b[i]=0
      (dp[i+1][0]+=dp[i][1])%=mod;  //(0,0)ならば小さくなることが確定
      //a[i]+b[i]
      (dp[i+1][1]+=dp[i][1]*2)%=mod; //(1,0)(0,1)ならば一致するので未確定
    }
  }

  cout<<(dp[L.length()][0]+dp[L.length()][1])%mod<<endl;

  return 0;
}



Measured memory_bytes: 2048
n,a,b,c = list(map(int, input().split()))
s = [[0]*2 for _ in range(n)]
S = []
for i in range(n):
  X = input()
  S += X
  cnt = 0
  for x in X:
    if x == 'A':
      s[i][cnt] = 0
    elif x == 'B':
      s[i][cnt] = 1
    else:
      s[i][cnt] = 2
    cnt += 1

if (a + b + c) == 0:exit(print('No'))
abc = [a,b,c]
ABC = ['A','B','C']


ans = [0] * n

def zero(xy):
  x = xy[0]
  y = xy[1]
  if abc[x] == 0 and abc[y] == 0:
    return -1,-1
  elif abc[x] == 0:
    return x,y
  elif abc[y] == 0:
    return y,x
  else:
    return 3,3

def main():
  global ans
  global abc
  
  for i in range(n):
    x,y = zero(s[i])
    if x == -1:exit(print('No'))
    if x == 3:
      if i < n-1:
        if s[i][1] in s[i+1]:
          x = s[i][1]
          y = s[i][0]
        else:
          x = s[i][0]
          y = s[i][1]
      else:
        x = s[i][0]
        y = s[i][1]
    ans[i] = x
    abc[x] += 1
    abc[y] -= 1

main()
print('Yes')
for i in range(n):
  print(ABC[ans[i]])


Measured memory_bytes: 20104
#include <iostream>

using namespace std;

int sx, sy, tx, ty;
int main(int argc, const char *argv[])
{
    cin >> sx >> sy >> tx >> ty;

    int dx = tx - sx, dy = ty - sy;

    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
    cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8         as B
import qualified Data.Vector.Unboxed           as U
import           Data.List
import           Control.Monad

main = do
  [n, c] <- map read . words <$> getLine
  d      <- U.concat <$> replicateM c readIntsU
  a      <- U.concat <$> replicateM n readIntsU
  print $f n c d a
f :: Int -> Int -> U.Vector Int -> U.Vector Int -> Int
f n c d a = minimum
  [ f cs | cs <- replicateM 3 [0 .. c - 1], length (nub cs) == 3 ] where
  f cs = sum $zipWith g cs cns
  g y = sum . zipWith f [0 .. c - 1] where f x cn = d U.! (x * c + y) * cn
  cns = map f [0 .. 2]   where
    f m =
      map (pred . length)
        $  group
        $  sort
        $  [1 .. c]
        ++ [ a U.! (i * n + j)
           | i <- [0 .. n - 1]
           , j <- [0 .. n - 1]
           , mod (i + j) 3 == m
           ]
readIntsU = U.unfoldr (B.readInt . B.dropWhile (== ' ')) <$> B.getLine


Measured memory_bytes: 16764
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();

        char c = '1';

        int ans = 0;
        for (int i = 0; i < n; i++) {
            char currentChar = s.charAt(i);
            if (c != currentChar) {
                ans++;
            }
            c = currentChar;
        }
        System.out.println(ans);

        sc.close();
    }

}


Measured memory_bytes: 24916
#include <iostream>
#include <algorithm>
using namespace std;
bool judge(int n, int k, int *a, long long x){
    long long b[500];
    int y = 0, left = 0, right = n-1;
    for(int i=0;i<n;i++){
        b[i] = *(a+i) % x;
    }
    sort(b, b+n);
    while(left < right){
        int c = min(b[left], x - b[right]);
        b[left] -= c;
        b[right] += c;
        y += c;
        if(b[right] == x)b[right--] = 0;
        else if(b[left] == 0)left++;
    }
    if(b[left] != 0)return false;
    return (y <= k);
}
int main(void){
    int n, k, ok = 1, ng = 1e7;
    int a[500];
    long long s = 0, ans = 0;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> a[i];
        s += a[i];
    }
    for(long long i=1;i*i<=s;i++){
        if(s%i == 0 && judge(n, k, a, s/i)){
            cout << s/i << endl;
            return 0;
        }
        if(s%i == 0 && judge(n, k, a, i)){
            ans = max(i, ans);
        }
    }
    cout << ans << endl;
}


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

int main() {
  long N;
  cin >> N;
  string s;
  long ans = 0;

  for (long i = 1; i <= N; i++) {
    s = to_string(i);
    if (s.size() % 2 == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B"


#include <iostream>
#include <vector>

using namespace std;
using lint = long long;


template<class T>
class FenwickTree {
private:
	int n;
	vector<T> bit;
public:
	FenwickTree(int sz, T&& x = T(0)) : n(sz), bit(n + 1) {
		for (int i = 0; i < n; i++) add(i, x);
	}

	T sum(int k) const {
		T res = 0;
		for (k--; k >= 0; k = (k & (k + 1)) - 1) res += bit[k];
		return res;
	}
	T sum(int l, int r) const { return sum(r) - sum(l); }

	void add(int k, const T& x) {
		for (; k < n; k |= k + 1) bit[k] += x;
	}
	void set(int k, const T& x) { add(k, x - sum(k, k + 1)); }
};


int main() {

	int n, q;
	cin >> n >> q;

	FenwickTree<lint> ft(n, 0);
	vector<int> ans;
	for (int i = 0; i < q; i++) {
		int c, x, y;
		cin >> c >> x >> y;
		x--;
		if (c) {
			ans.emplace_back(ft.sum(x, y));
		}
		else {
			ft.add(x, y);
		}
	}

	for (const auto& e : ans) cout << e << "\n";
	
	return 0;
}



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

using namespace std;
const int inf = 1e9+3;
int a[310][310], b[310][310], n, m, l;
int main() {
	scanf("%d%d%d", &n, &m, &l);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			a[i][j] = b[i][j] = inf;
		}
		a[i][i] = 0;	b[i][i] = 1; 
	}
	for (int i = 0; i < m; i++) {
		int x,y,z;
		scanf("%d%d%d", &x, &y, &z);
		a[x][y] = a[y][x] = z;
	}
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				a[i][j] = min(a[i][j], a[i][k]+a[k][j]);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (a[i][j] <= l) b[i][j] = 1;
		}
	}
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				b[i][j] = min(b[i][j], b[i][k]+b[k][j]);
			}
		}
	}
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			if (b[k][i] == inf) b[k][i] = -1;
		}
	}
	int q;
	scanf("%d", &q);
	while (q--) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (b[x][y] >= 0) printf("%d\n", b[x][y]-1);
		else printf("%d\n", -1);
	}
	return 0;
}

Measured memory_bytes: 1280
def calc_kitai(n):
    return (n * (n + 1) / 2) * (1 / n)


N, K = map(int, input().split())
P = list(map(int, input().split()))
sumP = []
max_idx = None
max_val = -float('inf')
for i in range(N - K + 1):
    if i == 0:
        max_val = sum(P[i:i + K])
        max_idx = i
        prv_val = sum(P[i:i + K])
    else:
        if max_val < prv_val + P[i + K - 1] - P[i - 1]:
            max_val = prv_val + P[i + K - 1] - P[i - 1]
            max_idx = i
        prv_val = prv_val + P[i + K - 1] - P[i - 1]

ans = 0
for i in range(K):
    ans += calc_kitai(P[max_idx + i])
print(ans)


Measured memory_bytes: 71792
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e6+5;
ll dp[N][2][2];
void solve(){
	int n; 
	cin>>n; 
	dp[1][0][0] = 8;
	dp[1][1][0] = dp[1][0][1] = 1;
	for(int i=1;i<n;i++){
		for(int a=0;a<=1;a++){
			for(int b=0;b<=1;b++){
				dp[i+1][a][b] += 8ll*dp[i][a][b]; // 1-8
				dp[i+1][a][b] %=mod;
				dp[i+1][1][b] += dp[i][a][b];// 0
				dp[i+1][1][b] %= mod;
				dp[i+1][a][1] += dp[i][a][b];// 9
				dp[i+1][a][1] %= mod;
			}
		}
	}
	cout<<dp[n][1][1]<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 34680
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>v(n,0);
    rep(i,n) cin >> v[i];

    ll sum =0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            sum+=v[i]*v[j];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  void solve() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; ++i) {
      if (i % k == 0) {
        cout << "OK\n";
        return;
      }
    }
    cout << "NG\n";
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;
ll ans = inf;

void recur(vector<vector<ll>> &a, vector<ll> &cost, vector<ll> &total, ll sum, ll index, ll n, ll y){
    ll m = a[0].size(), flag = 0;
    for(ll i=0;i<m;i++){
        if(total[i] < y){
            flag = 1;
        }
    }

    if(flag == 0){
        ans = min(ans, sum);        
    }

    if(index == n){
        return;
    }        

    sum += cost[index];
    for(ll i=0;i<m;i++){
        total[i] += a[index][i];
    }
    recur(a, cost, total, sum, index+1, n, y);
    sum -= cost[index];
    for(ll i=0;i<m;i++){
        total[i] -= a[index][i];
    }
    recur(a, cost, total, sum, index+1, n, y);
    return;
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,n,t,q,temp,sum=0,count=0,f=1;
    cin>>n>>m>>y;
    vector<ll> cost, total(m, 0);
    vector<vector<ll>> a;
    for(i=0;i<n;i++){
        cin>>x;
        cost.pb(x);
        vector<ll> temp;
        for(j=0;j<m;j++){
            cin>>x;
            temp.pb(x);
        }
        a.pb(temp);
    }
    recur(a, cost, total, 0, 0, n, y);
    if(ans == inf)ans = -1;
    // cout<<inf<<"\n";
    cout<<ans<<"\n";
}    
    

Measured memory_bytes: 3668
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define pb(a) push_back(a)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define INF 999999999

using namespace std;

int main(){
  string s;
  char  s1,s2,s3;
  cin >> s;
  s1=s[0];
  cin >> s;
  s2 = s[0];
  cin >> s;
  s3 = s[0];
  cout << (char)toupper(s1)<<(char)toupper(s2)<<(char)toupper(s3) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gcd __gcd
//SUNEET KUMAR -->  ਸੁਨੀਤ  
int power(int a,int n)//binary expo
{
    int r;
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
        r=power(a,n/2);
    if(n%2==0)
        return ((r)%mod)*((r)%mod)%mod;
    else
        return ((((r)%mod)*((r)%mod))%mod*((a)%mod))%mod;
}
int max(int a,int b)
{
    if(a>b)
        return a;
    else
        return b;
}
signed main()
{ 
     fastio;
     int n,k;
     cin>>n>>k;
     int h[n+4];
     int dp[n+2];
     for(int i=1;i<=n;i++)
     {
         cin>>h[i]; 
     }
     dp[1]=0;
     dp[2]=abs(h[2]-h[1]);
     for(int i=3;i<=n;i++)
     {
         vector<int>v;
         for(int j=1;j<=k;j++)
         {
             if(i>j)
             {
                v.pb(dp[i-j]+abs(h[i]-h[i-j]));
             }
             else
             {
                 break;
             }
         }
         sort(v.begin(),v.end());
         dp[i]=v[0];
         v.clear();
     }
     cout<<dp[n]<<endl;

      

}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	string s,t;
	int n,ans=0;
	cin>>s>>n;
	rep(i,0,n){
		cin>>t;
		t+=t;
		if(t.find(s)!=string::npos) ans++;
	}
	o(ans);
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

struct BIT {
    ll n;
    VL dat;
    void init(ll in) {
        n = in + 1;
        dat.resize(n + 1);
        eFOR(i, 0, n)dat[i] = 0;
    }
    ll sum(ll i) {
        ll s = 0;
        while (i >= 0) {
            s += dat[i];
            i = (i & (i + 1)) - 1;
        }
        return s;
    }
    void add(ll i, ll x) {
        while (i <= n) {
            dat[i] += x;
            i |= i + 1;
        }
    }
};

int main() {
    ll n;
    cin >> n;
    VL a(n), sorted(n);
    FOR(i, 0, n) {
        cin >> a[i];
        sorted[i] = a[i];
    }
    SORT(sorted);
    int ok = 0, ng = n;
    BIT bit;

    ll border = ((n * (n + 1) / 2) + 1) / 2;
    while (ng - ok > 1) {
        int mid = (ng + ok) / 2;
        int midnum = sorted[mid];
        bit.init(2 * n + 1);
        int sum = 0;
        bit.add(sum + n, 1);
        ll result = 0;
        FOR(i, 0, n) {
            sum += (a[i] >= midnum ? 1 : -1);
            result += bit.sum(sum + n);
            bit.add(sum + n, 1);
        }
        if (result >= border)ok = mid;
        else ng = mid;
    }
    cout << sorted[ok] << endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int ans = 0;

void dfs(int n,ll s){
	if(s > n) return;
	string t = to_string(s);
	int cnt3 = 0;
	int cnt5 = 0;
	int cnt7 = 0;
	rep(i,t.size()){
		if(t[i] == '3') cnt3++;
		if(t[i] == '5') cnt5++;
		if(t[i] == '7') cnt7++;
	}
	if(cnt3 && cnt5 && cnt7) ans++;

	dfs(n,s*10+3);
	dfs(n,s*10+5);
	dfs(n,s*10+7);
}

int main(){
	int N; cin >> N;
	dfs(N,0);
	cout << ans << endl;
	


}



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

int main()
{
    long long n,k;
    cin >> n >> k;
    if(n <= k){
        cout << 0 << endl;
        return 0;
    }
    priority_queue<long long> q;
    for(int i=0; i<n; i++){
        long long a;
        cin >> a;
        q.push(a);
    }
    
    while(k--) q.pop();
    long long ans = 0;
    while(!q.empty()){
        ans += q.top();
        q.pop();
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3444
import sys
from string import ascii_uppercase

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    ans = [0] * len(S)
    for i, c in enumerate(S):
        ans[i] = ascii_uppercase[(ascii_uppercase.index(c) + N) % 26]

    print(''.join(ans))
    return


if __name__ == '__main__':
    main()


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define END(x) cout << x << endl; exit(0);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, minimum, maximum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> n;
    for (int i = 111; i <= 999; i+=111) {
        if (i >= n) {
            END(i)
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
char st[200003];
int al[26];
int main()
{
 scanf("%s",st);
 int len = 0;
long long int ans=0;
for(;st[len];len++)
{
al[st[len]-'a']++;
}
ans = (long long int)(len)*(len-1)/2;
for(int i = 0; i < 26;i++)
ans -= (long long int)al[i]*(al[i]-1)/2;
printf("%lld\n",ans+1);
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(){
  int n;
  vector<long long int> a;
  cin>>n;

  long long int tmp;
  for(int i=0;i<n;i++){
    cin>>tmp;
    a.pb(tmp);
  }
  sort(a.begin(),a.end());
  vector<long long int> b;
  vector<long long int> c;

  int l,r,l2,r2;
  l=1;r=n-1;
  l2=0;r2=n-2;
  b.pb(a[0]);
  c.pb(a[n-1]);

  bool flag=true;
  for(int i=1;i<n;i++){
    if(flag){
      if(i%2==1){
	b.insert(b.begin(),a[r--]);
	c.insert(c.begin(),a[l2++]);
      }
      else{
	b.pb(a[r--]);
	c.pb(a[l2++]);
      }
    }
    else{
      if(i%2==1){
	b.insert(b.begin(),a[l++]);
	c.insert(c.begin(),a[r2--]);
      }
      else{
	b.pb(a[l++]);
	c.pb(a[r2--]);
      }
    }
    if(i%2==0) flag=!flag;
  }
  /*
  for(int i=0;i<n;i++){
    printf(":%d %d\n",a[i],b[i]);
    }*/
  tmp=0;
  long long int tmp2=0;
  for(int i=1;i<n;i++){
    tmp+=llabs(b[i]-b[i-1]);
    tmp2+=llabs(c[i]-c[i-1]);
  }
  cout<<max(tmp,tmp2)<<endl;
  return 0;
}


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int mod = 1e9+ 7;

void make(vector<int> &p){

    for(int x=0; x*x <= 10000 ; x++){

        if(!p[x])   continue;

        for(int i = 2*x; i <= 10000 ; i+= x)
            p[i] = 0;

    }

}

int32_t main(){

    int n;  cin >> n;
    vector<int> p(100000,1) ; p[1] = 0 , p[0] = 0 ;

    make(p);

    vector<int> pows(100000,0);

        for(int x=2 ; x<= 1000;x++){

            if(!p[x]) continue; 

            int pr = x;

            for(int i=1;i<=n;i++){
                int num = i;
                while(num % pr == 0){
                    pows[pr]++ , num /= pr;
                }
            }

        }

    vector<int> ans;

    for(int x=0;x<=1000;x++)
        if(pows[x] > 0)
            ans.push_back(pows[x] + 1);

    int final = 1;

    for(auto x : ans){
        final =( (x % mod ) * ( final % mod) ) % mod;
    }

    cout << final << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, Q;
string S;
char T[212345], D[212345];

bool check(int pos) {
	REP(i, Q) if (S[pos] == T[i]) {
		pos = pos + (D[i] == 'R' ? 1 : -1);
		if (pos < 0 || pos >= N) break;
		
	}
	return pos < 0;
}

int solve() {
	// [l, r) 落ちる最右を知りたい
	if (!check(0)) return -1;
	
	int l = 0, r = N;
	while (r - l > 1) {
		int m = (l + r) / 2;
		if (check(m)) l = m;
		else r = m;
	}
	return l;
}

int main() {
	cin >> N >> Q;
	cin >> S;
	
	REP(i, Q) {
		string t, d;
		cin >> t >> d;
		T[i] = t[0];
		D[i] = d[0];
	}
	
	int p = solve();
	reverse(ALL(S));
	REP(i, Q) D[i] = (D[i] == 'R' ? 'L' : 'R');
	int q = N - solve() - 1;
	
	int ans;
	if (p >= q) ans = N;
	else ans = q - p - 1;
	
	cout << ans << endl;
	
	return 0;
}


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

int main(){
	int a[100],b[100],c[100],n;
	int ans=0,tmp=0,tmp2=0;

	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	for(int i=1;i<=n-1;i++){
		scanf("%d",&c[i]);
	}
	for(int i=1;i<=n;i++){
		tmp = a[i];
		if(a[i]!=a[i-1]+1){
			ans += b[tmp];
		}else{
			ans += b[tmp] + c[tmp-1];
		}
	}		
	printf("%d\n", ans);
}

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

int main (int argc, char* argv[])
{
    int a, b;
    cin >> a >> b;

    if (a < -1000) return 0;
    if (1000 < b) return 0;

    if (a < b) cout << "a < b" << endl;
    else if (a > b) cout << "a > b" << endl;
    else cout << "a == b" << endl;

    return 0;
}

Measured memory_bytes: 3048