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


int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  vector<vector<int>> nums;
  for (int i = 0; i < N; i++) {
      int a, b;
      cin >> a >> b;
      nums.push_back({a, b});
  }
  sort(nums.begin(), nums.end());
  ll consumed = 0;
  for (int i = 0; i < nums.size(); i++) {
      consumed += nums[i][1];
      if (consumed >= K) {
	  cout << nums[i][0] << endl;
	  return 0;
      }
  }
}


Measured memory_bytes: 6324
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int i, j;
    int n, m;
    int s, c;

    cin >> n >> m;

    vector<int> ans(n);

    for (i = 0; i < n; i++) {
        ans[i] = -1;
    }

    for (i = 0; i < m; i++) {
        cin >> s >> c;
        if (ans[s-1] != -1 && ans[s-1] != c) {
            cout << -1 << endl;
            return 0;
        } else {
            ans[s-1] = c;
        }
    }

    if (ans[0] == 0) {
        if (n == 1) {
            cout << 0 << endl;
            return 0;
        } else {
            cout << -1 << endl;
            return 0;
        }
    }

    if (n == 1 && m == 0) {
        cout << 0 << endl;
        return 0;
    }

    for (i = 0; i < n; i++) {
        if (ans[i] == -1) {
            if (i == 0) ans[i] = 1;
            else ans[i] = 0;
        }
        cout << ans[i];
    }

    cout << endl;

    return 0;
}


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

// ABCテンプレート

#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  int N, ac=0, wa=0, tle=0, re=0;
  cin >> N;
  rep(i,N) {
    string s;
    cin >> s;
    if (s=="AC") ac++;
    else if (s=="WA") wa++;
    else if (s=="TLE") tle++;
    else re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 3628
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	for i in 0..v.len() {
	    if(v[i] == 0) {
	        println!("{}", i+1);
	    }
	}
}

Measured memory_bytes: 2100
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for i in range(N):
  ans += B[A[i]-1]
for j in range(N-1):
  if A[j] + 1 == A[j+1]:
    ans += C[A[j]-1]
print(ans)

Measured memory_bytes: 3064
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        if (s.Length % 2 != 0) return "No";

        for(int i=0; i<s.Length; i++) {
            var c = s[i];
            
            if(i % 2 == 0) {
                if (c != 'h') return "No";
            } else {
                if (c != 'i') return "No";
            }
        }

        return "Yes";
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll pow3[33];
ll work(ll a,ll b,ll c,ll d,int k)
{
    if(k==0)
    {
        return abs(a-c) + abs(b-d);
    }
    ll sx = a / pow3[k-1];
    ll sy = b / pow3[k-1];
    ll tx = c / pow3[k-1];
    ll ty = d / pow3[k-1];
    if(sx != tx && sy != ty)
    {
        return abs(a-c)+abs(b-d);
    }
    if(sx==tx && sy==ty)
    {
        return work(a%pow3[k-1],b%pow3[k-1],c%pow3[k-1],d%pow3[k-1],k-1);
    }
    if(sx == tx && sx % 3 == 1 && abs(sy-ty)>1 )
    {
        return abs(b-d) + min((a/pow3[k-1]+1)*pow3[k-1]-a + (c/pow3[k-1]+1)*pow3[k-1]-c, 
            a+1-a/pow3[k-1]*pow3[k-1] + c+1-c/pow3[k-1]*pow3[k-1]);
    }
    if(sy == ty && sy % 3 == 1 && abs(sx-tx)>1)
    {
        return abs(a-c) + min((b/pow3[k-1]+1)*pow3[k-1]-b + (d/pow3[k-1]+1)*pow3[k-1]-d, 
            b+1-b/pow3[k-1]*pow3[k-1] + d+1-d/pow3[k-1]*pow3[k-1]);
    }
    return work(a,b,c,d,k-1);
}
void solve(long long Q, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c, std::vector<long long> d){
    for(int i=0;i<Q;++i)
    {
        cout<<work(a[i]-1,b[i]-1,c[i]-1,d[i]-1,30)<<endl;
    }
}

int main(){
    pow3[0]=1;
    for(int i=1;i<=30;++i)pow3[i]=pow3[i-1]*3;
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> a(Q);
    std::vector<long long> b(Q);
    std::vector<long long> c(Q);
    std::vector<long long> d(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        scanf("%lld",&c[i]);
        scanf("%lld",&d[i]);
    }
    solve(Q, std::move(a), std::move(b), std::move(c), std::move(d));
    return 0;
}


Measured memory_bytes: 640
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T>
void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C>
void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C>
constexpr void reverse(C& c) { reverse(ALL(c)); }
template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion


int main()
{
    int n;
    stack<int> st;
    while(cin>>n) {
        if(n==0){
            P(st.top());
            st.pop();
        }
        else st.push(n);
    }
    return 0;
}

Measured memory_bytes: 3076
#include<stdio.h>
int main(void){

    int a[100]={0},i,n,x,work=0,j;
    while(scanf("%d",&n)!=EOF){
        a[n-1]++;
        if(n>work)work=n;
    }
    x=work;
    work=0;
    for(i=x-1;i>=0;i--){
        if(a[i]>work){
            work=a[i];
            for(j=x-1;j>=0;j--){
                if(a[j]<work)a[j]=0;
            }
        }
    }
    for(i=0;i<x;i++){
        if(a[i]!=0){
            printf("%d\n",i+1);
        }
    }

    return 0;
}

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

using namespace std;


bool reversecompare(int a, int b)
{
    return a > b;
}

int lena, lenb;
int asa [105];
int asb [105];
string newa, newb, a, b;

int main ()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> a >> b;
    lena = a.length();
    lenb = b.length();
    for(int i = 0; i < lena; i++)
        asa[i] = int(a[i]);
    for(int i = 0; i < lenb; i++)
        asb[i] = int(b[i]);
    stable_sort(asa, asa+lena);
    stable_sort(asb, asb+lenb, reversecompare);
    newa = "";
    newb = "";
    for(int i = 0; i < lena; i++)
        newa += char(asa[i]);
    for(int i = 0; i < lenb; i++)
        newb += char(asb[i]);
    if(newa.compare(newb) < 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

using namespace std;
#define intMax 2147483647
#define rep(i, a, b) for (long long i = a; i < b; i++)
#define repp(i, a, b) for (long long i = a; i >= b; i--)
#define be(a) (a.begin(), a.end())
#define rbe(p) (p.rbegin(), p.rend())
#define pb push_back

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<int> A(n + 1), B(n + 1), C(n + 1);
    vector<vector<int>> dp(n + 1, vector<int>(4, 0));
    rep(i, 1, n + 1)
    {
        cin >> A[i] >> B[i] >> C[i];
    }
    rep(i, 1, n + 1)
    {
        dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + A[i];

        dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + B[i];

        dp[i][3] = max(dp[i - 1][2], dp[i - 1][1]) + C[i];
    }
    cout << max({dp[n][1], dp[n][2], dp[n][3]});
}

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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
  ll n;
  cin >> n;
  vector<P> a(n);
  REP(i,n){
    a.at(i).first = input();
    a.at(i).second = i+1;
  }
  sort(all(a));
  REP(i,n)cout << a.at(i).second << (i+1==n?"":" ");
  cout << endl;
}

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

int main(){
    int H,W,a,N=0;
    cin >> H >> W;
    vector<vector<int>> v(H,vector<int> (W,0));
    vector<int> vr(1,0);

    for (int i=0;i<H;++i){
        for (int j=0;j<W;j++) {
            cin >> a;
            if ((a+2)%2==1) v[i][j] = 1;
            
            }
    }

    for (int i=0;i<H;++i){
        for (int j=0;j<W;j++) {
            if (v[i][j]==1) {
                if (j!=W-1) {
                    v[i][j+1] = (v[i][j+1]+1)%2;
                    vr.push_back(i);
                    vr.push_back(j);
                    vr.push_back(i);
                    vr.push_back(j+1);
                    }
                else if (i!=H-1) {
                    v[i+1][j] = (v[i+1][j]+1)%2;
                    vr.push_back(i);
                    vr.push_back(j);
                    vr.push_back(i+1);
                    vr.push_back(j);
                    }
            }
        }
    }
    cout << vr.size()/4 << endl;
    for (int k=1;k<vr.size();k+=4){
        cout << vr[k]+1 << " " << vr[k+1]+1 << " " << vr[k+2]+1 << " "
        << vr[k+3]+1 << endl;
    }
}
    //sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
  int main() {
    char c;
    cin>>c;
    if(c=='a'|c=='i'|c=='u'|c=='e'|c=='o'){
      cout<<"vowel"<<endl;
    }else{
      cout<<"consonant"<<endl;
    }
  }


Measured memory_bytes: 256
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

wT = []
p = {"p":P, "s":S, "r":R}
ans = 0

for t in range(N):
    for i, j in zip(["r", "s", "p"], ["p", "r", "s"]):
        if T[t] == i:
            wT.append(j)
            break
    if t - K >= 0:
        if wT[t - K] == wT[-1]:
            wT[-1] = "x"
            continue
        else:
            ans += p[wT[-1]]
    else:
        ans += p[wT[-1]]
print(ans)

Measured memory_bytes: 4792
n = int(input())
A = list(map(int,input().split()))
x = 0
for i in range(n//2):
    x = A[i]
    A[i] = A[n-i-1]
    A[n-i-1] = x
for i in range(n-1):
    print(A[i],end=" ")
print(A[n-1])


Measured memory_bytes: 5600
n,y=map(int,input().split())
 
def check(n,y):
    for i1 in range(n+1):
        if i1*10000>y:
            print(-1,-1,-1)
            return False
        
        for i2 in range(n+1-i1):
            if i1*10000+i2*5000+(n-i1-i2)*1000==y:
                    print(i1,i2,n-i1-i2)
                    return True
 
 
    print(-1,-1,-1)
    return False
 
check(n,y)

Measured memory_bytes: 3064
s = list(input())
n = len(s)
lcount = 0
rcount = 1
memory = 0
ans = [0 for _ in range(n)]
for i in range(1,n):
    if s[i] == 'R':
        if s[i-1] == 'L':
            ans[memory] = (rcount + 1) // 2 + lcount // 2
            ans[memory + 1] = rcount // 2 + (lcount + 1) // 2
            rcount = 1
            lcount = 0
        else:
            rcount += 1
    if s[i] == 'L':
        if s[i-1] == 'R':
            memory = i-1
        lcount += 1
ans[memory] = (rcount + 1) // 2 + lcount // 2
ans[memory + 1] = rcount // 2 + (lcount + 1) // 2
print(" ".join(map(str,ans)))
        


Measured memory_bytes: 11176
def dfs(ka, kb, kc, cnta, cntb, cntc, phase):
    global ans
    if phase == n:
        if 0 < cnta and 0 < cntb and 0 < cntc:
            ans = min(ans, abs(a-ka) + abs(b-kb) + abs(c-kc) + 10*(cnta+cntb+cntc-3))
        return
    dfs(ka+l[phase], kb, kc, cnta+1, cntb, cntc, phase+1)
    dfs(ka, kb+l[phase], kc, cnta, cntb+1, cntc, phase+1)
    dfs(ka, kb, kc+l[phase], cnta, cntb, cntc+1, phase+1)
    dfs(ka, kb, kc, cnta, cntb, cntc, phase+1)


n,a,b,c = map(int, input().split())
l = [int(input()) for _ in range(n)]
ans = 10**9
dfs(0,0,0,0,0,0,0)
print(ans)

Measured memory_bytes: 9044
#include <stdio.h>

int _max(int a,int b) { return a>b?a:b;}

int main()
{
    int n;scanf("%d",&n);
    int ansa=0,ansb=0,ansc=0;
    while (n--)
    {
        int a,b,c;scanf("%d%d%d",&a,&b,&c);
        int tmpa,tmpb,tmpc;
        tmpa=_max(ansb,ansc);tmpb=_max(ansa,ansc);tmpc=_max(ansa,ansb);
        ansa=tmpa+a;ansb=tmpb+b;ansc=tmpc+c;
    }
    printf("%d\n",_max(_max(ansa,ansb),ansc ));

}


Measured memory_bytes: 128
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])

if c11[0] != c21[0]:
    print(n - c11[1] - c21[1])
else:
    print(n - max(c11[1]+c22[1], c12[1]+c21[1]))

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

using namespace std;
typedef long long ll;


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

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

    ll dp[n+1][W+1];

    for (int i = 0; i <= W; i++)
        dp[0][i] = 0;
    for (int i = 0; i <= n; i++)
        dp[i][0] = 0;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= W; j++) {
            dp[i][j] = dp[i-1][j];
            if (w[i-1]<=j)
                dp[i][j] = max(dp[i][j],v[i-1]+dp[i-1][j-w[i-1]]);
        }
    }

    cout << dp[n][W];


    return 0;
}


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

int main(){
    /*int A,B,C;

    cin >> A >> B >> C;

    if(A==B || A==C || B==C){
        if(A==B && A==C && B==C) cout << "No";
        else cout << "Yes";
    }
    else cout << "No";*/

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

    for(int i=0; i < n; i++){
        if(a[i]%2 == 0){
            if((a[i]%3 != 0) && (a[i]%5 != 0)){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;*/

    /*int n,r;
    cin >> n >> r;
    if(n>=10) cout << r << endl;
    else cout << r+(100*(10-n)) << endl;
    return 0;*/

    int n,k;
    cin >> n >> k;
    int count = 0;
    while(n!=0){
        n=n/k;
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

string s;
int B[200005];

int main()
{
	cin >> s;
	if (s[0] == 'B') B[0] = 1;
	for (int i = 1;i < s.size();i++) {
		B[i] = B[i - 1];
		if (s[i] == 'B') B[i]++;
	}

	ll ans = 0;
	for (int i = 0;i < s.size();i++) {
		if (s[i] == 'W') {
			ans += B[i];
		}
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) cout << 1 << endl;
    else if (a == b || b == c || a == c) cout << 2 << endl;
    else cout << 3 << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	if (N + M > 9)cout << "error\n";
	else cout << N + M << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, m; cin>>n>>m;
	ll k; cin>>k;
	ll sa[200020], sb[200020];
	sa[0]=0, sb[0]=0;
	for(int i=0; i<n; i++){
		ll a; cin>>a; sa[i+1]=sa[i]+a;
	}
	for(int i=0; i<m; i++){
		ll b; cin>>b; sb[i+1]=sb[i]+b;
	}
	int ans=0;
	for(int i=0; i<=n; i++){
		if(sa[i]>k) break;
		int t=upper_bound(sb, sb+m+1, k-sa[i])-sb-1;
		ans=max(ans, t+i);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6756
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define il inline
#define rg register
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define rep(i,st,ed) for(rg int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(rg int i=(ed);i>=(st);--i)
#define rep0(i,n) for(rg int i=0;i<(n);++i)
#define per0(i,n) for(rg int i=(n)-1;i>=0;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il void getmin(T &x,const T &y){if(y<x) x=y;}
template<typename T> il void getmax(T &x,const T &y){if(y>x) x=y;}
il void fileio(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e18+7;
const int N=2e5+7;

int a[N],pos[N],n;

int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i),pos[a[i]]=i;
	int cur=0,ans=0;
	rep(i,1,n){
		if(pos[i]>pos[i-1]) ++cur;
		else cur=1;
		getmax(ans,cur);
	}
	printf("%d\n",n-ans);
	return 0;
}


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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a,b, c, cnt = 0;
  cin >> a >> b >> c;
  	if (a == b && b == c){
		if (a % 2 == 1){
		cout << 0 << "\n";
		}else{
	cout << -1 << "\n";
		}
	}else{
	while (true){
	if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
		break;
	}else{
		int a2 = a, b2 = b, c2 = c;
		a = (b2 + c2)/2;
		b = (a2 + c2)/2; 
		c = (a2 + b2)/2; 
		++cnt;
	}
	}
  cout << cnt << "\n";
	}
return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
	"sort"
)

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	var x, y, z, k int
	fmt.Fscan(fp, &x, &y, &z, &k)
	aList := make([]float64, x)
	bList := make([]float64, y)
	cList := make([]float64, z)
	for i := 0; i < x; i++ {
		fmt.Fscan(fp, &aList[i])
	}
	for i := 0; i < y; i++ {
		fmt.Fscan(fp, &bList[i])
	}
	for i := 0; i < z; i++ {
		fmt.Fscan(fp, &cList[i])
	}
	sort.Sort(sort.Reverse(sort.Float64Slice(aList)))
	sort.Sort(sort.Reverse(sort.Float64Slice(bList)))
	sort.Sort(sort.Reverse(sort.Float64Slice(cList)))
	yz := make([]float64, y*z)

	for i := 0; i < y; i++ {
		for j := 0; j < z; j++ {
			yz[i*z+j] = bList[i] + cList[j]
		}
	}
	cnt := k

	sort.Sort(sort.Reverse(sort.Float64Slice(yz)))
	sum := yz[:]
	if len(sum) > cnt {
		sum = yz[0:cnt]
	}
	cnt = len(sum)
	ans := make([]float64, x*cnt)
	for i := 0; i < x; i++ {
		for j := 0; j < cnt; j++ {
			ans[i*cnt+j] = aList[i] + sum[j]
		}
	}
	sort.Sort(sort.Reverse(sort.Float64Slice(ans)))

	for i := 0; i < k && i < 3000; i++ {
		fmt.Println(int64(ans[i]))
	}
}


Measured memory_bytes: 35076
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;


int main()
{
	fast;
	cin>>n>>m;
	// cout<<(n+m-1)/m
	fs(ar,n);
	sort(ar+1,ar+n+1);
	fo(i,1,n-m)
	sum+=ar[i];
	cout<<sum;
}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/


Measured memory_bytes: 1792
#include <vector>
#include <iostream>
using namespace std;
vector<int> par;
int root(int x) {
	if (x == par[x]) return x;
	return par[x] = root(par[x]);
}
bool contain_cycle(int n, vector<int> a, vector<int> b) {
	par.resize(n);
	for (int i = 0; i < n; ++i) par[i] = i;
	for (int i = 0; i < a.size(); ++i) {
		if (root(a[i]) == root(b[i])) {
			return true;
		}
		par[root(a[i])] = root(b[i]);
	}
	return false;
}
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	vector<int> deg(N);
	for (int i = 0; i < M; ++i) {
		cin >> A[i] >> B[i];
		--A[i], --B[i];
		++deg[A[i]];
		++deg[B[i]];
	}
	int state = 1;
	for (int i = 0; i < N; ++i) {
		if (deg[i] % 2 == 1) {
			state = 0;
			break;
		}
	}
	int cnt4 = 0;
	if (state == 1) {
		for (int i = 0; i < N; ++i) {
			if (deg[i] == 4) state = 2, ++cnt4;
			if (deg[i] >= 6) {
				state = 3;
				break;
			}
		}
	}
	if (state <= 1) {
		cout << "No" << endl;
	}
	else if (state == 3) {
		cout << "Yes" << endl;
	}
	else if (cnt4 >= 3) {
		cout << "Yes" << endl;
	}
	else {
		int advantage = 0;
		for (int i = 0; i < N; ++i) {
			if (deg[i] == 4) {
				vector<int> a, b;
				for (int j = 0; j < M; ++j) {
					if ((deg[A[j]] != 4 || A[j] == i) && (deg[B[j]] != 4 || B[j] == i)) {
						a.push_back(A[j]);
						b.push_back(B[j]);
					}
				}
				if (contain_cycle(N, a, b)) {
					++advantage;
				}
			}
		}
		int total = advantage + (cnt4 - advantage) / 2 + 1;
		cout << (total >= 3 ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  ll x;
  cin >> N >> x;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll ans = 0;
  REP(i, 1, N) {
    if(A[i-1] > x) {
      ans += A[i-1]-x;
      A[i-1] = x;
    }
    if(A[i-1]+A[i] > x) {
      ans += A[i-1]+A[i]-x;
      A[i] = x-A[i-1];
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
   ll n,y;cin >> n >>y;
    rep(i,n+1){
        rep(j,n+1){
            ll t=y-10000*i-5000*j;
            if(t<0)continue;
            if(t/1000+i+j==n){
            cout << i << " " << j << " " << t/1000 <<endl;
            return 0;
            }
        }
    }
    cout << -1 <<" " << -1 <<" " << -1 <<endl;
}   

Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty |) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty | $n:expr) => {
        (0..$n).map(|_| get!($t |)).collect::<Vec<_>>()
    };
}
macro_rules! tern {
    ($condition: expr, $_true: expr, $_false: expr) => {
        if $condition {
            $_true
        } else {
            $_false
        }
    };
}
fn main() {
    let X = get!(usize);
    let h = (X as f64 / 100f64).floor() as usize;
    let mut rem = X - h * 100;
    let mut alive = h;
    for i in (1..6).rev() {
        let n = (rem as f64 / i as f64).floor() as usize;
        if alive < n {
            println!("0");
            return;
        }
        alive -= n;
        rem -= n * i;
        if rem == 0 {
            println!("1");
            return;
        }
    }
    println!("0");
}


Measured memory_bytes: 4352
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

ret = 0
remain = A[0]
N.times do |i|
  if remain <= B[i]
    power = B[i] - remain
    ret += remain
    if A[i + 1] <= power
      remain = 0
      ret += A[i + 1]
    else
      remain = A[i + 1] - power
      ret += power
    end
  else
    ret += B[i]
    remain = A[i + 1]
  end
end
puts ret

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

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

bool isprime(ll n) {
  if(n == 1) return true;
  for(ll i = 2; i*i <= n; i++) {
    if(n % i == 0LL) return false;
  }
  return true;
}

const int MAX = 1000000 + 10;
int main() {
  ll A, B; cin>>A>>B;
  vector<ll> Acand, Bcand;
  for(ll i = 1; i * i <= A; i++) {
    if(A % i == 0) {
      Acand.push_back(i);
      if(i * i == A) continue;
      Acand.push_back(A / i);
    }
  }
  for(ll i = 1; i * i <= B; i++) {
    if(B % i == 0) {
      Bcand.push_back(i);
      if(i * i == B) continue;
      Bcand.push_back(B / i);
    }
  }
  //  pp(Acand, Acand.size());
  //  pp(Bcand, Bcand.size());
  set<ll> AcandSet(Acand.begin(), Acand.end());
  vector<ll> ans;
  REP(i, Bcand.size()) {
    if(AcandSet.find(Bcand[i]) != AcandSet.end()) {
      if(isprime(Bcand[i])) {
	ans.push_back(Bcand[i]);
      }
    }
  }
  //  pp(ans, ans.size());
    ll tmp = 0;
    REP(i, ans.size()) 
      if(isprime(ans[i])) {
	tmp++;
	//	cout << ans[i] << endl;
      }
    cout << tmp << endl;
  return 0;
}


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

const ll INF = 1LL << 60;
const ll MOD = ll(1e9)+7;


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

    vector<ll> A(N);
    vector<ll> B(400001);
    vector<ll> C(400001);

    for (ll i = 0; i < N; i++) {
        cin >> A.at(i);

        if (A.at(i) <= 200000) {
            B.at(i + A.at(i))++;

            if ((i - A.at(i)) <= 400000 && (i - A.at(i)) >= 0) {
                C.at(i - A.at(i))++;
            }
        }
    }

    ll ans = 0;

    for (ll i = 0; i < B.size(); i++) {
        ans += B.at(i)*C.at(i);
    }

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

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




int main()
{
	string ss = "YAKI";
	string s;
	cin>>s;
	for(int i=0;i<=3;i++)
		if(s[i] != ss[i]){puts("No");return 0;}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
N,M,*xys=$<.read.split.map(&:to_i)

counts = Array.new(N+1,1)
boxes = Array.new(N+1,false)
boxes[1] = true

xys.each_slice(2) do |x,y|
  counts[y] += 1
  counts[x] -= 1

  if boxes[x]
    boxes[y] = true
    if counts[x] == 0
      boxes[x] = false
    end
  end
end

p boxes.count(true)


Measured memory_bytes: 18300
#include <iostream>

using namespace std;
int gcd(int a,int b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int main()
{
    int g;
    int n,m;
    int l;
    while(cin>>n>>m){
        if(n>=m)
            g=gcd(n,m);
        else
            g=gcd(m,n);
        l=g*(n/g)*(m/g);
        cout<<g<<" "<<l<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))

h = []
for i in range(n):
    heapq.heappush(h, -a[i])

for i in range(m):
    b = -heapq.heappop(h)
    c = b // 2
    heapq.heappush(h, -c)

print(-sum(h))



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

const ll MAX = 510000;
const ll MOD = 998244353;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


// aのn乗のMOD
ll modpow(ll a,ll n){
    ll res = 1;
    while(n>0){
        // &１つはビット積
        if(n&1) res = res * a%MOD;
        a = a*a%MOD;
        n>>=1;
    }
    return res;
}



int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll N,M,K;
	cin>>N>>M>>K;
	ll d = modpow(M-1,N-K-1);
	d *= M;
	d %=MOD;
	COMinit();
	
	ll ans = 0;
	ll k = K;
	rep(i,K+1){
		ans += (d * COM(N-1,k))%MOD;
		ans %=MOD;
		--k;
		d *=M-1;
		d %= MOD;
	}

	cout<<ans<<"\n";
	

	
	return 0;
}


Measured memory_bytes: 15580
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int r = 0;
    function<void(int)> dfs = [&](int i) {
        for (int a = 3; a <= 7; a += 2) {
            int j = i * 10 + a;
            if (j <= n) {
                int p[10] = {};
                for (int t = j; t; t /= 10) p[t % 10]++;
                if (p[3] && p[5] && p[7]) r++;
                if ((ll)j * 10 < n) dfs(j);
            }
        }
    };
    dfs(0);

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll inf = 1e18+5;
ll h, a;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> h >> a;
  	if (h%a == 0)cout << h/a;
  	else cout << h/a +1;
}


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

using namespace std;

int n;
int a[20010],b[20010],p[20010];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	a[1]=n+1;
	for(int i=2;i<=n;i++)
		a[i]=a[i-1]+n+1;
	for(int i=1;i<=n;i++)
		b[i]=a[n-i+1];
	for(int i=1;i<n;i++)
		a[p[i]]-=n-i+1;
	for(int i=1;i<=n;i++)
		printf("%d ",a[i]);
	puts("");
	for(int i=1;i<=n;i++)
		printf("%d ",b[i]);
}

Measured memory_bytes: 896
from itertools import permutations

def dist(t1, t2):
    return ((t1[0] - t2[0])**2 + (t1[1] - t2[1])**2)**(0.5)

N = int(input())
coord = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
fact = 0
for tup in permutations(coord):
    fact += 1
    for t1, t2 in zip(tup, tup[1:]):
        ans += dist(t1, t2)
print(ans / fact)

Measured memory_bytes: 3188
import java.util.Scanner;
 
public class Main {
 
	public static final MyScanner in = new MyScanner();
	public static int[][][][] memo;
 
	public static void main(String[] args) {
 
		int N = in.nextInt();
		int answer = (N/2) + (N%2);
		System.out.println(answer);

	}
 

    public static long comb(int n, int r){
        long num = 1;
        for(int i = 1; i <= r; i++){
            num = num * (n - i + 1) / i;
        }
        return num;
    }
 
	public static class MyScanner{
		Scanner sc = new Scanner(System.in);
		String nextLine() {return sc.nextLine();}
		String next() {return sc.next();}
		int nextInt() {return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next());}
	}

}

Measured memory_bytes: 21844
fn main() {
    let v = read_vec::<u64>();
    let n = v[0];
    let m = v[1];

    let a = read_vec::<u64>();
    let a_first = a[0];
    /*
    if a.iter().all(|&i| i == a_first) {
        let ans = if (m / (a_first / 2)) % 2 == 0 {
            m / (a_first / 2)
        } else {
            m / (a_first / 2) + 1
        };
        println!("{}", ans);
        return;
    }
    */
    let a_half = a.into_iter().map(|ai| ai / 2).collect::<Vec<_>>();
    let mut a_gcd = a_half[0];
    for i in 1..n as usize {
        a_gcd = gcd(a_gcd, a_half[i]);
    }

    let a2 = a_half.into_iter().map(|ai| ai / a_gcd).collect::<Vec<_>>();
    let mut a_lcm = 1;
    for ai in a2 {
        if ai % 2 == 0 {
            println!("0");
            return;
        } else {
            a_lcm = lcm(a_lcm, ai);
        }
    }
    let aa = a_gcd * a_lcm;
    let ans = if (m / aa) % 2 == 0 {
        m / (aa * 2)
    } else {
        m / (aa * 2) + 1
    };
    println!("{}", ans);
}

fn gcd(x: u64, y: u64) -> u64 {
    if x == 0 {
        y
    } else {
        gcd(y % x, x)
    }
}

fn lcm(x: u64, y: u64) -> u64 {
    x * y / gcd(x, y)
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 8444
def main():
    N, L = (int(i) for i in input().split())
    s = sum(L+i-1 for i in range(1, N+1))
    mi = 10**5
    ans = -1
    for i in range(1, N+1):
        cur = L + i - 1
        eat = s - cur
        if abs(s - eat) < mi:
            mi = abs(s - eat)
            ans = eat
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

public class Main {
    private void solve() {
        int r = sc.nextInt();
        out.println(r * 3.1415926 * 2);
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}


Measured memory_bytes: 33076
#define ALL(v) v.begin(), v.end()
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


int main() {

	ll n, m;
	cin >> n >> m;

	priority_queue<int> q;


	for (ll i = 0; i < n; i++)
	{
		int temp;
		cin >> temp;
		q.push(temp);
	}


	for (int i = 0; i < m; i++)
	{
		int temp = q.top();
		q.pop();
		q.push(temp / 2);
	}

	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		ans += q.top();
		q.pop();
	}


	cout << ans << endl;


}



Measured memory_bytes: 892
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            long x = Long.parseLong(sc.next());
            long y = Long.parseLong(sc.next());
            if (Math.sqrt(x * x + y * y) <= d) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

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

using namespace std;

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

    S.push_back('E');
    string short_S;
    int i;
    for (i = 0; i < S.size() - 1; i++) {
        
        if (S[i] != S[i + 1]) short_S.push_back(S[i]);

    }

    cout << short_S.size() - 1;

    return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

  int R; cin >> R;
  if (R < 1200) {
    cout << "ABC" << endl;
  } else if (R < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }

  return 0;
};


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

int main(){
  int n;
  cin >> n;
  n*=2;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  int ans=0;
  for(int i=0;i<n;i+=2){
    ans+=a[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
//typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};


bool ch[150];
int num[150];

int main(){
    while(true){
    //    char data[120];
        string data;
        getline(cin,data);
    //    gets(data);
        if(data[0] == '.') break;
      //  int len = strlen(data);
        int len = data.length();
        int sum = 0;
        for(int i = 0;i < len;i++){
            int add = 0;
            switch(data[i]){
                case '(':
                    add = -1;
                    break;
                case '[':
                    add = -2;
                    break;
                case ')':
                    add = 1;
                    break;
                case ']':
                    add = 2;
                    break;
            }
            if(add == 0)continue;
            ch[sum] = false;
            num[sum++] = add;
        }
        int ans = 1,max = sum;
        while(true){
            if(sum % 2 != 0){ ans = 0; break;}
            if(sum == 0) break;
            int check = 0;
            for(int i = 1;i < sum;i++){
                int a,b;
                int count = 0;
                for(int j = 0;j < max;j++){
                    if(ch[j] == false){
                        count++;
                        if(count == i){
                            a = j;
                        }else if(count == i+1){
                            b = j;
                            break;
                        }
                    }
                }
                if(num[a] + num[b] == 0 && num[a] < num[b]){
                    ch[a] = true; 
                    ch[b] = true;
                    sum -= 2;
                    check = 1;
                    break;
                }
            }
            if(check == 0){ ans = 0; break;}
        }
        if(ans == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}



Measured memory_bytes: 3152
import java.util.Scanner;

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

		// 0
		// d*(d-1)
		// n*(n+1)
		// 51(d-n)
		long ans=3000;

		if (d-n>2022) {
			System.out.println(0);
		} else {
for(long i=n;i<=d-1;i++){
	for(long k=i+1;k<=d;k++){

		if(ans>((i%2019)*(k%2019))%2019){
			ans=((i%2019)*(k%2019))%2019;

		}
	}
}

System.out.println(ans);
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
using namespace std;
typedef long long ll;
bool x[110], y[110];
int main() {
	int h, w;
	cin >> h >> w;
	char a[110][110];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++)cin >> a[i][j];
	}
	for (int i = 0; i < h; i++) {
		bool f = false;
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				f = true;
			}
		}
		if (!f)x[i] = true;
	}
	for (int i = 0; i < w; i++) {
		bool f = false;
		for (int j = 0; j < h; j++) {
			if (a[j][i] == '#')f = true;
		}
		if (!f)y[i] = true;
	}
	for (int i = 0; i < h; i++) {
		if (x[i])continue;
		for (int j = 0; j < w; j++) {
			if (y[j])continue;
			cout << a[i][j];
		}
		cout << endl;
	}
	system("PAUSE");
	return 0;
}


Measured memory_bytes: 504
def z_algorithm(S):
    l=len(S)
    A=[0]*n
    i=1;j=0
    while i<l:
        while(i+j<l and S[j]==S[i+j]):
            j+=1
        A[i]=j
        if j==0:
            i+=1
            continue
        k=1
        while i+k<l and k+A[k]<j:
            A[i+k]=A[k]
            k+=1
        i+=k
        j-=k
    return A
n=int(input())
s=input()
ans=0
for i in range(n-1):
    a=z_algorithm(s[i:])
    for j in range(len(a)):
        if(a[j]<=j):
            ans=max(ans,a[j])
print(ans)

Measured memory_bytes: 52444