akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    if (N < 2*K-1) {
        cout << -1 << ln;
        return 0;
    }

    vector<int> a(N),b(N),c(N);
    rep(i,K) {
        b[i] = K+2*N-1-i*2;
        c[i] = K+3*N-1-i;
        a[i] = c[i] - b[i];
    }
    rep(i,K-1) {
        a[i+K] = N-K+i+1;
        b[i+K] = K+2*N-2-i*2;
        c[i+K] = 3*N-1-i;
    }
    rep(i,N-2*K+1) {
        a[i+2*K-1] = K+i;
        b[i+2*K-1] = K+N+N-2*K-i;
        c[i+2*K-1] = K+2*N+i;
    }

    rep(i,N) print(a[i],b[i],c[i]);
}

Measured memory_bytes: 3584
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

/**
 * 0007:Debt Hellの解答
 * 
 * @author MS14A
 * @version 2015/04/15
 */
public class Main {

    /** 初期借金額：10万円 */
    private static final BigDecimal INITIAL_DEBT = new BigDecimal("100000");

    /** 利子：5% */
    private static final BigDecimal INTEREST_RATE = BigDecimal.valueOf(0.05);

    /** \1000未満の繰り上げ計算用 */
    private static final BigDecimal DIVISOR_FOR_ROUND_UP = BigDecimal.valueOf(1000);

    /**
     * n 週間後の借金の残高を出力する。<br>
     * ※n は 100 以下とする。
     * 
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        // 標準入力読み取り
        int weeks = getWeeks();

        // n週間後の借金額計算
        System.out.println(calcDebt(weeks));
    }

    /**
     * 標準入力を読み取り、"n"の値を返す。
     * 
     * @return n：入力値
     * @throws IOException 標準入力読取り失敗時
     */
    private static int getWeeks() throws IOException {
        
        InputStreamReader streamReader = new InputStreamReader(System.in);
        BufferedReader bufferedReader = new BufferedReader(streamReader);
        
        int weeks = Integer.parseInt(bufferedReader.readLine());
        
        bufferedReader.close();
        streamReader.close();
        
        return weeks;
    }

    /**
     * n週間後の借金額を計算する。
     * 
     * @param weeks
     * @return n週間後の借金額
     */
    private static BigDecimal calcDebt(int weeks) {
        BigDecimal finalDebt = INITIAL_DEBT;

        for (int i = 0; i < weeks; i++) {
            // 利子額計算。1000で割った小数部を繰り上げる。
            BigDecimal interestAmount = finalDebt.multiply(INTEREST_RATE)
                    .divide(DIVISOR_FOR_ROUND_UP, 0, BigDecimal.ROUND_UP);

            // 借金額 = 前週の借金額 + 利子額
            finalDebt = finalDebt.add(interestAmount.multiply(DIVISOR_FOR_ROUND_UP));
        }

        return finalDebt;
    }

}

Measured memory_bytes: 16984
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<set>
#include<fstream>
#include<map>
#include<string>
#include <stdio.h>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<climits>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef vector<char>vc;
typedef vector<string>vs;
#define MP make_pair
#define all(v) v.begin(),v.end()
const ll mod = 1000000007;
const ll OO = (ll)1e18;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
ll gcd(ll a, ll b){ if (b == 0){ return a; }return gcd(b, a % b); }
ll fast_power(double base, ll power){
	if (power == 1) return base;
	if (power % 2 == 0) return fast_power((base*base), power / 2);
	else return(base*fast_power((base*base), power / 2));
}
//#pragma warning (disable : 4996)
void Qalbaz()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
}



int main(){
	//Qalbaz();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int x, a, b;
	cin >> x >> a >> b;
	x -= a;
	while (x - b >= 0)
		x -= b;
	cout << x;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    int b,f,r,v;
    int count[4][3][10]={{{}}};
    
    cin>>n;
    
    for(int i=0;i<n;i++){
        cin>>b>>f>>r>>v;
        count[b-1][f-1][r-1]+=v;
    }
    
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout<<" "<<count[i][j][k];
            }
            cout<<endl;
        }
        if(i!=3)
        cout<<"####################"<<endl;
    }
}



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

int main() {
  string S, T;
  cin >> S >> T;

  int ans = T.size();
  for (int i = 0; i <= S.size() - T.size(); i++) {
    int diff = 0;
    rep(j, T.size()) {
      if (T[j] != S[i + j]) diff++;
    }
    ans = min(ans, diff);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(x!=a.x)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long long o[101];
int l[1];
int j[1];

long long x,y,z,mod=1000000007;
//string r;
char r[21];

P u[1];
//queue<int> q;
//stack<int> s;
set<int> s;
map<long long,int> p;

vector<int> v;

bool as(P a,P b)
{
  //if(a.x!=b.x)
  //return a.x<b.x;
  return a.x<b.x;
}

long long f(int n,int m)
{
  if(n==m) return r[n]-'0';
  return (r[m]-'0')+f(n,m-1)*10;
}

int main()
{
  scanf("%d %d %d",&a,&b,&c);
  o[0]=(long long)(a-2)*(b-2);
  for(int t=1;t<=c;t++)
  {
    scanf("%d %d",&n,&m);
    for(int h=0;h<9;h++)
    {
      int x=n+dx[h],y=m+dy[h];
      if(x<2||x>=a||y<2||y>=b) continue;
      o[p[x*mod+y]]--;
      p[x*mod+y]++;
      o[p[x*mod+y]]++;
    }
  }
  for(int h=0;h<=9;h++)
    printf("%lld\n",o[h]);
}
//2
//21



Measured memory_bytes: 58496
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

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

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    //sort(all(a));
    map <int,int> m;
    REP(i,0,n) m[a[i]]++;
    VP r;
    for (auto p: m) r.pb(p.second, p.first);
    sort(all(r));
    int ans = 0;
    int index = r.size() - 1;
    REP (i,0,r.size()) {
        auto p = r[i];
        if (p.first == 1) ++ans;
        else {
            p.first %= 2;
            if (p.first == 1) {
                ++ans;
                continue;
            }
            if (index <= i) {
                //--ans;
                continue;
            }
            ++ans;
            --r[index].first;
            while (index > i && r[index].first == 1) --index;
        }
    }
    cout << ans << endl;
    // 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1
    // 1 2 3 5 6 8 11
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 6904
n = int(input())
ls = list(map(int,input().split()))
ls2 = [0 for i in range(n)]
for j in range(n):
    a = ls[j]
#aは出席番号j+1番目の順位
    ls2[a - 1] = j + 1
for k in range(n):
    print(ls2[k], end = " ")


Measured memory_bytes: 13880
N, M, P = map(int, input().split())
edge = []

for i in range(M):
    A, B, C = map(int, input().split())
    edge.append((A, B, P-C))

inf = float('inf')
cost = [inf] * (N+1)
cost[1] = 0
for i in range(N-1):
    for e in edge:
        a, b, c = e
        if cost[a] + c < cost[b]:
            cost[b] = cost[a] + c

for i in range(N):
    for e in edge:
        a, b, c = e
        if cost[a] + c < cost[b]:
            if b == N:
                print(-1)
                exit()
            else:
                cost[b] = cost[a] + c
        
print(max(-cost[N], 0))





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




int main()
{
   
  

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ind = -1;
    ll count = 0;
    while(1)
    {
        auto temp = s.find("ABC",ind+1);
        ind = temp;
        //cout<<ind<<endl;
        if(ind!=string::npos)
            count++;
        else
            break;
        
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main (){
    int N,Y;
    cin>>N>>Y;
    int y=Y/1000;
    int p=-1;
    int q=-1;
    int r=-1;
    rep(i,N+1){
        rep(j,N-i+1){
            int keynum=9*i+4*j;
            if(keynum==y-N){
                p=i;
                q=j;
                r=N-i-j;
            }
            else continue;

        }
    }
cout<<p<<" "<<q<<" "<<r<<endl;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a>0&&b>0)
        cout<<"Positive"<<endl;
    else if(max(a,b)>=0&&min(a,b)<=0||a==0||b==0)
            cout<<"Zero"<<endl;
        else
            if((abs(min(a,b))-abs(max(a,b)))%2==0)
                cout<<"Negative"<<endl;
            else
                cout<<"Positive"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl

bool odd(int x) {
    int keta=0;
    while (x) {
        keta++;
        x /= 10;
    }
    return keta % 2 == 1;
}

int main() {
    int n, ans;
    cin >> n;
    rep(i,n) {
        if(odd(i+1)) ans++;
    }
    ct(ans);
}

Measured memory_bytes: 256
s=input('')
l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
ok=0
for a in l:
    if a==s:
        ok=1
        break

if ok==0:
    print('A')
else:
    print('a')

Measured memory_bytes: 9128
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>

#define for0(i, n)    for (int i = 0  ; i <  (n); ++i)
#define for1n(i, n)   for (int i = 1  ; i <= (n); ++i)
#define for1(i, n)    for (int i = 1  ; i <  (n); ++i)
#define forn(i, n)    for (int i = 0  ; i <= (n); ++i)
#define forx(i, n, x) for (int i = (x); i <  (n); ++i)
#define forl(i, n, x, a) for (int i = (x), a = 0; a < (n);  \
                              i = (i + 1) % (n), ++a)

using namespace std;

typedef long long ll;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll> ,greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;

template<typename T>
struct point{
    T x, y;
    point(T a = 0, T b = 0) : x(a), y(b){}
    
    point operator+(point p) const { return {p.x + x, p.y + y}; }
    point operator-(point p) const { return {p.x - x, p.y - y}; }
    T operator*(point p) const { return p.x * x + p.y * y; }
    
    point operator+=(point p) {x += p.x; y += p.y; return *this; }
    point operator-=(point p) {x -= p.x; y -= p.y; return *this; }

    T length() const { return std::sqrt(x * x + y * y); }
    
    operator T() const { return length(); }

    T angle() const { return std::atan2(y, x); }
    
    static bool angleLesser(point<T> const& p, point<T> const& q) {
        return p.angle() < q.angle();
    }
    
    static bool lengthLesser(point<T> const& p, point<T> const& q) {
        return p.length() < q.length();
    }
};


int main(void){

    int N;
    
    cin >> N;

    point<long double> v[100];
    
    for0(i, N){
        cin >> v[i].x >> v[i].y;
    }

    sort(v, v + N, point<long double>::angleLesser);

    long double result = 0;
    
    for0(i, N){
        point<long double> p = {0, 0};
        forl(j, N, i, a){            
            p += v[j];
            result = max(result, p.length());
        }
    }

    printf("%.20Lf", result);
    
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int T = sc.nextInt();
        int[] a = new int[T];
        for (int i = 0; i < a.length; ++i) {
            a[i] = sc.nextInt();
        }

        int[] r = new int[K];
        int sameCount = 0;
        for (int i = 0; i < K; ++i) {
            int maxIdx = maxIdx(a);
            int nextMaxIdx = nextMaxIdx(a);
            if (i > 0 && r[i - 1] == maxIdx) {
                if (nextMaxIdx >= 0 && a[nextMaxIdx] > 0) {
                    a[nextMaxIdx]--;
                    r[i] = nextMaxIdx;
                    if (maxIdx == nextMaxIdx) {
                        sameCount++;
                    }
                } else {
                    a[maxIdx]--;
                    r[i] = maxIdx;
                    sameCount++;
                }
            } else {
                a[maxIdx]--;
                r[i] = maxIdx;
            }
        }
        System.out.println(sameCount);
    }
    private static int maxIdx(int[] a) {
        int max = -1;
        int maxIdx = -1;
        for (int i = 0; i < a.length; ++i) {
            if (a[i] > max) {
                max = a[i];
                maxIdx = i;
            }
        }
        return maxIdx;
    }
    private static int nextMaxIdx(int[] a) {
        int maxIdx = maxIdx(a);
        int nextMax = -1;
        int nextMaxIdx = -1;
        int zeroIdx = -1;
        for (int i = 0; i < a.length; ++i) {
            if (a[i] > 0 && i != maxIdx && a[i] > nextMax) {
                nextMax = a[i];
                nextMaxIdx = i;
            }
            if (a[i] == 0) {
                zeroIdx = i;
            }
        }
        if (nextMaxIdx == -1) {
            return zeroIdx;
        } else {
            return nextMaxIdx;
        }
    }
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

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

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

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

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

vvll to(200005);
vll ans;

void dfs(ll car,ll pre=-1){
	for(ll next:to[car]){
		if(next==pre) continue;
		ans[next]+=ans[car];
		dfs(next,car);
	}
}

int main()
{
	ll n,q,a,b,p,x;
	cin >> n >> q;
	rep(i,n-1){
		cin >> a >> b;
		--a;
		--b;
		to[a].pb(b);
		to[b].pb(a);
	}
	ans.resize(n);
	rep(i,q){
		cin >> p >> x;
		ans[--p]+=x;
	}
	dfs(0);
	rep(i,n) cout << ans[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 24320
from math import factorial

def cmb(n,k):
    if n < k or n < 0 or k < 0:
        return 0
    return factorial(n)//(factorial(k)*factorial(n-k))

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

for i in range(1, K+1):
    ans = cmb(K-1, i-1) * cmb(N-K+1, i)
    print(ans%(10**9+7))


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

int main() {
  int a[4];
  for (int i=0; i<4; i++) {
	cin >> a[i];
  }
  sort(a, a+4);
  if (a[0]==1 && a[1]==4 && a[2]==7 && a[3]==9) {
	cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <cassert>
 
typedef long long ll;
using namespace std;
 
#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL
 
#define SIZE 1000000
 
string S;
int n;
 
bool check(int x){
    bool used[SIZE] = {0};
    int s = n-1;
    int cc = 0;
    
    vector<int> O;
    
    for(int i=n-1;i>=0;i--){
        if(S[i]=='I'){
            used[i] = true;
            s = min(s-1,i-1);
            
            while(1){
                if(S[s]=='O'){
                    used[s] = true;
                    cc++;
                    O.push_back(s);
                    break;
                }
                
                if(s==0){
                    return false;
                }
                
                s--;
            }
        }
        
        if(cc==x) break;
    }
    
    if(cc!=x) return false;
    
    assert(x==(int)O.size());
    
    s = n-1;
    
    for(int i=0;i<x;i++){
        
        s = min(s,O[i]-1);
        
        while(1){
            if(s==-1) return false;
            
            if((S[s]=='J' || S[s]=='I') && used[s]==false){
                used[s] = true;
                break;
            }
            
            if(s<=0) return false;
            
            s--;
        }
        
    }
    
    return true;
}
 
int main(){
    cin >> n >> S;
    
    int l=0,r=n/3,mid;
    
    while(l<r){
        mid = (l+r+1)/2;
        
        if(check(mid)){
            l = mid;
        }else{
            r = mid-1;
        }
    }
    
    printf("%d\n",l);
    
    return 0;
}

Measured memory_bytes: 8256
#include <iostream>
#define MAX 301

using namespace std;

int rmn_min( int x, int y ){
  return ( x < y ? x : y );
}

int main(){
  int k = 0;
  int u = 0;
  int p = 0;
  int c = 0;
  char line[ MAX ];
  cin >> line;
  for( int i = 0; line[ i ] != 0; i++ ){
    switch( line[ i ] ){
      case 'K': k++; break;
      case 'U': u++; break;
      case 'P': p++; break;
      case 'C': c++; break;
    }
  }
  cout << rmn_min( rmn_min( rmn_min( k, u ), p ), c ) << endl;
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define p_b push_back
#define MOD 1
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ;

    char arr[4];
    scanf("%s",arr);
    sort(arr,arr+4);
    if(arr[0]==arr[1] && arr[2] == arr[3])
    {

        if(arr[0] != arr[2])
        {

            cout<< "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;




    return 0;
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
Vlist = np.array(list(map(int,input().split())))
Clist = np.array(list(map(int,input().split())))

Dlist = Vlist-Clist

sum_ = 0
for d in Dlist:
    if d >= 0:
        sum_ += d

print(sum_)


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

void ch(int &x, int &y){
    if(y < x){
        int tmp = y;
        y = x;
        x = tmp;
    }
}

int N, M, T;
vector<int>x, y;

void solve1(){
    using bs = bitset<50001>;
    vector<bs>dp(N+1); // dp[i][j] は i から j にゴールできるかどうか
    for (int i = 1; i <= N; ++i) {
        dp[i][i] = 1;
    }
    for (int i = M - 1; i >= 0; --i) {
        dp[x[i]] |= dp[y[i]];
        dp[y[i]] = dp[x[i]];
    }

    bs flag1; flag1.set();
    for (int i = 1; i <= N; ++i) {
        flag1 &= dp[i];
    }

    for (int j = 1; j <= N; ++j) {
        if (flag1[j]) {
            string s(M, '^');
            bs flag;
            flag[j] = 1;
            for (int i = M - 1; i >= 0; --i) {
                if (flag[y[i]] == 1) s[i] = 'v';
                flag[x[i]] = flag[x[i]] || flag[y[i]];
                flag[y[i]] = flag[x[i]];
            }
            assert(flag.count() == N);
            cout << s << "\n";
            return;
        }
    }
    cout << -1 << "\n";
}

void solve2(){
    if(N == 2){
        cout << -1 << "\n";
        return;
    }
    vector<vector<int>>graph(N+1, vector<int>());
    for (int i = 0; i < M; ++i) {
        graph[x[i]].push_back(i);
        graph[y[i]].push_back(i);
    }

    int x1 = x[0];
    int y1 = y[0] + 1;
    if(y1 == N + 1) {
        if(x1 == 1) y1 = 2;
        else y1 = 1;
    }
    ch(x1, y1);

    // 次で衝突する場合は進路転換
    for (int i = 0; i < M; ++i) {
        auto iter1 = upper_bound(graph[x1].begin(), graph[x1].end(), i);
        auto iter2 = upper_bound(graph[y1].begin(), graph[y1].end(), i);
        if(iter1 != graph[x1].end() && iter2 != graph[y1].end() && (*iter1 == *iter2)){
            if(x[i] == x1){
                cout << "v";
                x1 = y[i];
            } else if(y[i] == y1){
                cout << "^";
                y1 = x[i];
            } else if(y[i] == x1){
                cout << "^";
                x1 = x[i];
            } else if(x[i] == y1){
                cout << "v";
                y1 = y[i];
            }
        } else {
            if (y[i] == y1 || y[i] == x1) {
                cout << "v";
            } else {
                cout << "^";
            }
        }
        ch(x1, y1);
    }
}

int main() {
    cin >> N >> M >> T;
    x.resize(M); y.resize(M);
    for (int i = 0; i < M; ++i) {
        cin >> x[i] >> y[i];
    }
    if (T == 1) solve1();
    else solve2();
    return 0;
}

Measured memory_bytes: 306688
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define COUTDOUBLE(v) cout << std::setprecision(10)<<(v)<<endl;
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define f first
#define s second

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};




int main(){
    SCIN(str);
    cout<<str.front()<<str.size()-2<<str.back()<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;
ll p[20],k[20],s[20][20];
int main(){
    ll n,m,tmp=0,ans=0;
    cin>>n>>m;
    bool q=false;
    rep(i,0,m){
        cin>>k[i];
        rep(j,0,k[i]){cin>>s[i][j];s[i][j]--;}
    }
    rep(i,0,m)cin>>p[i];

    for(int mask = 0; mask < (1 << n); mask++){
        tmp=0;
        q=false;
        rep(i,0,m){
            tmp=0;
            rep(j,0,k[i])if(mask&(1<<s[i][j]))tmp++;
            if(tmp%2!=p[i]){q=true;break;}
            else{tmp=0;continue;}
        }
        if(!q)ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
from collections import deque

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H,W=MAP()

que = deque()
# 右左上下  
directions = [(0,1),(0,-1),(1,0),(-1,0)]
# 四方に一回り大きいグリッドを作る
grid = list2d(H+2, W+2, '*')
for i in range(1,H+1):
    row = list(input())
    for j in range(1, W+1):
        grid[i][j] = row[j-1]
        if grid[i][j] == '#':
            que.append((i, j, 0))

# 移動距離メモ
memo=[[-1]*(W+2) for i in range(H+2)]
while len(que):
    h1,w1,cost=que.popleft()
    if memo[h1][w1]!=-1:
        continue
    memo[h1][w1]=cost
    # 4方向見る
    for direction in directions:
        h2=h1+direction[0]
        w2=w1+direction[1]
        # 壁と黒はスキップ
        if grid[h2][w2]=='*' or grid[h2][w2]=='#':
            continue
        # 白を埋める
        if grid[h2][w2]=='.':
            grid[h2][w2]='#'
            que.append((h2, w2, cost+1))
ans=0
for i in range(1, H+1):
        ans=max(ans, max(memo[i]))
print(ans)


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

using namespace std;

int main()
{
    string s;

    string x, y;

    int a, b;

    cin >> s;

    x = s[0];

    x += s[1];

    y = s[2];

    y += s[3];

    bool amonth =false, bmonth= false;

    a = stoi(x);

    b = stoi(y);

    if(a>=1 && a<=12)
    {
        amonth = true;
    }

    if(b>=1 && b<=12)
    {
        bmonth = true;
    }

    if(amonth==false && bmonth==true)
    {
        cout << "YYMM" << endl;
    }
    if(amonth==true && bmonth==false)
    {
        cout << "MMYY" << endl;

    }
    if(amonth==true && bmonth==true)
    {
        cout << "AMBIGUOUS" << endl;
    }

    if(amonth==false && bmonth==false)
    {
        cout << "NA" << endl;

    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
int q,a,b;
char str[1000],p[1000],mei[10],RL[]="replace",RV[]="reverse",PR[]="print",cp;
scanf("%s",str);
scanf("%d",&q);
for(int aa=0;aa<q;aa++){
scanf("%s",mei);
if(strcmp(mei,RL)==0){
scanf("%d %d %s",&a,&b,p);
for(int d=a,c=0;d<=b;d++,c++)str[d]=p[c];
}
if(strcmp(mei,RV)==0){
scanf("%d %d",&a,&b);
for(int d=0,c=0;d<(b-a+1)/2;d++,c++){
cp=str[a+c];
str[a+c]=str[b-c];
str[b-c]=cp;
}
}
if(strcmp(mei,PR)==0){
scanf("%d %d",&a,&b);
for(int d=a;d<=b;d++)printf("%c",str[d]);
printf("\n");
}
}
return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<deque>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE],*_is=_buf,*_it=_buf;
inline char rdc(){
	if (_is==_it) _it=(_is=_buf)+fread(_buf,1,BUF_SIZE,stdin);
	return *_is++;
}
inline void rdi(int &x){
	int f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	if(f) x=-x;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(int x){
	write(x);
	putchar(' ');
}
inline void print(int x){
	write(x);
	putchar('\n');
}
int n;
struct B{
	int w,s,v;
	inline bool operator <(const B t)const{return w+s<t.w+t.s;}
}b[1111];
ll v[22222];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	int i,j;
	for(i=0;i<n;++i) cin>>b[i].w>>b[i].s>>b[i].v;
	sort(b,b+n);
	for(i=0;i<n;++i) for(j=b[i].s;~j;--j) if(v[j+b[i].w]<v[j]+b[i].v) v[j+b[i].w]=v[j]+b[i].v;
	ll a=0;
	for(i=0;i<22222;++i) a=max(a,v[i]);
	cout<<a<<endl;
	return 0;
}

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

def main():
    n = int(input())
    
    A = [0]*n
    B = [0]*n
    C = [0]*n
    
    a,b,c = map(int,input().split())
    A[0] = a
    B[0] = b
    C[0] = c
    
    for i in range(1,n):
        a,b,c = map(int,input().split())
        A[i] = max(B[i-1]+a, C[i-1]+a)
        B[i] = max(A[i-1]+b, C[i-1]+b)
        C[i] = max(A[i-1]+c, B[i-1]+c)
    
    print(max(A[n-1], B[n-1], C[n-1]))
    
if __name__ == '__main__':
    main()

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

// a^n mod m を計算する(二分累乗法:O(logn))
ll modpow(ll a, ll n, ll m) {
	ll x = 1;
	while(n > 0){
		if(n & 1) x = x * a % m;
		a = a * a % m;
		n >>= 1;
	}
	return x;
}

// nCr mod m
ll nCr(ll n, ll r, ll m){
	ll a = 1, b = 1;
	for(ll i=1; i<=r; ++i){
		a *= n - i + 1;
		b *= i;
		a %=m;
		b %=m;
	}
	return a * modpow(b, m-2, m) % m;
}

int main(){
	ll MOD = 1000000007, N,A,B;
	cin>>N>>A>>B;
	ll ans = modpow(2, N, MOD) - 1;
	ans -= nCr(N, A, MOD);
	ans -= nCr(N, B, MOD);
	ans %= MOD;
	if(ans < 0L) ans += MOD;
	cout<< ans <<endl;
}

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

ll dp[100005];
int main(){

ll n , w ; 
cin >> n >> w;
ll W[n+1] ; ll v[n+1]; 
for(ll i=1 ; i<=n ;i++){
     cin >> W[i] ; cin >> v[i] ;
}

 for(ll i=0 ; i<=100001 ;i++){
 dp[i] = -1;

 }
 dp[0]= 0; ll  ans =0;
 for(ll i=1 ; i<=n ;i++){
for(ll j=100001; j>=0 ; j--){ 

  if(j - v[i] >=0){  if(dp[j-v[i]] >=0){ if(dp[j]==-1){ dp[j]= W[i] + dp[j-v[i]];}else{dp[j] = min(dp[j] , dp[j-v[i]] + W[i]);}}}
 if(dp[j]<=w && dp[j]>=0){ ans = max(ans, j);}
}
   
 }

 cout << ans << endl;

}

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

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

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define vvii vector<vii>
#define pb push_back
#define endl "\n"
#define f first
#define s second

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll s, w;
    cin >> s >> w;
    if (w >= s)
        cout << "unsafe\n";
    else
        cout << "safe\n";
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();

		if (b - a <= 0) {
			System.out.println("delicious");
		} else {
			if (x - (b - a) >= 0) {
				System.out.println("safe");
			} else {
				System.out.println("dangerous");
			}
		}

	}

}

Measured memory_bytes: 21972
n = int(input())
h_li = list(map(int, input().split()))
count = 0
for i in range(100):
    f = 0
    for j in range(n):
        if h_li[j] >= i + 1:
            if f == 0:
                count += 1
                f = 1
        else:
            f = 0
print(count)


Measured memory_bytes: 2940
from heapq import heapify,heappop,heappush
N=int(input())
a=list(map(int,input().split()))
ans=-10**18
a_neg=[-x for x in a]
af=a[:N]
ae=a_neg[2*N:]
f_sum=[sum(af)]
e_sum=[sum(ae)]

heapify(af)
for aa in a[N:2*N]:
  heappush(af,aa)
  t=heappop(af)
  f_sum.append(f_sum[-1]+aa-t)

heapify(ae)
for aa in reversed(a[N:2*N]):
  heappush(ae,-aa)
  t=heappop(ae)
  e_sum.append(e_sum[-1]-aa-t)

for f,e in zip(f_sum,reversed(e_sum)):
  ans=max(ans,f+e)

print(ans)

Measured memory_bytes: 45480
#include <bits/stdc++.h>
#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(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N; cin >> N;
	V<int> A(N),B(N);
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> B[i];
	int inf = 1e9;
	VV<int> dp(1<<N,V<int>(N,inf));
	rep(i,N){
		dp[1<<i][i] = i;
	}
	rep(s,1<<N) rep(i,N) if(dp[s][i] != inf){
		int index_i = __builtin_popcount(s) - 1;
		int index_j = index_i + 1;
		rep(j,N) if(!((s>>j)&1) && ((i-index_i)%2==0 ? A[i] : B[i]) <= ((j-index_j)%2==0 ? A[j] : B[j])){
			int cost = __builtin_popcount((~s)&((1<<j)-1));
			chmin(dp[s|(1<<j)][j],dp[s][i]+cost);
		}
	}
	int ans = inf;
	rep(i,N) chmin(ans,dp[(1<<N)-1][i]);
	if(ans == inf) cout << -1 << endl;
	else cout << ans << endl;
}


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

using namespace std;

#define int long long

constexpr int INF = 1LL << 60;
constexpr int MOD = 998244353;
constexpr double EPS = 1.0e-11;

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

constexpr int MAX_N = 100005;

int n;
pii d[MAX_N];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(16);
    cout << fixed;

    cin >> n;
    int d1;
    cin >> d1;
    if (d1)
    {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 2; i <= n; i++)
    {
        int tmp;
        cin >> tmp;
        d[i] = {tmp, i};
    }
    sort(d + 2, d + n + 1);

    if (d[2].first != 1)
    {
        cout << 0 << endl;
        return 0;
    }

    int depth = d[2].first, preCount = 1, count = 0, ans = 1;
    for (int i = 2; i <= n; i++)
    {
        if (depth != d[i].first)
        {
            if (depth + 1 != d[i].first)
            {
                cout << 0 << endl;
                return 0;
            }
            depth = d[i].first;
            preCount = count;
            count = 0;
        }

        ans *= preCount;
        ans %= MOD;
        count++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  ll max = 0;
  ll num = 0;
  rep(i, n){
    ll a, b;
    cin >> a >> b;
    if(a>max){
      max = a;
      num = b;
    }
  }
  print(max + num);
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define F first
#define S second
const int N = 2e5+87;
vector<int> g[N];
int d;
int dfs(int u,int p)
{
    int k = 0;
    for (int v : g[u]) if (v != p) {
        int w = dfs(v,u);
        d = max(k + w + 1, d);
        k = max(k, w);
    }
    k += 1;
    d = max(d, k);
    return k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n-1; ++i) {
        int a,b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1,1);
    cout << (d%3==2?"Second\n":"First\n");
}


Measured memory_bytes: 20224
N,K=map(int,input().split())
A=list(map(int,input().split()))
mini=100000000000000
for i in range(N-K+1):
    if A[i]<0 and A[i+K-1]>=0:
        if abs(A[i])>abs(A[i+K-1]):
            if mini>abs(A[i+K-1])*2+abs(A[i]):
                mini=abs(A[i+K-1])*2+abs(A[i])
        else:
            if mini > abs(A[i]) * 2 + abs(A[i+K-1]):
                mini = abs(A[i]) * 2 + abs(A[i+K-1])
    else:
       if mini>max(abs(A[i]),abs(A[i+K-1])):
           mini=max(abs(A[i]),abs(A[i+K-1]))
print(mini)


Measured memory_bytes: 14532
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < n; i++)
using namespace std;


int main(){
  int h,w;
  cin >> h >> w;
  string s[h];
  REP(i,h){
    cin >> s[i];
  }
  int cnt[h][w] = {};
  REP(i,h){
    REP(j,w){
      if(s[i][j]=='#'){
        if(i!=0&&j!=0) cnt[i-1][j-1]++;
        if(i!=0) cnt[i-1][j]++;
        if(i!=0&&j!=w-1) cnt[i-1][j+1]++;
        if(j!=0) cnt[i][j-1]++;
        if(j!=w-1) cnt[i][j+1]++;
        if(i!=h-1&&j!=0) cnt[i+1][j-1]++;
        if(i!=h-1) cnt[i+1][j]++;
        if(i!=h-1&&j!=w-1) cnt[i+1][j+1]++;
      }
    }
  }
  REP(i,h){
    REP(j,w){
      if(s[i][j]=='#'){
        cout << '#';
      }else{
        cout << cnt[i][j];
      }
    }
    cout << endl;
  }
  return 0;
}


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

#define PY "YES\n"    // printf(PY);
#define PN "NO\n"     // printf(PN);

int main()
{
    int n, count=0, i;
    scanf("%d", &n);
    int arr[n+5];

    for(i=1; i<=n; i++)
        scanf("%d", &arr[i]);


    for(i=2; i<n; i++)
    {
        if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
            count++;
        else if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
            count++;
    }

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

    return 0;
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

int N;
int A[214514];

int solve(int f){
    int sum=0;
   REP(i,N){
       sum+=abs(A[i]-f);
   }
   return sum;
}

signed main(void){
   cin >> N;
   REP(i,N){
       cin >> A[i];
       A[i]-=(i+1);
   }
   sort(A,A+N);
   
   int ok=A[N-1],ng=A[0]-1,mid1,mid2;
    mid1=(ng+ng+ok)/3;
    mid2=(ng+ok+ok)/3;
   while(abs(ok-ng)>2){
       mid1=(ng+ng+ok)/3;
       mid2=(ng+ok+ok)/3;
       
       if(solve(mid1)<solve(mid2)){
           ok=mid2;
       }else{
           ng=mid1;
       } 
   }
   //cout << solve(ng) << " " <<solve(mid1) << " " <<solve(mid2) << " " <<solve(ok) << endl;
   cout << min(min(solve(ok),solve(ng)),min(solve(mid1),solve(mid2))) << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void) {
	char s[15], t[15], u[15];
	int a, b;
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if (s[0] == u[0]) {
		if (s[1] == u[1]) {
			a = a - 1;
		}
	}
	else if (t[0] == u[0]) {
		if (t[1] == u[1]) {
			b = b - 1;
		}
	}
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n, k;
	cin >> n >> k;
	int a[n]; map<int, int>mt;
	vii v;
	zip(i, 0, n)
	{
		cin >> a[i];
		mt[a[i]]++;

	}
	for (auto itr = mt.begin(); itr != mt.end(); itr++)
	{
		v.pb({itr->ss, itr->ff});
	}
	int ans = 0;
	sort(all(v));
	if (v.size() <= k)
	{
		cout << 0 << en;
		return 0;
	}
	zip(i, 0, v.size() - k)
	{
		//if (i >=0&&i<v.size()-k)
		ans += v[i].ff;
	}
	cout << ans << en;



	return 0;
}



Measured memory_bytes: 18928
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

d = {'r': p, 's': r, 'p': s} #勝ちスコア

point = 0
for i in range(k): #kまでは普通に勝ってもよい
    point += d[t[i]]

for i in range(k, n): #kからnまでは、k個前と同じなら、後の方を無得点化する
    if t[i] == t[i - k]:
        t[i] = 'x'
        continue
    point += d[t[i]]

print(point)


Measured memory_bytes: 49392
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

const int MOD = 1e9+7;

ll dfs(int K,int p,int v,vector<vector<int> >&G){
    int colors;
    if(p==-1)colors=K-1;
    else colors=K-2;

    if(G[v].size()>=K)return 0;
    else{
        ll tmp = 1;
        for(auto &&x:G[v]){//子への色の塗分け方
            if(x==p)continue;
            tmp*=colors;
            colors--;
            tmp%=MOD;
        }
        for(auto &&x:G[v]){//子以下の色の塗分け方
            if(x==p)continue;
            tmp*=dfs(K,v,x,G);
            tmp%=MOD;
        }
        return tmp;
    }
}

int main(){
    int N,K;
    cin >> N >> K;
    vector<vector<int> > G(N);
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cout << K*dfs(K,-1,0,G)%MOD << endl;
    return 0;
}

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


int main() {
  string odd, even ;
  cin >> odd ;
  cin >> even ;

  int n = max( odd.size(), even.size() ) ;
  rep( i, n ) {
    if ( i < n-1 ) {
      cout << odd[i] << even[i] ;
      continue ;
    }
    //n-1
    if ( odd.size() == even.size() ) cout << odd[i] << even[i] << endl ;
    else                             cout << odd[i] << endl ;
  }
 
  return 0 ;
}



Measured memory_bytes: 256