akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
ll N,K;
cin >> N >> K;
vector<ll> vec(N);
rep(i,N) {
    cin >> vec.at(i);
}
sort(vec.begin(),vec.end());
reverse(vec.begin(),vec.end());
ll ans = 0;
for(int i = K;i < N;i++) {
    ans += vec.at(i);
}
cout << ans << endl;

return 0;
}

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r,d,x;
    cin>>r>>d>>x;
    FOR(i,0,10){
      x = r*x - d;
      cout<<x<<endl;
    }
}


Measured memory_bytes: 256
N,X,Y = map(int,input().split())

ans = {i+1:0 for i in range(N-1)}

d = lambda i,j: min(abs(i-j), abs(X-i)+1+abs(Y-j), abs(Y-i)+1+abs(X-j))

for i in range(N):
    for j in range(i+1,N):
        ans[d(i+1,j+1)] += 1

for i in range(1,N):
    print(ans[i])

Measured memory_bytes: 3700
require 'date'

class Whatday
  def self.date(m, d)
    Date::DAYNAMES[Date.new(2004, m, d).wday]
  end
end

STDIN.read.split("\n").each do |line|
  m, d = line.split.map(&:to_i)
  break if m.zero?
  puts Whatday.date(m, d)
end

Measured memory_bytes: 8840
import scala.io.StdIn._

object Main extends App {

  val D = Array.fill(5)(readInt())

  def solve() = {
    val lastDishIndex = D.zipWithIndex.collect {
      case (minutes, i) if minutes % 10 != 0 => (minutes % 10, i)
    }.sortBy(_._1).map(_._2).headOption
    lastDishIndex match {
      case None => D.sum
      case Some(idx) => {
        D.zipWithIndex.foldLeft(0) { case (acc, (minutes, i)) =>
          if(i == idx) acc + D(i)
          else acc + D(i) + losTime(D(i))
        }
      }
    }
  }

  def losTime(t: Int): Int = {
    if(t % 10 == 0) 0
    else 10 - (t % 10)
  }

  println(solve())

}



Measured memory_bytes: 54920
from math import factorial

n, m = map(int, input().split())
if n in [0, 1] and m in [0, 1]:
    ans = 0
elif n in [0, 1]:
    ans = factorial(m) // (factorial(m - 2) * factorial(2))
elif m in [0, 1]:
    ans = factorial(n) // (factorial(n - 2) * factorial(2))
else:
    ans = factorial(n) // (factorial(n - 2) * factorial(2))
    ans += factorial(m) // (factorial(m - 2) * factorial(2))
print(ans)


Measured memory_bytes: 3064
# coding: utf-8
# Your code here!
#ポイント：ピリオドで文章が終わるとは限らない。ピリオドが2つ続いてたらということを考える

s = list(input())
#print(s)
c = 0
n = [] 
ans = [] 
for i in range(len(s)):
    if s[i] == "," or s[i] == "." or s[i] == " ":
        if c >= 3 and c <= 6:
            ans = ans + n + [" "] #appendは使えない
        n.clear()
        c = 0
    else:
        n.append(s[i])
        c += 1

del ans[-1] #最後のスペースを削除
#print(*ans, sep = "")
for i in range(len(ans)):
   print(ans[i], end = "")
print("")
   



Measured memory_bytes: 5604
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

char board[30][30];

int main(void){
	int n;
	cin>>n;
	vector<ll>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	priority_queue<ll,vector<ll>,less<ll> >pq;
	ll ans = 0;
	sort(a.begin(),a.end(),greater<ll>());
	for(int i=0;i<n;i++){
		if(pq.empty()){
			pq.push(a[i]);
		}
		else{
			ll p = pq.top();
			pq.pop();
			if(p>a[i]){
				ans+=p;
				pq.push(a[i]);
				pq.push(a[i]);
			}
			else{
				ans+=p;
				pq.push(p);
				pq.push(p);
			}
		}
	}
	cout<<ans<<endl;
    return 0;
}

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

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

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

    int N, X; cin >> N >> X;
    int x; cin >> x;
    int ans = abs(x - X);
    for (int i = 1; i < N; i++) {
        cin >> x;
        ans = gcd(ans, abs(x - X));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define INF 1e9+10
using namespace std;
const int maxn=1e5+100;
int xx[maxn];
int cd[maxn];
set<int>st;
int k=0;
int gcd(int a,int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
int main()
{
    int n,x;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&xx[i]);
    for(int i=1;i<=n;i++)
    {
        st.insert(xx[i]);
    }
    st.insert(x);
    set<int>::iterator it;
    int j=0;
    for(it=st.begin();it!=st.end();++it)
    {
        xx[++j]=*it;
    }
    int ans=INF;
    for(int i=2;i<=j;i++)
    {

        cd[k++]=xx[i]-xx[i-1];

    }
    ans=cd[0];
    for(int i=1;i<k;i++)
        ans=gcd(ans,cd[i]);
    printf("%d\n",ans);
    return 0;

}



Measured memory_bytes: 5760
#include <stdio.h>
#include <math.h>

int main()
{
	long long int a, b, n, ans;
	scanf("%lld %lld %lld", &a, &b, &n);
	
	if(b-1 < n){
        ans = floor(a * (b - 1) / b) - a * floor((b - 1) / b);
	}
	else{
		ans = floor((a * n) / b )- (a * floor(n / b));
	}	
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1680
#include<stdio.h>
int main() {
	int i=0, n, ans;
	scanf("%d", &n);
	/*while (1) {
		i++;
		if((i % 2 == 0) && (i%n == 0)) {
				ans = i;
				break;
		}
	}*/
	if (n % 2 == 0) {
		ans = n;
	}
	else {
		ans = 2 * n;
	}
	printf("%d\n", ans);

}

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

int main() {
  const int INF = 1200005;
  int n,m,x; cin >> n >> m >> x;
  vector<int> C(n);
  vector<vector<int>> A(n, vector<int>(m));
  rep(i,n) {
    cin >> C[i];
    rep(j,m) {
      cin >> A[i][j];
    }
  }
  int ans = INF;
  for (int b=1; b<(1<<n); b++) {
    int sum = 0;
    vector<int> U(n,0);
    rep(i,n) {
      if (((b>>i) & 1) == 1) {
        rep(j,m) U[j] += A[i][j];
        sum += C[i];
      }
    }
    bool flag = true;
    rep(j,m) {
     if (U[j] < x) { flag = false; break; }
    }
    if (flag) ans = min(ans,sum);
  }
  if (ans == INF) ans = -1;
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int cnt1[100003],cnt2[100003],n,x,mx1,mx2,x1,x2;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(i%2==0)
		{
			cnt1[x]++;
			if(mx1<cnt1[x])
				mx1=cnt1[x],
				x1=x;
		}
		else
		{
			cnt2[x]++;
			if(mx2<cnt2[x])
				mx2=cnt2[x],
				x2=x;
		}
	}
	sort(cnt1,cnt1+100003);
	sort(cnt2,cnt2+100003);
	if(x1!=x2)
		cout<<n-mx1-mx2;
	else
		cout<<n-max(mx1+cnt2[100001],mx2+cnt1[100001]);
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
char a[55][55];
char b[55][55];
int n,m;
int c[8][2]={1,1,1,-1,-1,1,-1,-1,1,0,-1,0,0,1,0,-1};
int panduan(int x,int y)
{
    int sum=0;
    int x1,y1;
    for(int i=0;i<8;i++)
    {
        x1=x+c[i][0];
        y1=y+c[i][1];
        if(x1<=n&&x1>=1&&y1<=m&&y1>=1&&a[x1][y1]=='#')
        sum++;
    }
    return sum;
}
int main()
{

    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i]+1;
    for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(a[i][j]=='#')
                    b[i][j]='#';
                else
                    b[i][j]=panduan(i,j)+'0';
            }
        }
    for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                cout<<b[i][j];
            }
            cout<<endl;
        }
    return 0;
}


Measured memory_bytes: 256
X, K, D = map(int, input().split())
X = abs(X)
k1 = X // D
if k1 >= K:
    print(abs(X - D * K))
    exit()

k = K - k1
x = X % D

while k > 0:
    x = abs(x - D)
    k -= 1
    if k == 0:
        print(x)
        exit()
    if abs(x) < D:
        if k % 2 == 0:
            print(abs(x))
        else:
            print(D-abs(x))
        exit()



Measured memory_bytes: 9120
limit = pow(10, 7)
K = int(input())
num = "7"
if K % 2 == 0 or K % 5 == 0:
    print (-1)
else:
    total = 0
    flag = False
    for i in range(1, limit + 1):
        total = (total * 10 + 7) % K
        if total == 0:
            flag = True
            break
    if flag:
        print (i)
    else:
        print(-1)

Measured memory_bytes: 9108
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

ll gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}

ll solve(ll x, ll y) {
    return x + y - 1;
}

int main() {
    int x, y; cin >> x >> y;

    int g = gcd(x, y);
    x /= g, y /= g;
    cout << solve(x, y) * g + 1 << endl;
    return 0;
}



Measured memory_bytes: 3116
n=input()
a=[map(int,raw_input().split()) for _ in xrange(n)]
t=1<<n
q=[-(1<<64)]*t
for m in xrange(t):
    s=0
    for i in xrange(n):
        if (m>>i)&1:
            for j in xrange(i):
                if (m>>j)&1:
                    s+=a[i][j]
    q[m]=max(q[m],s)
z=[-(1<<64)]*t
for m in xrange(t):
    z[m]=q[m]
    s=m
    while s:
        z[m]=max(z[m],z[s]+q[(~s)&m])
        s=(s-1)&m
print z[-1]

Measured memory_bytes: 85788
/**
 *      ///----- My Info -----///
 *      Code by: Ernesto Abreu
 *      Codeforces User: Ernest0_0Abreu
 *      Country: Cuba
 *      E-mail: ernestoabreup@gmail.com
 *      CopyRight
**/
#include <bits/stdc++.h>
#ifdef Ernest0_0Abreu
#include <debug/to_string.h>
#endif
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
    	///----- My Template -----///
///======================================================================================================================================
/// Red-Black Tree
// #include <ext/pb_ds/assoc_container.hpp>  // .find_of_order(x); .order_of_key(x);
// using namespace __gnu_pbds;
// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > indexed_set;
/// Function
#define pi (acos(-1))
#define lg2(x) 31-__builtin_clz(x)
#define lgx(x,b) log(b)/log(x)
/// Macros
#define fst first
#define scd second
#define left (node<<1)
#define right ((node<<1)+1)
#define size(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
/// Debug
#define _end cout << "\n"
#ifdef Ernest0_0Abreu
#define db(x) cerr << "[ "<< #x << " ]: " << to_string(x) << "\n"
#define dbrange(x,begin,end) cerr << "[ "<< #x << " ]: " << to_string(x,begin,end) << "\n"
#define dbname(x) cerr << to_string(x,#x) << "\n"
#define dbnamerange(x,begin,end) cerr << to_string(x,#x,begin,end) << "\n"
#define dbmat(x,begin_n,end_n,begin_m,end_m) cerr << to_string(x,#x,begin_n,end_n,begin_m,end_m) << "\n"
#else 
#define db(x) ;
#define dbrange(x,begin,end) ;
#define dbname(x) ;
#define dbnamerange(x,begin,end) ;
#define dbmat(x,begin_n,end_n,begin_m,end_m) ;
#endif
/// Typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// Constant
const int MAXN = 2e5+7;
const int MOD = 1e9+7;
const ull BASE = 311;
const ld EPS = 1e-9;
const int INF = ((1<<30)-1);
const ll INFLL = ((1ll<<62ll)-1ll);
const ll oo = 2e18;
/// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027;
/// Module Prime Numbers: 3, 998244353, 1000000007, 1000000009, 1000000021, 1000000033;
///=======================================================================================================================================
#define int long long
		///----- My code -----///

map<string,int> mp;
string s[MAXN];

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

	int N;
	cin >> N;
	int ans = 0;
	for(int i = 1; i <= N; ++i){
		cin >> s[i];
		mp[s[i]]++;
		if(mp[ s[i] ] == 1) ans++;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 25492
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, K, ans;
    string S;
    cin >> N >> K;
    cin >> S;
    S.at(K-1) += 0x20;
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
f = sum([1 for i in a if not i % 4])
if f >= int(N / 2):
  print('Yes')
else:
  s = sum([1 for i in a if not i % 2 and i % 4])
  if f + s // 2 >= int(N / 2):
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 20148
#include<iostream>
using namespace std;
typedef long long LL;
int main(){
	LL a[100],n;
	cin>>n;
	a[0] = 2;
	a[1] = 1;
	for(int i=2; i<=86; ++i){
		a[i] = a[i-1]+a[i-2];	
	}
	cout<<a[n]<<endl;
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
int n;
cin>>n;
set<int> m;
for(int i=0;i<n;i++){
int l;
cin>>l;
if(m.count(l))m.erase(l);
else m.insert(l);
}
cout<<m.size()<<endl;
}

Measured memory_bytes: 4864
/*In the name of Allah*/
#include<bits/stdc++.h>

#include<cstdio>
#include<vector>
#include<utility>
#include<string>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <string>

#include <set>
#include <map>
#include <sstream>
#include <queue>
#include <string.h>

#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace __gnu_cxx;
using namespace std;
typedef long long ll;
typedef long double ld;

#define pi acos(-1)
#define s(a) scanf("%d",&a)
#define p(a) printf("%d",a)

#define csp(a) cout<<a<<' '
#define cnl(a) cout<<a<<'\n'
#define nl cout<<'\n';
#define sp cout<<' ';


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

#define rep(i, n) REP(i, 0, (n))


#define REPE(i,a,b) for (int i = (a); i <= (b) ; ++i)
#define repe(i,n) REPE(i, 1, (n))


#define optimize() ios_base::sync_with_stdio(0)
int main(){ optimize();

string s; cin>>s; 
    
if(s[0]=='7'||s[1]=='7'||s[2]=='7')
        cout<<"Yes";
        else cout<<"No";


return 0;}

Measured memory_bytes: 3624
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

void solve(ll N, ll M) {
  ll r = (N * (N - 1)) / 2;
  ll l = (M * (M - 1)) / 2;

  ll result = r + l;
  cout << result << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  solve(N, M);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
long long n,x,ans;
int main()
{
	scanf("%lld%lld",&n,&x);
	while (x!=n&&x!=0)
	{
		if (x*2>n)
			x=n-x;
		ans+=(n-x)/x*3ll*x;
		n-=(n-x)/x*x;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
# https://atcoder.jp/contests/abc133/tasks/abc133_c
# MODって掛け算でも分解できなかったっけ？って気づけばO(n)となり終わり?
# いや、O(n)だと2*10**9なのでpythonだと間に合わない！
# mod 2019 の計算結果は2019ごとに繰り返すことに気がつくと一気に計算が少なくなる

MOD = 2019  # これなにげに3の倍数だからいつも見たいなMODの演算が通用しない笑
L, R = list(map(int, input().split()))
# このコーナーケースに注意
if (R - L) >= MOD:
    print(0)
    exit()

# Lをなるべく0に近づける
L %= 2019
# RをなるべくLに近づけてみる
R %= 2019
if R <= L:
    R += MOD

ans = 2019
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        ans = min(ans, (i * j) % MOD)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,a,b,cnt[3] = {};
	cin >> n >> a >> b;
	for(int i = 0;i < n;i++){
		int p;
		cin >> p;
		if(p <= a) cnt[0]++;
		else if(p > b) cnt[2]++;
		else cnt[1]++;
	}
	cout << min({cnt[0],cnt[1],cnt[2]}) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main()
{
    long long oo = 0xffffffffffff;
 
    int A, B, Q;
    cin>>A>>B>>Q;
    vector<long long> s(A+4);
    s[0] = -oo;
    s[1] = -oo+1;
    for (int i=0; i<A; i++)
        cin>>s[i+2];
    s[A+2] = oo-1;
    s[A+3] = oo;
    vector<long long> t(B+4);
    t[0] = -oo;
    t[1] = -oo+1;
    for (int i=0; i<B; i++)
        cin>>t[i+2];
    t[B+2] = oo-1;
    t[B+3] = oo;
 
    auto index = [&](vector<long long> &v, long long x)
    {
        return (int)(lower_bound(v.begin(), v.end(), x) - v.begin());
    };
 
    for (int i=0; i<Q; i++)
    {
        long long x;
        cin>>x;
 
        long long ans = oo;
        for (int b=0; b<8; b++)
        {
            int st = b&1;
            int d1 = b>>1&1;
            int d2 = b>>2&1;
 
            vector<long long> &v1 = st==0 ? s : t;
            vector<long long> &v2 = st==0 ? t : s;
 
            long long x2 = v1[index(v1, x)-d1];
            long long x3 = v2[index(v2, x2)-d2];
            ans = min(ans, abs(x-x2)+abs(x2-x3));
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 2944
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MOD 998244353
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long lli;
int cmp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main()
{
    int n, i, count=0;
    lli sum=0, ans=0, a[100000], min=1e9;
    scanf("%d",&n);
    for(i=0; i<n; i++) {
        scanf("%lld",a+i);
        if(a[i] < 0) {
            a[i] *= -1;
            count++;
        }
        min = MIN(min, a[i]);
        sum += a[i];
    }
    if(count%2 == 0) {
        ans = sum;
    } else {
        ans = sum - 2*min;
    }
    printf("%lld",ans);

    return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String input = scan.nextLine();
    int length = input.length();
    System.out.println(input.charAt(0) + String.valueOf(length - 2) + input.charAt(length - 1));
  }
}


Measured memory_bytes: 22100
// 3:10
#include <iostream>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <tuple>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll,ll>;
using tll = tuple<ll,ll,ll>;
#define pb push_back
#define for1(i,n) for (ll i=0;i<(n);(i)++)
#define for2(i,m,n) for (ll i=(m);(i)<(n);(i)++)
#define for3(i,m,n,d) for (ll i=(m);(i)<(n);(i)+=(d))
#define INF (1LL << 60)
#define DEBUG 0
#if DEBUG
    #define dump(v1) dump_1(#v1, v1)
    #define dump2(v1,v2) dump_2(#v1, v1, #v2, v2)
    #define dump3(v1,v2,v3) dump_3(#v1, v1, #v2, v2, #v3, v3)
#else
    #define dump(v1)
    #define dump2(v1,v2)
    #define dump3(v1,v2,v3)
#endif
#if DEBUG
template <typename T>
void dump_1(const string& n1, const T& v1)
{
    cerr << n1 << ": " << v1 << endl;
}
template <typename T1, typename T2>
void dump_2(const string& n1, const T1& v1, const string& n2, const T2& v2)
{
    cerr << n1 << ": " << v1 << "  " << n2 << ": " << v2 << endl;
}
template <typename T1, typename T2, typename T3>
void dump_3(const string& n1, const T1& v1, const string& n2, const T2& v2, const string& n3, const T3& v3)
{
    cerr << n1 << ": " << v1 << "  " << n2 << ": " << v2 << "  " << n3 << ": " << v3 << endl;
}
template <typename T1,typename T2>
ostream& operator << (ostream& os, const pair<T1,T2>& v)
{
    os << "(" << v.first << ", " << v.second << ")";
    return os;
}
template <typename T1,typename T2, typename T3>
ostream& operator << (ostream& os, const tuple<T1,T2,T3>& v)
{
    os << "(" << get<0>(v) << ", " << get<1>(v) << ", " << get<2>(v) << ")";
    return os;
}
template <typename T>
ostream& operator << (ostream& os, const vector<T>& v)
{
    os << "[";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << *it;
    }
    os << "]";
    return os;
}
template <typename T>
ostream& operator << (ostream& os, const set<T>& v)
{
    os << "{";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << *it;
    }
    os << "}";
    return os;
}
template <typename T1, typename T2>
ostream& operator << (ostream& os, const map<T1,T2>& v)
{
    os << "{";
    for (auto it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) {
            os << ", ";
        }
        os << it->first << ":" << it->second;
    }
    os << "}";
    return os;
}
#endif // DEBUG
template <typename T>
void print(const T& v)
{
    cout << v << endl;
}
//---------------------------------------------------------

void solve()
{
    ll X,A,B;
    cin >> X >> A >> B;
    if (B <= A) {
        print("delicious ");
    } else if (B <= A + X) {
        print("safe ");
    } else {
        print("dangerous ");
    }
}

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


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
	int home,a,b;
	scanf("%d%d%d",&home,&a,&b);
	if(abs(home - a ) < abs(home - b)) printf("A\n");
	else printf("B\n");
	
	
	
 	return 0;
}

Measured memory_bytes: 1612
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
const vi tbl = {1, 1, 2, 6, 24, 120, 720, 5040};

int main(void){
    int n;
    cin >> n;
    vi P(n), Q(n);
    for(int &p : P) cin >> p;
    for(int &q : Q) cin >> q;
    int p = 0, q = 0;
    for(int i=0; i<n-1; i++){
        p += (P[i]-1)*tbl[n-1-i];
        q += (Q[i]-1)*tbl[n-1-i];
        for(int j=i+1; j<n; j++){
            if(P[j]>P[i]) P[j]--;
            if(Q[j]>Q[i]) Q[j]--;
        }
    }
    cout << (p>q?p-q:q-p) << '\n';
    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int m = s.nextInt();
    int[][] A = new int[n][m];
    for(int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        A[i][j] = s.nextInt();
      }
    }
    int[] b = new int[m];
    for(int j = 0; j < m; j++) {
      b[j] = s.nextInt();
    }
    for(int i = 0; i < n; i++) {
      int c = 0;
      for (int j = 0; j < m; j++) {
        c += A[i][j] * b[j];
      }
      System.out.println(c);
    }
  }
}


Measured memory_bytes: 40716
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	string str;
	cin >> str;
	int count = str.length();
	bool flag = true;
	if (count ==1 || count == 3 || count == 5 || count == 7 || count ==9) {
		cout << "No" << endl;
		return 0;
	}
	if (count == 2) {
		if (str != "hi") {
			cout << "No" << endl;
			return 0;
		}
	}
	if (count ==4) {
		if (str != "hihi") {
			cout << "No" << endl;
			return 0;
		}
	}
	if (count == 6) {
		if (str != "hihihi") {
			cout << "No" << endl;
			return 0;
		}
	}
	if (count == 8) {
		if (str != "hihihihi") {
			cout << "No" << endl;
			return 0;
		}
	}
	if (count == 10) {
		if (str != "hihihihihi") {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
N, T = STDIN.gets.chomp.split(" ").map(&:to_i)

minimal_cost = nil

N.times do
  ci, ti = STDIN.gets.chomp.split(" ").map(&:to_i)

  if ti <= T 
    if minimal_cost.nil?
      minimal_cost = ci
    else
      minimal_cost = [minimal_cost, ci].min
    end
  end
end

if minimal_cost.nil?
  puts "TLE"
else
  puts minimal_cost
end


Measured memory_bytes: 1788
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const int big=1e9+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
int main(void){
	int i,n,j;cin>>n;
	vector<int>in(n);
	for(i=0;i<n;i++){cin>>in[i];}
	vector<int>kou;
	while(-1){
		kou.pub(1);
		for(j=0;j<n-1;j++){
			if(in[j]>in[j+1]){swap(in[j],in[j+1]);kou.pub(n-1);}
			kou.pub(1);
		}
		int ok=1;
		for(j=0;j<n;j++){
			if(in[j]!=j){ok=0;break;}
		}
		if(ok){break;}
	}
	cout<<kou.size()<<endl;
	for(auto it:kou){cout<<it<<endl;}
	RE;
}

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

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

  for(int i=0;i<N;i++){
    if((i%2==0) && (a[i]%2==1)){
      result += 1;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 3620
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let s: String = input();
    println!(
        "{}",
        s.chars()
            .enumerate()
            .filter_map(|(i, c)| if i % 2 == 0 { Some(c) } else { None })
            .collect::<String>()
    );
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
#define MAX_N 10
int dis[10][10];
int main(){
    int H,W;
    cin >> H >> W;
    REP(i,10){
        REP(j,10){
            int c;
            cin >> c;
            dis[i][j] = c;
        }
    }
    REP(k,10){
        REP(i,10){
            REP(j,10){
                if(dis[i][j] > dis[i][k] + dis[k][j]){
                    dis[i][j] = dis[i][k] + dis[k][j];
                }
            }
        }
    }
    int ans = 0;
    REP(i,H){
        REP(j,W){
            int A;
            cin >> A;
            if(A != -1) ans += dis[A][1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll N,M;
    cin >> N >> M;
    ll A[N];
    ll sum = 0;
    rep(i,N){
        cin >> A[i];
        sum+=A[i];
    }
    sort(A,A+N);
    string out = "Yes";
    rep(i,M){
        if(double(A[N-1-i])<(double)sum/(double)M/4.0){
            out = "No";
            break;
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import math

a = []
while True:
    n = int(input())
    if n == 0:
        break
    a.append(n)

for n in a:
    dp = [0] * (n + 1)
    dp[0] = 1
    for i in range(n + 1):
        if i > 0: dp[i] += dp[i - 1]
        if i > 1: dp[i] += dp[i - 2]
        if i > 2: dp[i] += dp[i - 3]
    
    print(int(math.ceil(dp[n] / (365 * 10))))


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

int main(){
    const uintmax_t MOD = 1000000007;
    int n, k;
    cin >> n >> k;

    uintmax_t min = 0, max = n, ans = 0;
    for(int i = 1; i <= n; i++) {
        min += i;
        max += n - i;
        if(i >= k - 1) ans += max - min + 1;
        ans %= MOD;
    }

    if(k == 1) ans = (ans + n + 1) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define EQ(x, y) (abs(x - y) < 1e-9)
typedef long long ll;

vector<int> g[100001];
int dp[100001];

int dfs(int node)
{
	if (dp[node] != -1)
		return dp[node];
	for (auto x : g[node]){
		dp[node] = max(dp[node], dp[x] == -1 ? 1 + dfs(x) : 1 + dp[x]);
	}
	return dp[node] == -1 ? 0 : dp[node];
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;

	int n, m;
	cin >> n >> m;
	for (int i = 0, from, to; i < m; ++i){
		cin >> from >> to;
		g[from].push_back(to);
	}
	
	for (int i = 1; i <= n; ++i)
		g[0].push_back(i);

	memset(dp, -1, sizeof(dp));
	cout << dfs(0) - 1 << '\n';
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;

int main () {
    int a, b; cin >> a >> b;
    
    if (a + (a - 1) > a + b) cout << a + (a - 1) << endl;
    else if (b + (b - 1) > a + b) cout << b + (b - 1) << endl;
    else cout << a + b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>

using namespace std;

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

const int N=10000001;
lli seive[N]={0};
lli ct[N]={0};
lli divct[N]={0};
vector<lli> p;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i,j,tt=1;
    //cin>>tt;
    while(tt--)
    {
        seive[1]=1;
        ct[1]=1;
        divct[1]=1;
        for(i=2;i<N;i++)
        {
            if(seive[i]==0)
            {
                seive[i]=i;
                divct[i]=2;
                ct[i]=1;
                p.push_back(i);
            }
            for(j=0;j<p.size() && p[j]<=seive[i] && i*p[j]<N;j++)
            {
                if(p[j]<seive[i])
                {
                    seive[i*p[j]]=p[j];
                    ct[i*p[j]]=1;
                    divct[i*p[j]]=2*divct[i];
                }
                else
                {
                    seive[i*p[j]]=p[j];
                    ct[i*p[j]]=ct[i]+1;
                    divct[i*p[j]]=divct[i];
                    divct[i*p[j]]/=(ct[i]+1);
                    divct[i*p[j]]*=(ct[i*p[j]]+1);
                }
            }
        }
        lli n,ans=0;
        cin>>n;
        for(i=1;i<=n;i++)
        {
            ans+=(divct[i]*i);
            //cout<<ans<<" ";
        }
        cout<<ans<<"\n";
    }
    return 0;
}



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


int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int ans;
  int D = A - B;
  if(D > C){
    ans = 0;
  }
  else{
    ans = C - D;
  }
  cout << ans << endl;
  
    
}


Measured memory_bytes: 256
def kenken(place, others, map)
  if(map[place + 1] == "." && place + 1 != others) then
    #puts 1
    return 1
  elsif(map[place + 2] == "." && place + 2 != others) then
    #puts 2
    return 2
  else
    #puts 0
    return 0
  end
end

  arr = gets.split(" ")
  map = gets
  n = arr.shift.to_i - 1
  a = arr.shift.to_i - 1
  b = arr.shift.to_i - 1
  c = arr.shift.to_i - 1
  d = arr.shift.to_i - 1

  if(d > c) then
    #puts "aaa"
    while(b <= n) do
      if(kenken(b, a, map) == 0) then
        puts "No"
        exit
      end
      b += kenken(b, a, map)
#      puts "b is"
#      puts b
      if(b == d) then
        while(a <= c) do
          if(kenken(a, b,map) == 0) then
            puts "No"
            exit
          end
          a += kenken(a, b, map)
#          puts "a is"
#          puts a
          if(a == c) then
            puts "Yes"
            exit
          end
        end
      end
    end
    puts "Error"
    exit
  else
#    puts "bbb"
    while(a <= n) do
      while(kenken(a, b, map) != 0) do
        a += kenken(a, b, map)
#        puts "a is"
#        puts a
        if(a == c) then
          puts "Yes"
          exit
        end
      end
      if(kenken(b, a, map) != 0 && b != d) then
        b += kenken(b, a, map)
#        puts "b is"
#        puts b
      else
        puts "No"
        exit
      end
    end
  end
  puts "Error"
  exit

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

void check(const vi& pre, const vi& in, int& pos, int l, int r) {
    int n = pre.size();

    if (l < r && pos < n) {
        int root = pre[pos++];
        int mid = distance(in.begin(), find(in.begin(), in.end(), root));

        check(pre, in, pos, l, mid);
        check(pre, in, pos, mid + 1, r);

        cout << root + 1;
        if (!(l == 0 && r == n)) { cout << " "; }
        else { cout << endl; }
    }
}

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

    vi pre(n), in(n);

    rep(i, 0, n) {
        int k;
        cin >> k;
        pre[i] = k - 1;
    }

    rep(i, 0, n) {
        int k;
        cin >> k;
        in[i] = k - 1;
    }

    int pos = 0;
    check(pre, in, pos, 0, n);
    return 0;
}


Measured memory_bytes: 3108
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    K = II()
    A,B = LMIIS()
    for i in range(A,B+1):
        if i % K == 0:
            print('OK')
            return
    print('NG')

if __name__ == '__main__':
    main()

Measured memory_bytes: 65160
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
//#define ONLINE_JUDGE
long long power(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;     
    x = x % p; 
    if (x == 0) return 0; 

    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}
int main()
{
	/*
		Jainam Shah's Code
	*/
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ll N,M;
	cin>>N>>M;
	ll ans = N*M;
	cout<<ans<<endl;
	
	
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define Rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int64_t intl;


int main(){
  intl N, A,B;
  cin  >> A >> B >>N;
  intl X;
  if ( N > B){ 
    X = ( N/B) * B -1;
  }
  else if ( N == B) {
    X = N - 1;
  }
  else {
    X = N;
  }
 cout << (A * X) / B - A*(X/B);
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main()
{
    int a,b,k;
    cin>>a>>b>>k;
    if ((b-a)%2==0)
    {
        if ((b-a)/2 >=k)
        {
            for (int i=0; i<k; i++)
            {
                cout<<a+i<<endl;
            }
            for (int i=k-1; i>=0; i--)
            {
                cout<<b-i<<endl;
            }
        }
        if ((b-a)/2 <k)
        {
            for (int i=0; i<=b-a; i++)
            {
                cout<<a+i<<endl;
            }
        }
    }
    if ((b-a)%2!=0)
    {
        if ((b-a-1)/2 >=k)
        {
            for (int i=0; i<k; i++)
            {
                cout<<a+i<<endl;
            }
            for (int i=k-1; i>=0; i--)
            {
                cout<<b-i<<endl;
            }
        }
        if ((b-a-1)/2 <k)
        {
            for (int i=0; i<=b-a; i++)
            {
                cout<<a+i<<endl;
            }
        }
    }
    return 0;
}

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

from collections import deque

b = deque([])
for i in range(n):
	if i%2 == 0:
		b.appendleft(a[i])
	else:
		b.append(a[i])

if n%2 == 0:
	b.reverse()
	print(*b)
else:
	print(*b)

Measured memory_bytes: 26020
#include "bits/stdc++.h"
using namespace std;
int main(){
    long long int a[5],n,mina=2000000000000000;
    int i;
    cin >>n;
    for(i=0;i<5;i++){
        cin >> a[i];
        mina=min(mina,a[i]);
    }
    cout << (n+mina-1)/mina+4<<endl;
    return 0;
}

Measured memory_bytes: 256
x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
divisors = make_divisors(x)

for d in divisors:
  b = - int(x**(1/5)) - 1
  f = False
  while True:
    if (b+d)**5 - b**5 == x:
      f = True
      break
    elif (b+d)**5 - b**5 > x and b > 0:
      break
    b += 1
  if f:
    print(b+d, b)
    break




Measured memory_bytes: 66272
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n, h[N], a[N];
ll dp[N], c[N];
void upd(int x, ll v)
{
	for(int i=x; i<N; i+=(i&-i)) c[i] = max(c[i], v);
}
ll query(int x)
{
	ll ans = 0;
	for(int i=x; i>0; i-=(i&-i)) ans = max(ans, c[i]);
	return ans;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n;
 	for(int i=1; i<=n; i++) cin >> h[i];
 	for(int i=1; i<=n; i++) cin >> a[i];
 	for(int i=1; i<=n; i++)
 	{
 		ll pre = query(h[i]-1);
 		dp[i] = pre + a[i];
 		upd(h[i], dp[i]);
 	}
 	ll ans = *max_element(dp+1, dp+n+1);
 	cout << ans;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 0
#define int long long
//#define int ll
using namespace std;
typedef vector<int> vi;

signed main(){
    int N,K;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    vector<int> p(N);
    rep(i,N)
    {
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    int nw = INF,sum;
    rep(i,N-K+1)
    {
        sum = p[i+K-1] - p[i];
        if(nw > sum) nw = sum;
    }
    cout << nw << endl;
    return 0; 
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.PrintWriter;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 高橋くんの夏休みN
		int N = Integer.parseInt(sc.next());
		// 夏休みの宿題M
		int M = Integer.parseInt(sc.next());
      
        int res = 0;
        for (int i=0; i<M; i++) {
          int day = Integer.parseInt(sc.next());
          res += day;
        }
		
		// res が N より大きかったら -1
      	if (res > N) {
          System.out.println("-1");
        } else {
          System.out.println(N-res);
        }
	}
}

Measured memory_bytes: 41416
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int n; cin >> n;
    int ans = 0;
    FOR(i, 1, n+1){
        int cnt = 0;
        if (i % 2 == 0) continue;
        FOR(j, 1, n+1){
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) ans++;
    }
    cout << ans << endl;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    vector<int> P(N);
    for (auto &x: P) cin >> x;
    sort(P.begin(), P.end());
    int Ans = 0;
    for (int i = 0; i < K; i++) {
        Ans += P[i];
    }
    cout << Ans << "\n";
    return 0;
}

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

#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    ll L, R;
    ll mod = 2019;
    cin >> L >> R;

    ll ans = 2020;

    if (R - L >= 2019) {
        ans = 0;
    }

    repd(i, L, R) {
        repd(j, i + 1, R + 1) {
            ll res = (i * j) % mod;
            ans = min(ans, res);
            if (ans == 0) {
                break;
            }
        }
        if (ans == 0) {
            break;
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=100005;
int n,m,ans,fa[N];
int a[N],b[N],c[N];
int isring[N],deg[N];
vector<int> v1,v2,v3,vec[N];
int get(int x){
	return x==fa[x]?x:fa[x]=get(fa[x]);
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%d",&n,&m);
	For(i,1,n) fa[i]=i;
	For(i,1,m) scanf("%d%d%d",&a[i],&b[i],&c[i]);
	For(i,1,m){
		++deg[a[i]]; ++deg[b[i]];
		fa[get(a[i])]=get(b[i]);
		if (a[i]!=b[i]) ++ans;
	}
	For(i,1,n)
		vec[get(i)].PB(i);
	int s1=0;
	For(i,1,n) if (get(i)==i){
		bool ring=1;
		for (auto j:vec[i])
			if (deg[j]!=2) ring=0;
		isring[i]=ring;
		if (vec[i].size()>=2&&isring[i]) ++s1;
	}
	ans+=s1;
	//cout<<ans<<' '<<s1<<endl;
	if (!s1) return cout<<ans<<endl,0;
	int key1=0,key2=0;
	For(i,1,m) if (c[i]>=2)
		if (!isring[get(a[i])]||vec[get(a[i])].size()>=2){
			if (!isring[get(a[i])]){
				if (a[i]!=b[i]) key1+=c[i]-1;
				else v2.PB(c[i]-1);
			}
			else{
				key2+=c[i]-1;
			}
		}
		else v3.PB(c[i]-2);
	//cout<<key1<<' '<<s1<<endl;
	sort(v2.begin(),v2.end());
	sort(v3.begin(),v3.end());
	if (v2.size()&&!key1){
		key1+=v2.back();
		v2.pop_back();
		ans++;
	}
	if (!key1) return cout<<-1<<endl,0;
	int key=key1+key2;
	//cout<<key<<' '<<v2.size()<<' '<<v3.size()<<endl;
	int p1=v2.size()-1,val=1<<30;
	for (auto i:v3) key+=i;
	For(i,0,v3.size()){
		for (;p1>=0&&key<s1;key+=v2[p1--]);
		//cout<<key1<<' '<<v3[i]
		if (key>=s1) val=min(val,(int)(v3.size()-i)*2+(int)v2.size()-p1-1);
		if (i==v3.size()) break;
		key-=v3[i];
	}
	if (val==1<<30) puts("-1");
	else printf("%d\n",ans+val);
}
/*
7 7
1 2 1
2 1 1
1 3 2
4 5 1
5 4 1
6 7 1
7 6 1
*/



Measured memory_bytes: 10604
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

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

int main() {
	int n;
	cin >> n;
	vint a(n);
	rep(i, n)cin >> a[i];
	sort(a.begin(), a.end());
	int cnt = 0;
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			cnt += 2;
			i++;
		}
	}
	cout << n - cnt << endl;
	return 0;
}


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

int main(){
  int dt[10];
  for(int i=0;i<10;i++)cin>>dt[i];
  sort(dt,dt+10);
  for(int i=9;i>=7;i--)cout<<dt[i]<<endl;
  return 0;
}

Measured memory_bytes: 1176