akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int q = scanner.nextInt();
        long [] shines = new long[a];
        long [] temples = new long[b];
        long[] query = new long[q];
        for (int i = 0; i < a; ++i) {
            shines[i] = scanner.nextLong();
        }
        for (int i = 0; i < b; ++i) {
            temples[i] = scanner.nextLong();
        }
        for (int i = 0; i < q; ++i) {
            query[i] = scanner.nextLong();
        }
        Arrays.sort(shines);
        Arrays.sort(temples);

        for (int j = 0; j < q; ++j) {
            int shineIndex = -(Arrays.binarySearch(shines, query[j]) + 1);
            int templeIndex = -(Arrays.binarySearch(temples, query[j]) + 1);
            long res = Long.MAX_VALUE;
            // ab x
            if (shineIndex -1 >= 0 && templeIndex - 1 >= 0) {
                long current = Math.max(query[j] - shines[shineIndex - 1], query[j] - temples[templeIndex - 1]);
                res = Math.min(res, current);
            }

            // x ab
            if (shineIndex < a && templeIndex < b) {
                long current = Math.max(shines[shineIndex] - query[j], temples[templeIndex] - query[j]);
                res = Math.min(res, current);
            }


            // a x b
            if (shineIndex - 1 >= 0 && templeIndex < b) {
                long current1 = temples[templeIndex] - shines[shineIndex - 1] +
                        query[j] - shines[shineIndex - 1];
                long current2 = temples[templeIndex] - shines[shineIndex - 1] +
                        temples[templeIndex] - query[j];
                long current = Math.min(current1, current2);
                res = Math.min(res, current);

            }

            // b x a
            if (templeIndex - 1 >= 0 && shineIndex < a) {
                long current1 = shines[shineIndex] - temples[templeIndex - 1] +
                        query[j] - temples[templeIndex - 1];
                long current2 = shines[shineIndex] - temples[templeIndex - 1] +
                        shines[shineIndex] - query[j];
                long current = Math.min(current1, current2);
                res = Math.min(res, current);
            }
            System.out.println(res);
        }
    }


}


Measured memory_bytes: 108348
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    double a,b,x,y,g,h,z;
    cin >> a >> b >> x >> y;
    g = a - x;
    h = b - y;
    z = g*g+h*h;
    cout << fixed << setprecision(8) << sqrt(z) << endl;
}
    
    
    


Measured memory_bytes: 3292
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.io.PrintWriter;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        PrintWriter out = new PrintWriter(System.out);

        final String[] sl = s.split(" ");
        long N = Integer.parseInt(sl[0]);
        long M = Integer.parseInt(sl[1]);

        if (N == 1) {
            if (M == 1) out.println(1);
            else out.println(M - 2);
        } else {
            if (M == 1) out.println(N - 2);
            else out.println((N - 2) * (M - 2));
        }

        out.flush();
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
void solve(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<int>cost(n);
    int a[n][m];
    for(int i=0;i<n;i++){
        cin>>cost[i];
        for(int j=0;j<m;j++)
        cin>>a[i][j];
    }
    int max = pow(2,n);int ans=INT_MAX;
    for(int i=0;i<max;i++){
        int total=0;
        vector<int>exp(m,0);
        for(int j=0;j<n;j++){
            if(i&(1<<j)){
                total+=cost[j];
                for(int k=0;k<m;k++)
                exp[k]+=a[j][k];
            }
        }
        bool ok=true;
        for(int j=0;j<m;j++)
        {
            if(exp[j]<x) ok=false;
        }
        if(ok) ans=min(ans,total);
    }
    if(ans==INT_MAX) cout<<-1<<'\n';
    else cout<<ans<<'\n';
}
int  main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
    //cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 4044
using System;
class A{
    static void Main(string[]args){
        int N=int.Parse(Console.ReadLine());
        int d=(int)Math.Pow(10,6);
        int c=0;
        for(int i=1;i<=N-i;i++){
            c=sumi(i)+sumi(N-i);
            if(c<d) d=c;
        }
        Console.WriteLine(d);

    }
    static int sumi(int n){
        int SUM=0;
        while(n!=0){
            SUM=SUM+(n%10);
            n=n/10;
        }
        return SUM;
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <climits>
#define SIZE 100001
#define INF INT_MAX >> 1
 
using namespace std;
 
int dp[SIZE];
 
int main(void){
	int n, k; cin >> n >> k;
	int h[SIZE] ={0};
	for(int i=0; i<n; i++){
		cin >> h[i];
	}
 
	fill(dp, dp+n, INF);
	dp[0] = 0;
	for(int i=1; i<n; i++){
		for(int j=1; j<=k; j++){
			if(i-j >= 0) dp[i] = min(dp[i], dp[i-j] + abs(h[i-j]-h[i]));
		}
	}
 
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

// int gcd(int a, int b) {
//     if (a < b) swap(a, b);
//     if (a % b)
//         return gcd(b, a % b);
//     else
//         return b;
// }

template <class Type>
Type gcd(Type a, Type b) {
    if (a < b) swap(a, b);
    if (a % b)
        return gcd(b, a % b);
    else
        return b;
}

int main() {
    int n;
    cin >> n;
    vector<int> x(n + 1);
    for (int i = 0; i <= n; i++) {
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        d[i] = x[i + 1] - x[i];
    }
    int ans = d[0];
    for (int i = 1; i < n; i++) {
        ans = gcd(ans, d[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3952
N=int(input())
A=list(map(int, input().split()))
ans=1
for i, a in enumerate(A):
  if i==0:
    flag=0
  elif flag==0 and a==A[i-1]:
    pass
  elif a>=A[i-1] and flag>=0:
    flag=1
  elif a<=A[i-1] and flag<=0:
    flag=-1
  else:
    flag=0
    ans+=1
print(ans)

Measured memory_bytes: 62704
#include <iostream>
using namespace std;
string s;
int main() {
	int i, j;
	cin>>s;
	for(i=0; s[i]!='A'; i++);
	for(j=s.size()-1; s[j]!='Z'; j--);
	cout<<j-i+1;
	return 0;
}

Measured memory_bytes: 640
x,y,a,b,c = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
ans = []
P.sort()
Q.sort()
R.sort()
for i in range(x):
    ans.append(P[a-i-1])
for i in range(y):
    ans.append(Q[b-i-1])
flag = True
ans.sort()
ans_sum = sum(ans)
cur = c-1
temp = 0
for i in range(c):
    if cur >= 0 and temp <= (x+y-1):
        if R[cur] >= ans[temp]:
            ans_sum += R[cur]-ans[temp]
            cur -= 1
            temp += 1
print(ans_sum)


Measured memory_bytes: 22720
a, b, c = map(int, input().split())

ans = 'NO'
if a < b and c%a == 0:
  ans = 'YES'
else:
  for i in range(1, 10000):
    if (b*i + c)%a == 0:
      ans = 'YES'
      break
  
print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main()
{
    ll n; cin >> n;
    ll s = (int)sqrt(n);
    ll t;
    while(1){
        if(!(n%s)) { t = n/s; break;}
        s--;
    }

    ll ans = s + t - 2;

    cout << ans << endl;

    return 0;
} 

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int D;
vll C, T;
vvll S;

inline ll calcScore() {
	vll last(26, -1);	
	ll score = 0;
	for (int i = 0; i < D; i++) {
		score += S[i][T[i]];
		last[T[i]] = i;
		for (int j = 0; j < 26; j++) {
			score -= (i-last[j])*C[j];
		}
	}
	return (score);
}

void Main() {
	cin >> D;
	C = makeVector(26, 0ll); cin >> C;
	S = makeVector(D, 26, 0ll); cin >> S;
	T = makeVector(D, 0ll);
	
	vll last(26, -1);	
	for (int i = 0; i < D; i++) {
		ll maxp = -1, maxd = -LLINF;
		ll decr = 0;
		for (int k = 0; k < 26; k++) {
			decr += (i-last[k]) * C[k];
		}
		for (int j = 0; j < 26; j++) {
			ll sc = S[i][j] - decr + (i-last[j]) * C[j];
			if (maxd < sc) {
				maxp = j;
				maxd = sc;
			}
		}
		T[i] = maxp;
		last[T[i]] = i;
	}
	
	ll maxv = -LLINF;
	int M = 240000;
	for (int i = 0; i < M; i++) {
		int d = rand()%D;
		int q = rand()%26;
		ll tmp = T[d];
		T[d] = q;
		ll score = calcScore();
		if (score <= maxv) T[d] = tmp;
		else maxv = score;
	}
	
	for (int i = 0; i < D; i++) {
		cout << T[i]+1 << el;
	}
	//cout << maxv << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3752
x = input().split()
l = ""
m = 0
Count = 0
mostword = ""

for i in range(len(x)):
    if len(x[i]) > len(l):
        l = x[i]

for j in range(len(x)):
    a = x[j]
    Count = x.count(a)
    if Count > m: 
        m = Count
        mostword = a

print(mostword, l)


Measured memory_bytes: 5560
if __name__ == "__main__":
    N, K = map(int, input().split())
    h = list()
    for i in range(N):
        h.append(int(input()))

    h = sorted(h)

    res = 10 ** 9 + 1
    for i in range(N-K+1):
        if res > h[i+K-1] - h[i]:
            res = h[i+K-1] - h[i]
    
    print(res)


Measured memory_bytes: 8280
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;


signed main()
{
	int N, M;
	cin >> N >> M;

	if (abs(N - M) > 1)
	{
		cout << "0" << endl;
		return 0;
	}

	int a = N;
	int b = M;

	for (int i = N - 1; i >= 1; i--)
	{
		a *= i;
		a %= 1000000007;
	}
	for (int i = M - 1; i >= 1; i--)
	{
		b *= i;
		b %= 1000000007;
	}

	if (N - M == 0)
	{
		int ans = (a * b) % 1000000007;
		ans *= 2;
		ans %= 1000000007;
		cout << ans << endl;
	}
	else
	{
		int ans = (a * b) % 1000000007;
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SORT(A) std::sort(A.begin(), A.end())
#define RSORT(A) std::sort(A.begin(), A.end(), std::greater<>())
#define FR(A, e) for (auto& e : A)
#define SHOW(A) for (auto& e : A) {cout << e << " ";}; cout << endl;
#define within(x,_left,_right) (_left <= x && x <= _right)
#define rwithin(x, _l, _r) (_l < x && x < _r)
#define ALL(A) A.begin(),A.end()
#define RALL(A) (A).rbegin(),(A).rend()
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define sz(x) ((int)x.size())
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define bitcnt(x) (__builtin_popcountll(x))
#define fi first
#define se second
#define bg(A) A.begin()
#define ed(A) A.end()
#define rbg(A) A.rbegin()
#define red(A) A.rend()
using LL = long long;
using db = double;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VL = vector<LL>;
using VVL = vector<VL>;
const LL MOD = 1e9 + 7;
const LL LMAX = 0x7fffffffffffffff;
const LL LMIN = 0x8000000000000000;
typedef std::pair<int, int> PII;
typedef std::pair<LL, LL> PLL;
typedef std::pair<int, char> PIC;
// int dx[4] = {1, -1, 0, 0}; // 冯诺依曼型邻居
// int dy[4] = {0, 0, 1, -1};
// int dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; // 摩尔型邻居
// int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
// #include<iomanip> cout << fixed <<  setprecision(k) 输出k位精度


int main(){
    int n; cin >> n;
    int ac, wa, tle, re;
    ac = wa = tle = re = 0;

    string s;
    for (int i = 0; i < n; ++ i){
        cin >> s;
        if (s == "AC") ++ ac;
        else if (s == "WA") ++ wa;
        else if (s == "TLE") ++ tle;
        else if (s == "RE") ++ re;
    }
    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);

    return 0;
}

Measured memory_bytes: 3684
from math import ceil
time_setting = []
for _ in range(5):
    time_setting.append(int(input()))

ones_place = [i % 10 if i % 10 != 0 else 10 for i in time_setting]
ans = 0
for time in time_setting:
        ans += ceil(time / 10) * 10

ans -= 10 - min(ones_place)  
print(ans)

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())

ll MOD(ll x, ll m) {
    ll r = x % m;
    if (r < 0) {
        r += m;
    }
    return r;
}

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 9e18
#define MINF -INF


const ll md = 1e9 + 7;

void add_self(ll& a, ll b) {
    a = MOD((a + b), md);
}

void sub_self(ll& a, ll b) {
    a = MOD((a - b), md);
}

void mul_self(ll& a, ll b) {
    a = MOD((a * b), md);
}

ll power(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) {
            mul_self(res, a);
        }
        mul_self(a, a);
        b >>= 1;
    }
    return res;
}

ll mod_inverse(ll a) {
    return power(a, md-2); // only when md is prime
}

vll factorial;
void computeFactorials(ll n) {
    factorial.resize(n + 1);
    factorial[0] = 1;
    for (ll i = 1; i <= n; i++) {
        factorial[i] = MOD(factorial[i - 1] * i, md);
    }
}

ll choose(ll n, ll k) {
    ll a = mod_inverse(factorial[k]);
    ll b = mod_inverse(factorial[n - k]);
    ll ab = MOD(a * b, md);
    return MOD(factorial[n] * ab, md);
}

void solve() {
    ll k;
    cin >> k;
    string s;
    cin >> s;
    ll n = s.size();
    computeFactorials(n+k);
    ll res = 0;
    FOR(i, 0, k+1) {
        ll cur = 1;
        mul_self(cur, power(26, i));
        mul_self(cur, choose(n+k-1-i, n-1));
        mul_self(cur, power(25, k-i));
        add_self(res, cur);
    }
    // cout << fixed << setprecision(6);
    cout << res << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 19820
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderMake.ABC171
{
    class ABC171C
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            List<char> ans = new List<char>();
            String ret="";
            while (n != 0)
            {
                n--;
                ans.Add(alphNum(n));
                n = n / 26;
            }
            for(int i = 0; i < ans.Count; i++)
            {
                ret += ans[ans.Count - i - 1];
            }
            Console.WriteLine(ret);
        }

        static char alphNum(long num)
        {
            long amari = num % 26;
            return (char)(97 + amari);
        }
        
    }
}


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code
char arr[2010][2010];
ll diff[2010][2010];
int main()
{
	int n, m;
	cin>>n>>m;
	repn(i, 1, n)
		repn(j, 1, m)
		{
			cin>>arr[i][j];
		}
	repn(i, 1, n)
	{
		int left[m+2], right[m+2];
		left[0] = 0;
		right[m+1] = m+1;
		repn(j, 1, m)
		{
			if(arr[i][j] == '.') left[j] = left[j-1];
			else left[j] = j;
		}
		repb(j, m, 1)
		{
			if(arr[i][j] == '.') right[j] = right[j+1];
			else right[j] = j;
		}
		repn(j, 1, m)
		{
			diff[i][j] = j - left[j] + right[j] - j - 1;
		}
	}
	
	repn(i, 1, m)
	{
		int left[n+2], right[n+2];
		left[0] = 0;
		right[n+1] = n+1;
		repn(j, 1, n)
		{
			if(arr[j][i] == '.') left[j] = left[j-1];
			else left[j] = j;
		}
		repb(j, n, 1)
		{
			if(arr[j][i] == '.') right[j] = right[j+1];
			else right[j] = j;
		}
		repn(j, 1, n)
		{
			diff[j][i] += j - left[j] + right[j] - j - 1;
		}
	}
	ll ans = 0;
	repn(i, 1, n)
	{
		repn(j, 1, m){
		  chmax(ans, diff[i][j] - 1);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 35712
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = sum(B)
before = -9999
for i in range(N):
  now = A[i]
  if now == before + 1:
    ans += C[A[i-1]-1]
  before = A[i]
print(ans)

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

int main()
{
    int N,i,min,max;
    cin >> N;
    int A[N];
    for ( i = 0; i < N; i++ ){cin >> A[i];}
    min = A[0];
    max = A[0];
    for ( i = 1; i < N; i++)
    {
        if (max<A[i]) max = A[i];
        else if (min>A[i]) min = A[i];
    }
    
    cout << max-min << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int a,b,c,d;
string ans;
int main() {
	int aa;
	cin >>aa;
	a = aa / 1000;
	b = (aa - a * 1000) / 100;
	c = (aa - a * 1000-b*100) / 10;
	d = (aa - a * 1000-b*100-c*10);
	if (a + b + c + d == 7) {
		cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
	}
	else if (a - b + c + d == 7) {
		cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
	}
	else if (a + b - c + d == 7) {
		cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
	}
	else if (a + b + c - d == 7) {
		cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
	}
	else if (a - b - c + d == 7) {
		cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
	}
	else if (a + b - c - d == 7) {
		cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
	}
	else if (a - b + c - d == 7) {
		cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
	}
	else if (a - b - c - d == 7) {
		cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
	}
	return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  ll N,A,B,C,D,E;
  cin>>N>>A>>B>>C>>D>>E;
  ll Min=min({A,B,C,D,E});
  cout<<(N+Min-1)/Min+4<<endl;
  return 0;
}


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


# xCy = xCx-y
# あるaについて，a/2に近い方が良い
# -> |aj - a / 2|となるajを選ぶ (a以外)

maxA = max(A)
mv = float("inf")
aj = None
for a in A:
    if a != maxA:
        value = abs(a - maxA // 2)
        if value < mv:
            mv = value
            aj = a

print(maxA, aj)

Measured memory_bytes: 62704
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

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

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

bool a[10];
bool f(int x){
	if(x == 0)return true;
	if(a[x%10])return false;
	return f(x/10);
}
	

int main(){
	int n,k,d[10];
	scanf("%d%d",&n,&k);
	rep(i,k)scanf("%d",&d[i]);
	
	rep(i,10)a[i] = false;
	rep(i,k)a[d[i]] = true;
	
	for(int i = n ; ; i ++){
		if(f(i)){
			cout << i << endl;
			return 0;
		}
	}
}



Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#include <math.h>
#include <bits/stdc++.h>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() {
	int a,b;
	cin >> a >> b;
	cout << a*b << " " << 2*a+2*b << endl;
}



Measured memory_bytes: 3084
m, d = input().split()

if len(d) == 1:
  print(0)
  exit()

result = 0

for month in range(int(m)):
  for day in range(10, int(d)):
    d_1, d_10 = map(int, str(day+1))
    if 2 <= d_1 and 2 <= d_10 and d_1 * d_10 == month+1:
      result += 1
    
print(result)

Measured memory_bytes: 9136
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, n) for (int i = int(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
using DI = pair<double, int>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

lint gcd(lint a, lint b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

int main() {
	string s;
	cin >> s;
	if (s == "SUN") cout << 7 << endl;
	else if (s == "MON") cout << 6 << endl;
	else if (s == "TUE") cout << 5 << endl;
	else if (s == "WED") cout << 4 << endl;
	else if (s == "THU") cout << 3 << endl;
	else if (s == "FRI") cout << 2 << endl;
	else cout << 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> v1,v2;
	std::map<ll, ll> map1,map2;
	rep(i,N){
		int v;
		cin>>v;
		if(i%2 == 0){
			v1.push_back(v);
			map1[v]++;
		}
		else{
			v2.push_back(v);
			map2[v]++;
		}
	}
	vector<P> cnt1,cnt2;
	//個数、keyのPairのベクター
	for(auto x :  map1){
		cnt1.push_back({x.second,  x.first});
	}
	for(auto x :  map2){
		cnt2.push_back({x.second,  x.first});
	}
	cnt1.push_back({0,0});
	cnt2.push_back({0,0});
	sort(all(cnt1));
	sort(all(cnt2));
	printpair(cnt1);printpair(cnt2);
	int ans  = N;
	int N1 = cnt1.size();
	int N2 = cnt2.size();
	if(cnt1[N1-1].second==cnt2[N2-1].second){
		ans -= max(cnt1[N1-1].first+cnt2[N2-2].first,cnt1[N1-2].first+cnt2[N2-1].first);
	}
	else{
		ans -= cnt1[N1-1].first+cnt2[N2-1].first;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 8052
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
const int size=4000;
vi graph[size];
int lineDistances[size][size];
vvb visited(size, vb(size));
vi vertexA, vertexB;
int number, diameter;
void dfs(int root, int start, int distanceInLines)
{
	//commandsBeforeVisitRecursion.
	visited[root][start]=true;
	lineDistances[root][start]=distanceInLines;
	for(int next : graph[start])
	{
		if(!visited[root][next])
		{
			dfs(root, next, distanceInLines+1);
		}
	}
	//commandsAfterVisitRecursion.
}
void usingDFS()
{
	cin>>number>>diameter;
	int vertex0, vertex1;
	for(int i=1; i<number; ++i)
	{
		cin>>vertex0>>vertex1;
		graph[vertex0].push_back(vertex1);
		graph[vertex1].push_back(vertex0);
		vertexA.push_back(vertex0);
		vertexB.push_back(vertex1);
	}
	for(int vertex=1; vertex<=number; ++vertex)
	{
		dfs(vertex, vertex, 0);
	}
	if(diameter%2==0)
	{
		int minimum=40000;
		for(int i=1; i<=number; ++i)
		{
			int counter=0;
			for(int j=1; j<=number; ++j)
			{
				if(lineDistances[i][j]>diameter/2)
				{
					++counter;
				}
			}
			minimum=min(minimum, counter);
		}
		cout<<minimum<<endl;
	}
	else
	{
		int dotA, dotB, tempMaxDist, minimum=40000;
		for(int i=0; i<vertexA.size(); ++i)
		{
			int counter=0;
			dotA=vertexA[i];
			dotB=vertexB[i];
			for(int j=1; j<=number; ++j)
			{
				tempMaxDist=min(lineDistances[j][dotA], lineDistances[j][dotB]);
				if(tempMaxDist>diameter/2)
				{
					++counter;
				}
			}
			minimum=min(minimum, counter);
		}
		cout<<minimum<<endl;
	}
}
/*
template<typename Type>
void showContent(Type inputVector)
{
	for(int i=1; i<=number; ++i)
	{
		for(int j=1; j<=number; ++j)
		{
			cout<<"["<<i<<"]["<<j<<"] <- "<<inputVector[i][j]<<endl;
		}
	}
	return;
}
*/
/*
template<typename NewType>
void showContent0(NewType inputVector)
{
	for(int i=0; i<inputVector.size(); ++i)
	{
		for(int j=0; j<inputVector.size(); ++j)
		{
			cout<<"["<<i<<"]["<<j<<"] <- "<<inputVector[i][j]<<endl;
		}
	}
	return;
}
*/
/*
template<typename TypeName>
void showContent1(TypeName inputVector)
{
	for(int i=0; i<inputVector.size(); ++i)
	{
		cout<<inputVector[i]<<", ";
	}
	return;
}
*/
int main()
{
    usingDFS();
        //cout<<endl;
	//showContent(visited);
	//cout<<endl;
	//showContent(lineDistances);
	//cout<<endl;
	//showContent0(visited);
	//cout<<endl;
	//showContent0(lineDistances);
	//cout<<endl;
	//showContent1(vertexA);
	//cout<<endl;
	//showContent1(vertexB);
	return 0;
}

Measured memory_bytes: 34816
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = input().split()

print(M + N)

Measured memory_bytes: 59500
#lines = <<'EOS'
#5 3
#1 2 3 4 5
#EOS

lines = $stdin.read
array = lines.split("\n")
n,k = array[0].split(" ").map(&:to_i)
lar = array[1].split(" ").map(&:to_i)

s = 0
lar = lar.sort.reverse

for i in 0..k-1
  s += lar[i]
end

puts s


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int sum,sum1;
int main() {
	string s;
	cin>>s;
	for(int i=0; i<s.size(); i++) {
		if(s[i]=='S') {
			sum++;
		}
		if(sum>0&&s[i]=='T') {
			sum1+=2;
			sum--;
		}
	}
	cout<<s.size()-sum1<<endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  cout << N*(N-1) / 2 + M*(M-1) / 2 << endl;
  return 0;
}




Measured memory_bytes: 3608
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int n, k;
bool can_use[10];

bool get_can_pay(int n) {
    while (n > 0) {
        // cout << n << endl;
        int digit = n % 10;
        if (!can_use[digit])
            return false;
        n /= 10;
    }
    return true;
}

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);

    cin >> n >> k;
    for (int i = 0; i <= 9; i++) {
        can_use[i] = true;
    }
    for (int i = 0; i < k; i++) {
        int m1;
        cin >> m1;
        can_use[m1] = false;
    }

    while (!get_can_pay(n)) {
        n++;
    }
    cout << n << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;

namespace AtCorder
{
  class Program
  {
    static void Main()
    {
      CheckCookies();
    }

    static void CheckCookies()
    {
      string[] charaList = ReadLine().Split(' ');
      int A,B,K;
      A = int.Parse(charaList[0]);
      B = int.Parse(charaList[1]);
      K = int.Parse(charaList[2]);

      for(int i = 0; i < K; i++)
      {
        if(i%2 == 0)
        {
          if(A%2 == 1) A--;
          B += A / 2;
          A = A / 2;
        } 
        else
        {
          if(B%2 == 1) B--;
          A += B / 2;
          B = B / 2;
        } 
      }
      WriteLine(A + " " + B);
    }
  }
}

Measured memory_bytes: 11092
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {
	int N, M;
	cin>>N>>M;
	map<int, vector<int>> g;
	for (int i = 0;i < M;++i) {
		int x, y;
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}

	vector<bool> v(N+1, false);
	function<void(int)> dfs = [&] (int r) {
		if (v[r]) return;
		v[r] = true;
		auto neighs = g[r];
		for (int i = 0;i < neighs.size();++i) {
			if (v[neighs[i]]) continue;
			dfs(neighs[i]);
		}
	};
	
	int ans = 0;
	for (int i = 1;i <= N;++i) {
		if (!v[i]) ++ans;
		dfs(i);
	}


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


Measured memory_bytes: 16236
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        List<Integer> red = new ArrayList<Integer>();
        List<Integer> green = new ArrayList<Integer>();
        List<Integer> white = new ArrayList<Integer>();
        for (int i=0; i<A; i++) {
            red.add(sc.nextInt());
        }
        for (int i=0; i<B; i++) {
            green.add(sc.nextInt());
        }
        for (int i=0; i<C; i++) {
            white.add(sc.nextInt());
        }
        Collections.sort(red, Collections.reverseOrder());
        Collections.sort(green, Collections.reverseOrder());
        Collections.sort(white, Collections.reverseOrder());
        List<Integer> all = new ArrayList<Integer>();
        all.addAll(red.subList(0, X));
        all.addAll(green.subList(0, Y));
        all.addAll(white);
        Collections.sort(all, Collections.reverseOrder());
        long sum = 0;
        for (int x: all.subList(0, X+Y)) {
            sum += (long)x;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 97184
N,W = map(int,input().split())
dp = [0]*(W+1)
for _ in range(N):
    w,v = map(int,input().split())
    if w > W:
        continue
    else:
        for j in range(w,W+1)[::-1]:
            if dp[j] < dp[j-w]+v:
                dp[j] = dp[j-w]+v
print(dp[W])

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

int main(){
	
	double a, b, c, d, e, f, x=0, y=0; // ???????°???°?????°??? %f
	while(cin >> a >> b >> c >> d >> e >> f){
		x = (double)( (b*f-c*e)/(b*d-a*e) );
		y = (double)( (a*f-c*d)/(a*e-b*d) );
		if(x == 0) x = 0.000;
		if(y == 0) y = 0.000;

		printf("%.3f %.3f\n",x,y);
	}
}

Measured memory_bytes: 3208
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 2e5 + 5, LG = 19, MOD = 1e9 + 7;
const int SQ =225;
const long double EPS = 1e-7;
int P[N], n, k;
set<int> st;
int mx[N], mn[N];
bool isSorted[N];
int calcSorted(){
  int ans = 0;
  vector<int> sum; sum.pb(0);
  f(i,1,n)
    sum.pb(sum.back() + (P[i] > P[i-1]));
  f(i,k-1,n){
    int tot = sum[i];
    if(i-(k-1) > 0)
      tot -= sum[i-(k-1)];
    if(tot == k - 1)isSorted[i] = 1;
  }
  return ans;
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  cin >> n >> k;

  f(i,0,n){
    cin >> P[i];
    st.insert(P[i]);
    if(i >= k - 1){
      mn[i] = *st.begin();
      mx[i] = *st.rbegin();
      st.erase(P[i-k+1]);
    }
  }
  calcSorted();
  int ans = !isSorted[k-1];
  bool f = isSorted[k-1];
  f(i,k,n){
    ///check that i - k is the minimum of p[i-k->i-1]
    ///check that i is the i is the maximum of p[i-k+1->i]
    if(P[i-k] == mn[i-1] && P[i] == mx[i])continue;
    ans+=(!isSorted[i]);
//    cout<<i<<' '<<isSorted[i]<<endl;
    f |= isSorted[i];
  }
//  cout<<ans<<endl;
  cout << ans+f << endl;


  return 0;
}


Measured memory_bytes: 11516
#include <stdio.h>

int main(){
  int N=0,A[101],i,j=0,v=0,k;

  //入力
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
   for(i=0;i<N-1;i++){
     printf("%d ",A[i]);
  }
   printf("%d",A[N-1]);
  
      printf("\n");
  //挿入ソート
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    //printf("%d",j);
    
    while(j>=0 && A[j]>v){//０番目ではないかつ取り出した数字より一つ前の数字が大きいとき
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }
      for(k=0;k<N-1;k++){
	printf("%d ",A[k]);
      }
      printf("%d",A[N-1]);
      printf("\n");
  }
  /*
    for(i=0;i<N;i++){
    for(j=0;j<N;j++){
    printf("%d ",A[j]);
    }
    printf("\n");
    }*/
  return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  ll n,k;
  cin >> n >> k;
  vl x(n);
  ll a=-1;
  rep(i,n){
    cin >> x[i];
    if(x[i]<0){
      a=i;
    }
  }
  vl dp_minus(n+2,INF);
  vl dp_plus(n+2,INF);
  dp_minus[0]=0;
  dp_plus[0]=0;
  for(ll i=a;i>=0;i--){
    dp_minus[a-i+1]=(-1)*x[i];
  }
  FOR(i,a+1,n){
    dp_plus[i-a]=x[i];
  }
  ll ans=INF;
  rep(i,k+1){
    ans=min(ans,min(2*dp_plus[i]+dp_minus[k-i],2*dp_minus[i]+dp_plus[k-i]));
    //cout << dp_plus[i] << " " << dp_minus[i] << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
def ipt(N=0,switch=0):
    if N == 0:
        return list(map(int,input().split()))
    else:
        if switch==0:
            return [list(map(int,input().split())) for _ in range(N)]
        else:
            return [int(input()) for _ in range(N)]

cnt = 0
a,b,c,x=ipt(4,1)
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                cnt += 1

print(cnt)

Measured memory_bytes: 3064
mycode = '''
# distutils: language=c++
# cython: language_level=3, boundscheck=False, wraparound=False
# cython: cdivision=True

ctypedef long long LL
cdef LL MOD = 10**9 + 7
cdef LL N = int(input())
cdef LL ans = 1

cdef i
for i in range(2, N + 1):
    ans *= i
    ans %= MOD
print(ans)
'''
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':  # コンパイル時
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    import os
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode


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

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (a >= b) {
    cout << "delicious" << endl;
  } else if (b - a <= x) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
# define M_PI           3.1415926535
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	double n;
	cin>>n;
	double x=2*M_PI*n;
	cout<<x;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    vector<ll> A(N), zero(60), one(60);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        bitset<60> bit(A[i]);
        for(int u = 0; u < 60; u++) {
            if(bit.test(u)) one[u]++;
            else zero[u]++;
        }
    }
    ll ans = 0;
    for(int i = 59; i >= 0; i--) {
        ll cnt = zero[i] * one[i] % mod, two = (ll)pow(2, i) % mod;
        ll plus = cnt * two % mod;
        ans = (ans + plus) % mod;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  long long N, M, A, max, sum;
  cin >> N >> M;

  priority_queue<long long> S;

  for (int i = 0; i < N; i++)
  {
    cin >> A;
    S.push(A);
  }

  for (int i = 0; i < M; i++)
  {
    max = S.top();
    S.pop();
    S.push(max / 2);
  }

  for (int i = 0; i < N; i++)
  {
    sum += S.top();
    S.pop();
  }

  cout << sum << endl;
}


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

int main() {
  string S;
  cin>>S;
  S+='Z';
  int ans=0;
  
  for(int i=0;i<S.size();i++){
    int ans1=0;
    int j=i;
    while(S.at(j)=='A'||S.at(j)=='T'||S.at(j)=='G'||S.at(j)=='C'){
      ans1++;
      j++;
    }
    ans=max(ans,ans1);
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#define mod 998244353
#define maxn 100005
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m;
int col[maxn][3],dp[maxn][2];//col[i][j]: color of a[i][i - 1 + j].
map <P,int> tak;
typedef map <P,int> :: iterator Ite;
bool legal(int x,int y,int c){ return col[x][y - x + 1] != 1 - c; }
void add(int &x,int y){ x += y; if(x > mod) x -= mod; }
ll modpow(ll x,ll y){
	ll res = 1;
	while(y){
		if(y & 1) res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int main(){
	memset(col,-1,sizeof(col));
	scanf("%d%d",&n,&m);
	ll pow2 = ((ll)n * n - (3ll * n - 2)) >> 1;
	bool ok = true;
	for(int i=1;i<=m;i++){
		int x,y,c;
		scanf("%d%d%d",&x,&y,&c);
		if(abs(x - y) > 2){
			Ite it = tak.find(mp(y,x));
			if(it != tak.end()){
				if(it -> second ^ c) ok = false;
			}else{
				pow2--;
				tak.insert(mp(mp(x,y),c));
			}
		}else if(x - y == 2){
			Ite it = tak.find(mp(y,x));
			if(it != tak.end()){
				if(!legal(x - 1,y + 1,it -> second ^ c)) ok = false;
				else col[x - 1][1] = it -> second ^ c;
			}else{
				pow2--;
				tak.insert(mp(mp(x,y),c));
			}
		}else if(x - y == -2){
			Ite it = tak.find(mp(y,x));
			if(it != tak.end()){
				if(!legal(x + 1,y - 1,it -> second ^ c)) ok = false;
				else col[x + 1][1] = it -> second ^ c;
			}else{
				pow2--;
				tak.insert(mp(mp(x,y),c));
			}
		}else{
			if(!legal(x,y,c)) ok = false;
			else col[x][y - x + 1] = c;
		}
	}
	if(!ok){
		puts("0");
		return 0;
	}
	dp[1][0] = legal(1,1,0);
	dp[1][1] = legal(1,1,1);
	for(int i=1;i<n;i++){
		if(legal(i,i+1,0) && legal(i+1,i,0) && legal(i+1,i+1,0)) add(dp[i+1][0],dp[i][0]);
		if(legal(i,i+1,1) && legal(i+1,i,1) && legal(i+1,i+1,0)) add(dp[i+1][0],dp[i][0]);
		if(legal(i,i+1,1) && legal(i+1,i,0) && legal(i+1,i+1,0)) add(dp[i+1][0],dp[i][1]);
		if(legal(i,i+1,0) && legal(i+1,i,1) && legal(i+1,i+1,0)) add(dp[i+1][0],dp[i][1]);
		if(legal(i,i+1,1) && legal(i+1,i,0) && legal(i+1,i+1,1)) add(dp[i+1][1],dp[i][0]);
		if(legal(i,i+1,0) && legal(i+1,i,1) && legal(i+1,i+1,1)) add(dp[i+1][1],dp[i][0]);
		if(legal(i,i+1,0) && legal(i+1,i,0) && legal(i+1,i+1,1)) add(dp[i+1][1],dp[i][1]);
		if(legal(i,i+1,1) && legal(i+1,i,1) && legal(i+1,i+1,1)) add(dp[i+1][1],dp[i][1]);
	}
	ll ans = (dp[n][0] + dp[n][1]) % mod;
	ans = ans * modpow(2,pow2) % mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;++i){
    double x1,y1,x2,y2,x3,y3,x4,y4;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
    double vx = x2-x1 , vy = y2-y1;
    double ux = x4-x3 , uy = y4-y3;
    if(abs(vx*uy-ux*vy)<1.e-10){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
}

Measured memory_bytes: 3152