akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.lang.*;
import java.io.*;

class Main{
	public static void main (String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		int arr[]= new int[n];
		for(int i=0;i<n;i++){
			arr[i] = scan.nextInt();
			if(map.containsKey(arr[i])){
				map.put(arr[i],map.get(arr[i])+1);
			}
			else{
				map.put(arr[i],1);
			}
		}
		int count=0;
		for(int i=0;i<n;i++){
			if(!map.containsKey(arr[i])){
				continue;
			}
			if(map.get(arr[i])>arr[i]){
				count += map.get(arr[i])-arr[i];
			}
			else if(map.get(arr[i])<arr[i]){
				count+=map.get(arr[i]);
			}
			map.remove(arr[i]);
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 65156
n = int(input())
a = [0]*(n+1)
for i in range(1, n+1):
    a[i] = int(input())

index = 1
ret = 1
for i in range(n):
    next = a[index]
    if next == 2:
        print(ret)
        exit(0)
    if next == -1:
        break
    ret += 1
    a[index] = -1
    index = next

print(-1)

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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str() // int to string
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)
#define deb(x) cout << #x" = " << x << '\n'
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

int n, m, t[123456], ori[123456], p;

int sum() {
	int ret = 0;
	fr(i, 0, n) ret+= t[i];
	return ret;
}

int main() {
//    freopen("input.in", "r", stdin);
	scanf("%d", &n);
	fr(i, 0, n) scanf("%d", ori+i);
	scanf("%d", &m);
	fr(i, 0, m) {
		int ch;
		scanf("%d %d", &p, &ch);
		p--;
		fr(i, 0, n) t[i] = ori[i];
		t[p] = ch;
		printf("%d\n", sum());
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;                                                            
#define pb push_back                                                            
#define mp make_pair                                                                                                                                
#define sqr(a) ((a) * (a))                                                      
#define io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   
#define co() cout.precision(10);                                                
#define F for(li i=0;i<n;i++)
#define fo(i,a,n) for(i=a;i<n;i++)
#define ne cout<<"\n"; 
#define nec cout<<"\n";continue; 
#define test int t;cin>>t;while(t--)
#define first ff
#define second ss
//#define oj #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif

typedef long long li;
typedef long double ld;

const li mod = 1e9+7;

int main() 
{
    io();
    string s;
    cin>>s;
    li n=0,i;
    for(i=0;i<s.length();i++)
    {
    	li x=s[i]-'0';
    	n+=x;
	}
	if(n%9)
	cout<<"No";
	else
	cout<<"Yes";
}

Measured memory_bytes: 3700
from itertools import product

N = int(input())

count = 0
for i in range(2, len(str(N))):
  for p in set(product('753', repeat=i+1)):
    if int(''.join(p)) > N:
      continue
    if all(p.count(s) > 0 for s in '753'):
      count += 1

print(count)

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

int main(){
  int A, B, M;
  cin >> A >> B >> M;
  
  vector<int> a(A);
  vector<int> b(B);
  vector<vector<int>> m(M, vector<int>(3));
  for(int i = 0; i < A; i++){
    cin >> a[i];
  }
  for(int i = 0; i < B; i++){
    cin >> b[i];
  }
  for(int i = 0; i < M; i++){
    for(int j = 0; j < 3; j++){
      cin >> m[i][j];
    }
  }
  
  int min = 0;
  min += *min_element(a.begin(), a.end());
  min += *min_element(b.begin(), b.end());
  for(int i = 0; i < M; i++){
    int val = a[m[i][0]-1]+b[m[i][1]-1]-m[i][2];
    if(val < min)
      min = val;
  }
  
  cout << min;
  
  return 0;
}

Measured memory_bytes: 6528
#pragma GCC optimize("O3")
#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;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int n; cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    vector<vector<ll>> dp(n+1, vector<ll>(n+1, 0));

    for(int len=1; len<=n; len++){
        for(int i=0; i<n; i++){
            int l = i, r = i + len;
            if(n < r) continue;

            if((n - len) % 2 == 0){
                dp[l][r] = max(dp[l+1][r] + a[l], dp[l][r-1] + a[r-1]);
            }
            else{
                dp[l][r] = min(dp[l+1][r] - a[l], dp[l][r-1] - a[r-1]);
            }
        }
    }

    cout << dp[0][n] << endl;

    return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=(s);i<(t);++i)
#define per(i,s,t) for(int i=((t)-1);i>=s;--i)
#define repb(i,s,t) for(int i=(s);i<=(t);++i)
#define lepb(i,s,t) for(int i=(s);i>=(t);--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
#define mst(a,b) memset(a,b,sizeof(a))
#define dd(x) cout<<#x<<'='<<x<<' '
#define de(x) cout<<#x<<'='<<x<<'\n'
#define fi first
#define se second
#define sq(x) ((x)*(x))
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int inf = 0x3f3f3f3f;
const ll inff = 4557430888798830399ll;
const db eps = 1e-10;
const db pi = acos(-1.0);
const ll mod = 1e9+7;

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,x;vector<int> v[2];vector<pii> c[2];
	cin>>n;
	repb(i,1,n)
	{
		cin>>x;
		v[i&1].pb(x);
	}
	rep(i,0,2)
	{
		sort(all(v[i]));c[i].pb(mp(0,0));
		rep(j,0,sz(v[i]))
		{
			x=0;
			rep(k,j,sz(v[i]))if(v[i][j]==v[i][k])x+=1,j=k;
			c[i].pb(mp(x,v[i][j]));
		}
		sort(all(c[i]));reverse(all(c[i]));
	}
	if(c[0][0].se!=c[1][0].se)cout<<n-c[0][0].fi-c[1][0].fi<<endl;
	else cout<<n-max(c[0][1].fi+c[1][0].fi,c[0][0].fi+c[1][1].fi)<<endl;
}

Measured memory_bytes: 1784
n,m,x = map(int,input().split())
arr = [list(map(int,input().split())) for i in range(n)]
from itertools import combinations
alg = [0]*m
cost = 99999999
for i in range(1,n+1):
    for com in combinations(range(n),i):
        tmpcost = 0
        alg = [0]*m
        for num in com:
            c = arr[num][0]
            rikai = arr[num][1:]
            tmpcost += c
            alg  = [x + y for (x, y) in zip(alg, rikai)]
        if min(alg)>=x:
            cost = min(cost,tmpcost)

if cost == 99999999:
    print(-1)
else:
    print(cost)

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


int64_t combi(vector<int64_t> data){
    int64_t answer = 0;

    answer = data.at(0)*data.at(1)*data.at(2) +
                data.at(0)*data.at(1)*data.at(3) +
                data.at(0)*data.at(1)*data.at(4) +
                data.at(0)*data.at(2)*data.at(3) +
                data.at(0)*data.at(2)*data.at(4) +
                data.at(0)*data.at(3)*data.at(4) +
                data.at(1)*data.at(2)*data.at(3) +
                data.at(1)*data.at(2)*data.at(4) +
                data.at(1)*data.at(3)*data.at(4) +
                data.at(2)*data.at(3)*data.at(4);

    return answer;
}


int main(){

    int n;
    cin >> n;

    vector<int64_t> data(5, 0);

    for (int i = 0; i<n; i++){
        string a;
        cin >> a;

        if (a.at(0) == 'M'){
            data.at(0)++;
        }else if (a.at(0) == 'A'){
            data.at(1)++;
        }else if (a.at(0) == 'R'){
            data.at(2)++;
        }else if (a.at(0) == 'C'){
            data.at(3)++;
        }else if (a.at(0) == 'H'){
            data.at(4)++;
        }
    }

    int64_t ans = combi(data);

    cout << ans << endl;

}

Measured memory_bytes: 3640
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

// ??????????????§??°
#define MAX_V 10000

class edge {
public:
  int from, to, cost;
  edge(int from = 0, int to = 0, int cost = 0): from(from), to(to), cost(cost) {}
  bool operator < (const edge &e) const {
    return e.cost < cost;
  }
};

int V;
vector <edge> graph[MAX_V];

// ??????????????§????°???¨?????¨????±???????
// O(|E|log|E|)
int prim() {
  bool used[MAX_V];
  memset(used, false, sizeof(used));
  int ret = 0;
  int cnt = 0;

  priority_queue<edge> pque;
  for (int i = 0; i < graph[0].size(); i++) {
    // ??????0????????????????????????????????????????????\????????????
    pque.push(graph[0][i]);
  }
  cnt++;
  used[0] = true;
  while (true) {
    // ??¢????¨????????????????????????????????????????
    while (!pque.empty() && used[pque.top().to]) pque.pop();
    if (pque.empty()) break;

    int p = pque.top().to;
    cnt++;
    used[p] = true;
    ret += pque.top().cost;
    pque.pop();
    if (cnt >= V) break;
    // ??????p???????¨??????????????????????????????????????????????????????\????????????
    for (int i = 0; i < graph[p].size(); i++) {
      edge e = graph[p][i];
      if (used[e.to]) continue;
      pque.push(e);
    }
  }

  return ret;
}

int main() {
  int E;
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int s, t, w;
    cin >> s >> t >> w;
    graph[s].push_back(edge(s, t, w));
    graph[t].push_back(edge(t, s, w));
  }
  cout << prim() << endl;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()
int main(){
  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N));
  for(int i = 0; i < 2; i++){
   for(int j = 0; j < N; j++){
    cin >> A.at(i).at(j);
   }
  }

  //累積和
  vector<int> A0(N);
  vector<int> A1(N);
  for(int i = 0; i < N; i++){
   if(i == 0){
     A0.at(i) = A.at(0).at(i);
     A1.at(i) = A.at(1).at(i);
   }
   else{
     A0.at(i) = A0.at(i-1) + A.at(0).at(i);
     A1.at(i) = A1.at(i-1) + A.at(1).at(i);
   }
  }

  int result = 0;
  for(int i = 0; i < N; i++){
   //i列目で下に降りた場合
   int counter;
   if(i == 0){
     counter = A0.at(i) + A1.at(N-1);
   }
   else{
       counter = A0.at(i) + A1.at(N-1) - A1.at(i - 1);
   }
   if(counter > result) result = counter;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int n, x, t; 

int main()
{
	cin >> n >> x >> t; 
	if(n % x == 0)
    {
    	cout << t * (n / x) << endl; 
    }
	else
    {
    	cout << t * (n / x + 1) << endl; 
    }
	return 0; 
}

Measured memory_bytes: 3632
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    int H, W;
    cin >> H >> W;

    int c[10][10];
    FOR(i, 0, 10){
        FOR(j, 0, 10){
            cin >> c[i][j];
        }
    }

    FOR(i, 0, 10){
        FOR(j, 0, 10){
            FOR(k, 0, 10){
                // i -> j -> k
                c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
            }
        }
    }

    ll cost = 0;
    FOR(i, 0, H){
        FOR(j, 0, W){
            int a;
            cin >> a;
            if(a!=-1){
                cost += c[a][1];
            }
        }
    }

    p(cost);
    
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)

sum = 0
n.times do |i|
  next if i == 0
  if a[i] < a[i-1]
    sum += a[i-1] - a[i] 
    a[i] = a[i-1]
  end
end

puts sum

Measured memory_bytes: 28140
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

#define EPS 1e-7

int main(){
	int e;
	while(scanf("%d", &e), e != 0){
		int ans = e;
		int k;
		for(int z = 0; (k = e - z * z * z) >= 0; ++z){
			int y = (int)(sqrt(k) + EPS);
			int x = k - y * y;
			ans = min(ans, x + y + z);
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1028
import sys
input = sys.stdin.readline
N = int(input())
CSF = [list(map(int,input().split())) for i in range(N-1)]

ans = [0 for _ in range(N)]

for i in range(N-1) :
    temp = CSF[i][1] + CSF[i][0]
    t = i + 1
    while t < N-1 :
        if temp < CSF[t][1] :
            temp = CSF[t][1] + CSF[t][0]
        else :
            temp = ((temp+CSF[t][2]-1)//CSF[t][2])*CSF[t][2] + CSF[t][0]
        t += 1
    ans[i] = temp

for answer in ans :
    print(answer)


Measured memory_bytes: 3188
#include <iostream>

int main(){
  int n, m, i;
  std::cin >> n >> m;
  i = n;
  while(m % i != 0){
    if(i > m / 2) {
      i = m;
      break;
    }
    i++;
  }
  std::cout << m / i << std::endl;
}

Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/



int main() {
ll N;
cin>>N;
if(N%2==0){
    cout<<N/2-1<<endl;
}
else{
    cout<<N/2<<endl;
}


return 0;
}






Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;

#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define ll      long long

void solve() {
        int n;
        cin >> n;
        vector<int> p(n);
        for (int i = 0; i < n; i ++) cin >> p[i];
        int ans = 0;
        for (int i = 0; i < n; i ++) {
                if (p[i] == i + 1) { 
                        swap(p[i], p[i + 1]);
                        ans ++;
                }
        }
        cout << ans << endl;
}

int main() {
        int T;
        //freopen("a.in", "r", stdin);
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        //cin >> T;
        T = 1;
        while (T --) solve();
        return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pil pair<int,along long>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define pb push_back
#define mk make_pair
#define eps 1e-12
#define maxn 100009
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	ll ans=0;
	for(int mask=0;mask<(1<<(n-1));mask++)
	{
		string w;
		for(int i=0;i<n-1;i++)
		{
			if(mask&(1<<i))
			{
				w.insert(w.begin(),s[n-i-1]);
				ll x=atoll(&w[0]);
				ans=ans+x;
				w.clear();
			}
			else
			{
				w.insert(w.begin(),s[n-i-1]);
			}
		}
		w.insert(w.begin(),s[0]);
		ll x=atoll(&w[0]);
		ans=ans+x;
	}
	cout<<ans<<"\n";
}

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

namespace Indexed_0 {
  inline int Left(int x)    { return (x << 1) + 1; }
  inline int Right(int x)   { return (x << 1) + 2; }
  inline int Parent(int x)  { return (x - 1) >> 1; }
  inline int Brother(int x) { return ((x - 1) ^ 0x01) + 1; }
  const int RootId = 0;
};
namespace Indexed_1 {
  inline int Left(int x)    { return (x << 1); }
  inline int Right(int x)   { return (x << 1) + 1; }
  inline int Parent(int x)  { return (x >> 1); }
  inline int Brother(int x) { return x ^ 0x01; }
  const int RootId = 1;
};
using namespace Indexed_0;
//using namespace Indexed_1;

namespace MinMaxIndex {
  template<typename T, std::size_t N>
  inline int MaxIndex(T (&ps)[N], int x, int y) {
    return ps[x] < ps[y] ? y : x;
  }
  template<typename T, std::size_t N>
  inline int MinIndex(T (&ps)[N], int x, int y) {
    return ps[x] < ps[y] ? x : y;
  }
};
using namespace MinMaxIndex;

namespace Heap {
  template<typename T, std::size_t N>
  void MaxHeapify_S1(T (&ps)[N], int n, int x) {
    int left = Left(x);
    int right = Right(x);
    int i = x;
    if( left - RootId < n ) {
      i = MaxIndex(ps, i, left);
    }
    if( right - RootId < n ) {
      i = MaxIndex(ps, i, right);
    }
    if( i != x ) {
      std::swap(ps[i], ps[x]);
      MaxHeapify_S1(ps, n, i);
    }
  }
  template<typename T, std::size_t N>
  void MaxHeapify(T (&ps)[N], int n) {
    assert( n <= (int)N );
    for(int i = n / 2; i >= 0; --i) {
      MaxHeapify_S1(ps, n, i);
    }
  }
};
using namespace Heap;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_B
void Verify_1() {
  static_assert( RootId == 0 , "not 0-Indexed");
  int xs[512345];
  int n;
  scanf("%d", &n);
  for(int i = 0; i < n; ++i) {
    scanf("%d", &xs[i]);
  }
  MaxHeapify(xs, n);
  for(int i = 0; i < n; ++i) {
    printf(" %d", xs[i]);
  }
  puts("");
}

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

Measured memory_bytes: 5036
Exp = ["+", "-", "*"]
def solve(num)
  num.permutation(4).each do |a, c, e, g| 
    Exp.repeated_permutation(3).each do |b, d, f|
      ks = "("; ke = ")"
      [ks + a + b + c + ke + d + ks + e + f + g + ke,
       ks + a + b + ks + c + d + e + ke + ke + f + g,
       a + b + ks + ks + c + d + e + ke + f + g + ke,
       ks + ks + a + b + c + ke + d + e + ke + f + g,
       a + b + ks + c + d + ks + e + f + g + ke + ke].each do |form|
         return form if eval(form) == 10
      end
    end
  end
  nil
end
loop do
  num = gets.split
  break if num[0] == "0"
  res = solve(num)
  puts res ? res : 0
end

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

#define vt          vector
#define sz(x)       int((x).size())
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

using ll = long long;
using pii = pair<int, int>;

void solve() {
    int a, b;
    cin >> a >> b;
    cout << 6 - a - b;
}

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

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) {
        // cout << "Case " << tc << ": ";
        solve();
    }
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    string t("2018"),s;
    
    rep(i,10){
        char c; cin >> c;
        if(i>=0 && i<=3){
            cout << t[i];
        }else{
            cout << c;
        }
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a,inc=(b-a)/abs(b-a); i!=b ; i+=inc)
#define scan(arr,n) for(int i=0;i<n;i++) cin>>arr[i]
#define deb(x) cout<<#x<<"->"<<x<<endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#define print(arr,a,b) for(int i=a;i!=b;i++){cout<<arr[i]<<" ";}cout<<endl;
using ll=long long int;
int arr_min(int arr[],int a,int b){ int min=arr[0]; for(int i=a;i!=b;i++){if(min>arr[i]) min=arr[i];}return min;}
int arr_max(int arr[],int a,int b){ int max=arr[0]; for(int i=a;i!=b;i++){if(max<arr[i]) max=arr[i];}return max;}

signed main()
{
	ios_base::sync_with_stdio(false);   
    cin.tie(NULL);

	#ifndef ONLINE_JUDGE
      	freopen("input.txt", "r", stdin);
      	freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    while(t-->0){
    	int n,m;
    	cin>>n>>m;
    	int arr[n+1];
    	for(int i=1;i<=n;i++)
    		cin>>arr[i];
    	vector<pair<ll,ll> > v;
    	
    	bool flag[n+1];
    	for(int i=0;i<=n;i++)
    		flag[i]=true;
    	for(int i=0;i<m;i++)
    	{
    		ll a,b;
    		cin>>a>>b;
    		if(arr[a]<=arr[b])
    		{
    			
    			flag[a]=false;
                    			
    		}
    		if(arr[a]>=arr[b])
    			flag[b]=false;

    		

    	}
    	int count=0;
    	// print(flag,1,n+1);
    	for(int i=1;i<=n;i++)
    	{
    		if(flag[i]==true)
    			count++;
    	}


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

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

typedef long long ll;

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

    ll *A = new ll [N];
    for(int i=0; i<N; i++)
    {
        cin >> A[i];
    }

    ll max_d = A[0] + K - A[N-1];

    for(int i=0; i<N; i++)
    {
        ll d = A[i] - A[i-1];
        if(d > max_d)
        {
            max_d = d;
        }
    }

    cout << K - max_d << endl;

    return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>

int main(void){
    int tmp,q,minq=10,sum=0,count=0;
    for(int i=0;i<5;i++){
        scanf("%d",&tmp);
        q = tmp%10;
        sum += tmp - q;
        if(q){
            count++;
            if(q<minq)minq=q;
        }
    }
    if(minq==10)printf("%d\n",sum);
    else printf("%d\n",sum+10*(count-1)+minq);
    return 0;
}
	

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)  # 大きい順にそーと
B = []  # 輪
cnt = 0
for a in A:
    if len(B) != 0:
        j = len(B) // 2
        cnt += B[j]
    B.append(a)
print(cnt)

Measured memory_bytes: 31752
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll  long long int
#define INF 10000000000000000LL
#define pll pair<long long , long long>
const int MAX=1e7;
const ll MOD=998244353;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
ll inv(ll a, ll b){
	ll res=1;
	while(b){
		if(b%2)
			res=(res*a)%MOD;
		b=b/2;
		a=(a*a)%MOD;
	}
	return res;
}
int main() 
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    cout.tie(0);
    int n,s;
    cin>>n>>s;
    ll dp[n+1][s+1];
    ll arr[n+1];
    for(int i=1;i<=n;i++)
    	cin>>arr[i];
    memset(dp,0,sizeof(dp));
   dp[0][0]=inv((ll)2, (ll)(n));
   for(int i=1;i<=n;i++){
   	for(int j=0;j<=s;j++){
   		dp[i][j]+=dp[i-1][j];
   		if(j+arr[i]<=s)
   			dp[i][j+arr[i]]+=(dp[i-1][j])*inv((ll)(2),MOD-2);
   		dp[i][j]%=MOD;
   	}
   }
   cout<<dp[n][s];
}

Measured memory_bytes: 74048
#include<stdio.h>

#define MAX 2001
#define W 0
#define G 1
#define B 2

int n, M[MAX][MAX];

int prim(void){
  int i,v, u, minv,sum=0;
  int d[MAX],p[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i] = MAX;
    p[i] = -1;
    color[i] = W;
  }

  d[0] = 0;

  while(1){
    minv = MAX;
    u = -1;
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=B){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=B;
    sum += d[u];

      
    for(v=0;v<n;v++){
      if(color[v]!=B&&M[u][v]<d[v]&&M[u][v]>-1){
	p[v]=u;
	d[v]=M[u][v];
      }
    }
  }
  return sum;
}

int main(){
  int i,j,e;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&M[i][j]);
    }
  }

  e = prim();

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

  return 0;
}



Measured memory_bytes: 2128
use std::cmp::max;
use proconio::input;


fn main() {
    input! {
        n: usize,
        m: i64,
        q: i64,
        data: [(usize, usize, i64, i64); q],
    }

    println!("{:?}", dfs(n, m, &mut vec![], &data));
}

fn dfs(n: usize, m: i64, cur: &mut Vec<i64>, data: &Vec<(usize, usize, i64, i64)>) -> i64 {
    if cur.len() >= n {
        return points(cur, data)
    }

    let mut res = 0;
    match cur.last() {
        Some(l) => {
            for v in *l..=m {
                cur.push(v);
                res = max(res, dfs(n, m, cur, &data));
                cur.pop();
            }
        },
        None => res = max(res, dfs(n, m, &mut vec![1], &data)),
    }

    res
}


fn points(seq: &Vec<i64>, data: &Vec<(usize, usize, i64, i64)>) -> i64 {
    let mut res = 0;
    for (a, b, c, d) in data.iter() {
        if seq[b - 1] - seq[a - 1] == *c {
            res += d;
        }
    }

    res
}


Measured memory_bytes: 2200
s = str(input())
k = int(input())
if len(set(s)) == 1 and "1" in s:
    print(1)
elif s.count("1") > k:
    print(1)
else:
    for i in range(len(s)):
        if s[i] != "1":
            print(s[i])
            break

Measured memory_bytes: 3064
#include "bits/stdc++.h"

class LazySegmentTree
{
    int n;
    using T1 = int;
    using T2 = int;
    T1 id1 = INT_MAX;
    T2 id2 = -1;
    std::vector<T1> node; // min
    std::vector<T2> lazy; // update

    // 遅延評価
    void eval(int k, int l, int r)
    {
        // 遅延配列が空なら終了
        if (lazy[k] == id2)
            return;
        // 遅延配列を適用
        node[k] = lazy[k];
        if (r - l > 1)
        {
            lazy[2 * k + 1] = lazy[k];
            lazy[2 * k + 2] = lazy[k];
        }
        // 遅延配列初期化
        lazy[k] = id2;
    }

  public:
    LazySegmentTree(int _n)
    {
        int sz = _n;
        n = 1;
        while (n < sz)
            n *= 2;
        // 配列初期化
        node.resize(2 * n - 1, id1);
        lazy.resize(2 * n - 1, id2);
    }
    // 半開区間 [a, b) に対して値 val を反映させる
    void update(int a, int b, T2 val, int l = 0, int r = -1, int k = 0)
    {
        if (r < 0)
            r = n;
        // ノード k で遅延評価
        eval(k, l, r);
        if (b <= l || r <= a)
            return;
        // 区間が被覆されている場合
        if (a <= l && r <= b)
        {
            // 遅延配列更新, 評価
            lazy[k] = val;
            eval(k, l, r);
        }
        else
        {
            // 子ノードの値を評価し, 更新
            int mid = (l + r) / 2;
            update(a, b, val, l, mid, 2 * k + 1);
            update(a, b, val, mid, r, 2 * k + 2);
            node[k] = std::min(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    // 半開区間 [a, b) に対してクエリを投げる
    T1 query(int a, int b, int l = 0, int r = -1, int k = 0)
    {
        if (r < 0)
            r = n;
        eval(k, l, r);
        // 範囲外なら単位元返す
        if (b <= l || r <= a)
            return id1;
        if (a <= l && r <= b)
            return node[k];
        int mid = (l + r) / 2;
        T1 vl = query(a, b, l, mid, 2 * k + 1);
        T1 vr = query(a, b, mid, r, 2 * k + 2);
        return std::min(vl, vr);
    }
};

using namespace std;

void solve_dsl_2_f()
{
    int n, q;
    cin >> n >> q;
    LazySegmentTree lst(n);
    while (q--)
    {
        int type;
        cin >> type;
        if (type == 0)
        {
            int s, t, x;
            cin >> s >> t >> x;
            t++;
            lst.update(s, t, x);
        }
        else
        {
            int s, t;
            cin >> s >> t;
            t++;
            cout << lst.query(s, t) << endl;
        }
    }
}

int main()
{
    solve_dsl_2_f();
}



Measured memory_bytes: 4960
a, b = map(int, input().split())
win = ""

if a < b:
    win = "Bob"
elif b < a:
    win = "Alice"
if a == 1 or b == 1:
    if a < b:
        win = "Alice"
    elif b < a:
        win = "Bob"
if a == b:
    win = "Draw"

print(win)

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

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int[] arr = {a,b,c};
        Arrays.sort(arr);
        if ((arr[0]+arr[1])==arr[2]) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35660
#include<bits/stdc++.h>
using namespace std;
const int MAX = 2e5 ;
const int INF = 1e9 + 1e5 + 2;
const int mod= 1e9+7;
using namespace std;
bool cmp(const pair<int,int> &a,
               const pair<int,int> &b)
{
       if (a.first==b.first)
           return (a.second >b.second);
       return (a.first<b.first);
}
int main()
{
    string s,t;

    cin>>s;

    t=s;

    reverse(t.begin(),t.end());

    if (t!=s)
    {
        cout<<"No";
        return 0;
    }

    int n=s.size();

    string x;

    for (int i=0; i<(n-1)/2; ++i)
        x+=s[i];
    string y=x;

    reverse(y.begin(),y.end());

    if (x!=y)
    {
        cout<<"No";
        return 0;
    }

    x="",y="";

    for (int i=(n+3)/2-1; i<n; ++i)
        x+=s[i];

    y=x;

    reverse(y.begin(),y.end());

    if (x!=y)
    {
        cout<<"No";
        return 0;
    }
    cout<<"Yes";












}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

signed main() {
    
    char a, b;
    cin >> a >> b;
    
    if(a=='H' && b=='H' || a=='D' && b=='D') cout << "H" << endl;
       else cout << "D" << endl;
    
    return 0;
}


Measured memory_bytes: 256
def comb(n, r):
    if n < r:
        return 0

    ret = 1
    for i in range(1, r + 1):
        ret = ret * (n - i + 1) // i

    return ret


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

v.sort(reverse=True)
ave = sum(v[:a]) / a

if v[0] == v[a-1]:
    sm = v.count(v[0])
    cnt = 0
    for i in range(a, b + 1):
        cnt += comb(sm, i)

else:
    last = v[a-1]
    select = v[:a].count(last)
    sm = v.count(last)
    cnt = comb(sm, select)

print(ave)
print(cnt)


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

int main(void)
{
	int n, s;
	while (cin >> n, n){
		cin >> s;
		int ma, mi, sum;
		ma = mi = sum = s;
		
		for (int i = 1; i < n; i++){
			cin >> s;
			ma = max(s, ma);
			mi = min(s, mi);
			sum += s;
		}
		n -= 2;
		sum -= (ma + mi);
		
		int res = sum / n;
		
		cout << res << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 0
n=int(input());p=eval('list(map(int,input().split())),'*n);x,y,h=[x for x in p if x[2]][0]
for I in range(10201):j,i=I//101,I%101;H=h+abs(x-j)+abs(y-i);print(*(j,i,H)*all(max(H-abs(t[0]-j)-abs(t[1]-i),0)==t[2]for t in p))

Measured memory_bytes: 3928
dd = int(input())
c = list(list(map(int, input().split())))
s = [[0]*26]*dd
v = [[0]*26]*dd
vs = [[0]*26]*dd
ans = [0]*dd
for i in range(dd):
    s[i] = list(list(map(int, input().split())))



for i in range(26):
    for j in range(dd):
        v[j][i]=s[j][i]+c[i]*(j+1)

for i in range(dd):
    maxv = -100000
    for j in range(26):
        if maxv < v[i][j]:
            maxv = v[i][j]
            ans[i]=j+1
for a in ans:
    print(a)

Measured memory_bytes: 68176
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;

    ll res = 0;
    REP(i, 1, n + 1) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        res += i;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#include<algorithm>
int main()
{
	int n,l;
    cin>>n>>l;
    string s[n];
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
    }
    sort(s,s+n);
    for(int i=0;i<n;i++)
        cout<<s[i];
	return 0;
}

Measured memory_bytes: 3612
/*AOJ 0024*/

#include<iostream>
using namespace std;

int f(double v){
	double t = v/9.8;

	double y = 4.9 * t * t;

	int ans = (y / 5);

	if(y == (int)y){
		return ans+1;
	}
	else{
		return ans+2;
	}
}


int main(){

	double v;

	while(cin>>v){
		cout<<f(v)<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

template <typename T>
struct SegmentTree
{
    using F = function<T(T, T)>;
    
    const F f;
    const T e;
    
    int n;
    vector<T> seg;
    
    SegmentTree(int nn, const F f, const T e) : f(f), e(e){
        n = 1;
        while(n < nn) n <<= 1;
        seg.assign(n * 2, e);
    }
    
    void set(int i, T x){
        seg[i + n] = x;
    }
    
    void build(){
        for(int k = n - 1; k > 0; k--){
            seg[k] = f(seg[k * 2], seg[k * 2 + 1]);
        }
    }
    
    void update(int i, T x){
        int k = i + n;
        seg[k] = x;
        while(k >>= 1){
            seg[k] = f(seg[k * 2], seg[k * 2 + 1]);
        }
    }
    
    T query(int l, int r){
        l += n, r += n;
        T L = e, R = e;
        for(; l != r; l >>= 1, r >>= 1){
            if(l % 2) L = f(L, seg[l++]);
            if(r % 2) R = f(seg[--r], R);
        }
        return f(L, R);
    }
    
    T operator[](const int i)const {
        return seg[i + n];
    }
    
    template<typename C>
    int right_bound_sub(int k, const C &check, T x){
        while(k < n){
            if(check(f(x, seg[k * 2]))){
                k = k * 2;
            }
            else{
                x = f(x, seg[k * 2]);
                k = k * 2 + 1;
            }
        }
        return k - n;
    }
    
    template <typename C>
    int right_bound(int i, const C &check){
        T x = e;
        for(int l = i + n, r = n * 2; l != r; l >>= 1, r >>= 1){
            if(l % 2){
                if(check(f(x, seg[l]))){
                    return right_bound_sub(l, check, x);
                }
                x = f(x, seg[l]);
                l++;
            }
        }
        return -1;
    }
    
    template <typename C>
    int left_bound_sub(int k, const C &check, T x){
        while(k < n){
            if(check(f(seg[k * 2 + 1], x))){
                k = k * 2 + 1;
            }
            else{
                x = f(seg[k * 2 + 1], x);
                k = k * 2;
            }
        }
        return k - n;
    }
    
    template <typename C>
    int left_bound(int i, const C &check){
        T x = e;
        for(int l = n, r = i + n; l != r; l >>= 1, r >>= 1){
            if(r % 2){
                if(check(f(seg[--r], x))){
                    return left_bound_sub(r, check, x);
                }
                x = f(x, seg[r]);
            }
        }
        return -1;
    }
};

int main()
{
    int n, k;
    cin >> n >> k;
    int l[12], r[12];
    for(int i = 0; i < k; i++) cin >> l[i] >> r[i];
    SegmentTree<ll> seg(n, [](ll a, ll b){return (a + b) % MOD;}, 0ll);
    seg.update(0, 1);
    for(int i = 1; i < n; i++){
        for(int j = 0; j < k; j++){
            seg.update(i, (seg[i] + seg.query(max(0, i - r[j]), max(0, i - l[j] + 1))) % MOD);
        }
    }
    cout << seg[n - 1] << endl;
}


Measured memory_bytes: 7480
N = int(input())
line = list(map(int, input().split()))
n = N - 1
ans = 1
line.sort()
s = len(line)
index = s - 1
while(index > 1):
    if line[index] == n and line[index-1] == n:
        ans *= 2
        n = n - 2
        index = index - 2
    else:
        print(0)
        break

if index == 1:
    if line[index] == n and line[index-1] == n:
        ans *= 2
        print(ans % (10**9+7))
    else:
        print(0)

elif index == 0:
    if line[0] == 0:
        print(ans % (10**9+7))
    else:
        print(0)


Measured memory_bytes: 14008
#include<stdio.h>
#include<math.h>
int main()
{
    int n,a,k,i,count=0;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&a);
        k=sqrt(a);
        for(i=2;i<=k;i++)
        {
            if(a%i==0)
                break;
        }
        if(i>=k+1)
            count++;
    }
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 2080
a,b,k=map(int,input().split())
flag=True
for i in range(k):
    if(flag and a%2==1):
        a-=1
        b+=(a//2)
        a//=2
        flag=not flag
        continue
    elif(flag):
        flag=not flag
        b+=(a//2)
        a-=(a//2)
        continue
    if(not flag and b%2==1):
        b-=1
        a+=(b//2)
        b//=2
        flag=not flag
        continue
    elif(not flag):
        a+=(b//2)
        b-=(b//2)
        flag=not flag
print(a,b)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    
    long long n, x;
    cin >> n;
    vector<long long> seg(n+1, 0);
    
    for(int i = 0; i < n; i++){
        cin >> x;
        long long sum = 0;
        for(int j = x-1; j > 0; j = j & (j-1)){
            if(seg[j] > sum)
                sum = seg[j];
        }
        for(int j = x; j < n + 1; j += (j & -j)){
            if(sum + x > seg[j]){
                seg[j] = sum + x;
            }
        }
    }
    
    long long ans = 0;
    for(int j = n; j > 0; j = j & (j-1)){
        if(seg[j] > ans)
            ans = seg[j];
    }
    cout << (n*(n+1))/2 - ans <<endl;
    
}

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

int main()
{
    int h,n,x;
    cin>>h>>n;
    long long int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        sum+=x;
    }
    if(sum>=h)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}



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

int main() {
  int n, m, x, y, temp;
  bool found = false;
  vector<int> xv, yv;
  cin >> n >> m >> x >> y;
  for (int i=0; i<n; i++) {
    cin >> temp;
    xv.push_back(temp);
  }
  for (int i=0; i<m; i++) {
    cin >> temp;
    yv.push_back(temp);
  }
  for (int i=x+1; i<=y; i++) {
    if (*max_element(xv.begin(), xv.end())<i && *min_element(yv.begin(), yv.end())>=i) found = true;
    if (found) break;
  }
  if (found) cout << "No War";
  else cout << "War";
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

vector<vector<int>> ch;
vector<int> ans;

void solve(int i) {
    vector<int> nxt;
    for (int j : ch[i]) {
        solve(j);
        nxt.eb(ans[j]);
    }
    sort(all(nxt));
    reverse(all(nxt));
    int rez = 0;
    forn(j, 0, nxt.size()) {
        rez = max(rez, 1 + j + nxt[j]);
    }
    ans[i] = rez;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    forn(i, 1, n) cin >> a[i];
    ch.resize(n);
    forn(i, 1, n) ch[a[i] - 1].eb(i);
    ans.resize(n);
    solve(0);
    cout << ans[0] << '\n';
}


Measured memory_bytes: 14336
import java.util.Scanner;

public class Main{

	  //given n times, and R, an array of currencies
	  public static int compute_maxprofit(int n, int[] R){
		  int max_profit = -999999999;
		  for(int i = 0; i < n-1; i++){
			  for(int j = i+1; j < n; j++){
					if(R[j] - R[i] > max_profit)
						max_profit = R[j] - R[i];
				  	}
		  }
		  return max_profit;
	  }
	  
	  public static int compute_maxprofitDP(int n, int[] R){
		  int max_profit = -999999999;
		  int minElement = R[0];
		  for(int i = 1; i < n; i++){
			  max_profit = max(R[i]-minElement, max_profit);
			  if(R[i] < minElement)
				  minElement = R[i];
		  }
		  return max_profit;
	  }
	  
	  public static int max(int a, int b){
			return (a>=b) ? a : b;
		}
	  
	  public static void main(String[] argv) {
			Scanner in = new Scanner(System.in);
			int num = in.nextInt();
			int[] R = new int[num];
			for(int i=0; i<num; i++)
			{
				R[i] = in.nextInt();
			}
			System.out.println(compute_maxprofitDP(num, R));
			in.close();
	  }
}



Measured memory_bytes: 100980
function main()
lines=readlines()
N,M=map(x->parse(Int,x),split(shift!(lines)))
A=[Array{Pair{Int,Int}}(0) for _=1:N]
P=Array{Int}(0)
for i=1:M
	p,y=map(x->parse(Int,x),split(shift!(lines)))
	push!(A[p],y=>i)
	push!(P,p)
end
ans=Array{Int}(M)
for i=1:N
	sort!(A[i])
	for j=1:length(A[i])
		ans[A[i][j].second]=j
	end
end
function f(x)
	s=Array{Char}(0)
	while x>0
		push!(s,Char(x%10+48))
		x=div(x,10)
	end
	while length(s)<6
		push!(s,'0')
	end
	reverse!(s)
	for c=s
		print(c)
	end
end
for i=1:M
	f(P[i])
	f(ans[i])
	println()
end
end
main()


Measured memory_bytes: 169208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
// const ll MOD=1000000007ll;
static const ll MOD=1e9 + 7;
static const int MAX=510000;
const int MAX_N = 5e5 + 10;


ll fact[MAX], fact_inv[MAX];

//繰り返し二乗法
ll power(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

ll comb(ll n, ll r){
    return (fact[n] * fact_inv[r]) % MOD * fact_inv[n-r] % MOD;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}//mod mでの逆元aを計算

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    fact[0] = 1;
    //階乗計算(O(n))
    for(int i = 0; i < MAX_N; i++) fact[i+1] = fact[i] * (i+1)%MOD;
    fact_inv[MAX_N] = power(fact[MAX_N], MOD - 2);
    //逆元計算(O(logp + n))
    for(int i = MAX_N - 1; i >= 0; i--) fact_inv[i] = fact_inv[i+1]%MOD*(i+1)%MOD;
    //あとはcomb(n,r)に値を突っ込めば良い
    int n, k; cin >> n >> k;
    ll ans = 0;
    if(k >= n - 1)cout << comb(2 * n - 1, n) << endl; 
    else{
        if(k == 1){
            ans += comb(n - 1, n - 1 - 1) * comb(n, 1);
            ans %= MOD;
        }else{
        for(int i = 0; i <= k; i++){
            ans += comb(n - 1, n - i - 1) * comb(n, i);
            ans %= MOD;
        }
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 8192
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,i;
	f=-1;
	g=0;
	scanf("%d",&a);
	for(i=1;i<=a;i++){
		scanf("%d %d",&s,&d);
		if(f==d){
			if(g>s){
				g=s;
			}
		}
		else if(f<d){
			f=d;
			g=s;
		}
	}
	printf("%d %d\n",g,f);
	return 0;
}

Measured memory_bytes: 1028
def f(n):
	if n % 2 == 0:
		return n / 2
	else:
		return 3 * n + 1
		
s = int(input())

a = []
for i in range(1000000):
	if i == 0:
		a.append(s)
	else:
		if f(a[-1]) in a:
			print(i+1)
			break
		else:
			a.append(f(a[-1]))

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

int main() {
  int N;
  cin >> N;
  int64_t L = 1, M = 2;
  for (int i = 1; i < N; ++i) {
    L = L + M;
    M = L - M;
  }
  cout << L << endl;
  return 0;
}


Measured memory_bytes: 256