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

int main(){
  int x;
  cin>>x;
  int ans=0;
  ans += floor(x/500)*1000;
  ans += floor((x%500)/5)*5;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
void main() {
    auto N = ri;
    auto a = readAs!(int[]).map!(v => v-1).array;
    int[int] m;
    foreach(int i, v; a) {
        m[i] = v;
    }
    ulong res;
    foreach(i; 0..N) {
        if(m[m[i]] == i) res++;
    }
    res /= 2;
    res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

long rl() {
	return readAs!long;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 10300
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=4e3+5;
const int mod=1e9+7;
ll n,f[3][maxn],ans[3][maxn],sum;
string s;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            f[0][i]=1;
            ans[0][i]=ans[0][i-1]+1;
        }
        else ans[0][i]=ans[0][i-1];
        if(s[i]=='G'){
            f[1][i]=1;
            ans[1][i]=ans[1][i-1]+1;
        }
        else ans[1][i]=ans[1][i-1];
        if(s[i]=='B'){
            f[2][i]=1;
            ans[2][i]=ans[2][i-1]+1;
        }
        else ans[2][i]=ans[2][i-1];
    }
    for(int i=1;i<n;i++){
        if(s[i]=='R'){
            sum=sum+ans[1][i-1]*(ans[2][n-1]-ans[2][i]);
            sum=sum+ans[2][i-1]*(ans[1][n-1]-ans[1][i]);
            for(int j=i-1,k=i+1;j>=0 && k<n ;j--,k++)
                if((f[1][j] && f[2][k]) || (f[2][j] && f[1][k])) sum--;
        }
        else if(s[i]=='G'){
            sum=sum+ans[0][i-1]*(ans[2][n-1]-ans[2][i]);
            sum=sum+ans[2][i-1]*(ans[0][n-1]-ans[0][i]);
            for(int j=i-1,k=i+1;j>=0 && k<n ;j--,k++)
                if((f[0][j] && f[2][k]) || (f[2][j] && f[0][k])) sum--;
        }
        else{
            sum=sum+ans[1][i-1]*(ans[0][n-1]-ans[0][i]);
            sum=sum+ans[0][i-1]*(ans[1][n-1]-ans[1][i]);
            for(int j=i-1,k=i+1;j>=0 && k<n ;j--,k++)
                if((f[1][j] && f[0][k]) || (f[0][j] && f[1][k])) sum--;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3736
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	
    int x = sc.nextInt();
    
    int ans = 0;
    
    ans = x/500*1000;
    x = x%500;
    ans += x/5*5;
    System.out.println(ans);

  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    while (1) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        vector<ll> c(m), x(n);
        rep(i, m) cin >> c[i];
        rep(i, n) cin >> x[i];

        auto dp = make_vec<ll>(n + 10, 256);
        rep(i, n + 10) rep(j, 256) dp[i][j] = LINF;
        dp[0][128] = 0;
        rep(i, n) {
            rep(j, 256) {
                rep(k, m) {
                    int nxt = min(255ll, max(0ll, j + c[k]));
                    chmin(dp[i + 1][nxt],
                          dp[i][j] + (x[i] - nxt) * (x[i] - nxt));
                }
            }
        }
        ll ans = LINF;
        rep(j, 256) chmin(ans, dp[n][j]);
        cout << ans << endl;
    }
}


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

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  multiset<int> st;
  st.insert(-1);
  st.insert(1e9 + 7);

  int ans = 0;
  for (int i = 0; i < N; i++) {
    auto temp = st.lower_bound(A[i]);
    temp--;
    if (*temp != -1) {
      st.insert(A[i]);
      st.erase(temp);
    } else {
      ans++;
      st.insert(A[i]);
    }
  }

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

Measured memory_bytes: 5760
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int[] integerDigits(int n) {
    if (n == 0) return [0];
    return text(abs(n)).map!(e => cast(int)(e - '0')).array;
}

int calc(int n, int[] d) {
    for (int i = n; ; i++) {
        if (integerDigits(i).sort().setIntersection(d).empty)
            return i;
    }
    assert(false);
}

void main() {
    int n, k; scan(n, k);
    auto d = readints;
    writeln(calc(n, d));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 1276
n,m,c = map(int, input().split())
b = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    a = [int(j) for j in input().split()]
    sum = c
    for j in range(m): sum += a[j]*b[j]
    if sum > 0: ans += 1
print(ans)


Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
n,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)

L=[list(map(int,input().split())) for i in range(q)]
ctL=[0]*n
for i in range(q):
  ctL[L[i][0]-1]+=L[i][1]

def bfs(v):
  distance=[-1]*n
  distance[v]=ctL[v]
  next=[v]
  next2=set()
  visited=[-1]*n
  visitct=0
  while len(next)!=0 and visitct!=n:
    for i in range(len(next)):
      if visited[next[i]]==-1:
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            distance[connection[next[i]][j]]=distance[next[i]]+ctL[connection[next[i]][j]]
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return distance

x=bfs(0)
for i in range(n):
  x[i]=str(x[i])
print(' '.join(x))

Measured memory_bytes: 150240
#include <stdio.h>
#include <string.h>

char s[100004];

int main(void){
	int i,n,len,rightFlg,foot[2];
	char before;
	scanf("%d",&n);

	while(n--){
		scanf("%s",s);

		len = strlen(s);
		foot[0] = -1;
		foot[1] = 1;
		rightFlg = 1;
		before = 0;

		for(i=0;i<len;i++){
			if(before == s[i]) break;

			switch(s[i]){
			case 'U':
			case 'D':
				foot[rightFlg] = 0;
				break;
			case 'R': break;
				foot[rightFlg] = 1;
			case 'L': break;
				foot[rightFlg] = -1;
			}

			if(foot[0] > foot[1]) break;

			before = s[i];
			rightFlg = !rightFlg;
		}

		printf("%s\n",i==len ? "Yes" : "No");
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n = 0;
    vector<vector<int> > num;
    string s;
    while(cin >> s){
        num.resize(n + 1);
        istringstream iss(s);
        for(;;){
            int a;
            iss >> a;
            num[n].push_back(a);
            char c;
            if(!(iss >> c))
                break;
        }
        ++ n;
    }

    vector<vector<int> > dp(n, vector<int>((n+1)/2, 0));
    dp[0][0] = num[0][0];
    for(int i=0; i<n/2; ++i){
        for(int j=0; j<=i; ++j){
            dp[i+1][j] = max(dp[i+1][j], dp[i][j] + num[i+1][j]);
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + num[i+1][j+1]);
        }
    }
    for(int i=n/2+1; i<n; ++i){
        for(int j=0; j<n-i; ++j){
            dp[i][j] = max(dp[i][j], dp[i-1][j] + num[i][j]);
            dp[i][j] = max(dp[i][j], dp[i-1][j+1] + num[i][j]);
        }
    }

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

    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

	int d,sum;
	while(scanf("%d",&d)!=EOF){
		sum = 0;
		for(int i=d;i<=600;i+=d){
			sum += d*(i-d)*(i-d);
		}
		printf("%d\n",sum);
	}

    return 0;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int D;
    cin >> D;
    string answer = "Christmas";
    for(int i = D; i < 25; i++)
    {
        answer += " Eve";
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
n, m, x, y = map(int, input().split())
x1 = list(map(int, input().split()))
y1 = list(map(int, input().split()))
x1.append(x)
y1.append(y)

if max(x1) < min(y1):
    print("No War")
else:
    print("War")        


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

ll MOD = 1e+9 + 7;

ll sum(ll a, ll b) {
    return (a + b) * (b - a + 1) / 2;
}

int main() {
    ll n, k, l, r, ans = 0;
    cin >> n >> k;

    for (ll i = k; i <= n + 1; i++) {
        l = sum(0, i - 1);
        r = sum(n - i + 1, n);
        ans += (r - l + 1) % MOD;
    }
    cout << ans % MOD << endl;

    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	static const int N=1<<19;
	ll dp[1<<20];
	ll lazy[1<<20]; 
	segtree(){
		memset(dp,0,sizeof(dp));
	}

	void lazy_eval(int k){
		dp[k]+=lazy[k];
		if(k<N-1){
			lazy[k*2+1]+=lazy[k];
			lazy[k*2+2]+=lazy[k];
		}
		lazy[k]=0;
	}

	void lazy_upd(int k){
		dp[k]=dp[k*2+1]+dp[k*2+2];
	}

	void update(int a,int b,ll v,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return;
		if(a<=l && r<=b){
			lazy[k]+=v;
			lazy_eval(k);
			return;
		}
		int mid=(l+r)/2;
		update(a,b,v,k*2+1,l,mid);
		update(a,b,v,k*2+2,mid,r);
		lazy_upd(k);
	}

	ll query(int a,int b,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		ll vl=query(a,b,k*2+1,l,mid);
		ll vr=query(a,b,k*2+2,mid,r);
		lazy_upd(k);
		return vl+vr;
	}
};

segtree seg;

int n;
int a[100005];
ll rest[100005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<=n;i++){
		scanf("%d",&a[i]);
	}
	if(n==0){
		printf("%d\n",(a[0]==1)?1:-1);
		return 0;
	}
	if(a[0]==1){
		printf("-1\n");
		return 0;
	}
	ll ans=1;
	ll cnt=0;
	seg.update(0,1,2);
	int cur=0;
	for(int i=1;i<=n;i++){
		//printf("%d %d %lld %lld\n",i,cur,seg.query(cur,cur+1),ans);
		while(seg.query(cur,cur+1)<a[i]){
			//printf("%d %d %lld %lld %lld\n",i,cur,seg.query(cur,cur+1),a[i],ans);
			ll val=seg.query(cur,cur+1);
			ans+=(ll)(i-cur)*val;
			a[i]-=val;
			seg.update(cur+1,i,val);
			cur++;
			if(cur==i){
				printf("-1\n");
				return 0;
			}
		}
		ans+=(ll)(i-cur)*a[i];
		seg.update(cur,cur+1,-a[i]);
		seg.update(cur+1,i,a[i]);
	}
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;

int main()
{
    string S;

    cin >> S;

    uint32_t len = S.length();
    uint32_t tmp = 0, ans = 0;

    for (size_t i = 0; i < len;++i)
    {
        if (S[i] == 'R')
            tmp++;
        else
            tmp = 0;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N;
map<int,int>mp;
signed main(){
	cin>>N;
	mp[0]=1;
	int sum=0,ans=0;
	rep(i,N){
		int A;cin>>A;
		sum+=A;
		ans+=mp[sum];
		mp[sum]++;
	}
	cout<<ans<<endl;
}


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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main() {
    int a, b; char op;
    cin >> a >> op >> b;
    cout << (op == '+' ? a + b : a - b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }
 
int main(){
    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 0; i <= m ; i++){
        for (int j = 0; j <= n; j++){
            int bl = i * (n - j) + j * (m - i);
            if(bl == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int len, types;
    cin >> len >> types;
    vector<int> arr(types);
    int sum = 0, big = 0;
    for(int i = 0; i < types; i++) {
        cin >> arr[i];
        sum += arr[i];
        big = max(arr[i], big);
    }
    if(types == 1) {
        cout << sum - 1;
        return 0;
    }
    sum -= big;
    if(sum < big - 1) {
        cout << big - 1 - sum;
    } else {
        cout << 0;
    }
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>

using namespace std;

// Returns 1 if the i-th bit of x is set, 0 otherwise.
#define BIT_SET(x, i) (((x) & (1<<(i))) != 0)
// Sets the i-th bit of x to 1
#define SET_BIT(x, i) ((x) | (1<<(i)))
// Sets the i-th bit of x to 0
#define UNSET_BIT(x, i) ((x) & ~(1<<(i)))
// Log a debug message
#ifdef DEBUG
#define LOG(e) (std::cout << (e) << std::endl)
#endif
#ifndef DEBUG
#define LOG(e)
#endif
// Log a collection
#define LOG_COLLECTION(c,i) for (int i=0; i<c.size(); i++) { LOG(c[i]); }
// Log an array
#define LOG_ARRAY(a,i,l) for (int i=0; i<l; i++) { LOG(a[i]); }

#define HOUR_SECONDS 3600
#define DAY_SECONDS (24*HOUR_SECONDS)

class Task {
    public:
        void solve(istream& in, ostream& out) {
        	int N, s, w, acc = 0;
        	in >> N;
        	vector<int> v(N);
        	for (int j = 0; j < N; j++) {
        		in >> s >> w;
				LOG(s); LOG(w);
        		v[j] = (acc + s) % DAY_SECONDS;
        		acc = (acc + s + w) % DAY_SECONDS;
        	}
            sort(v.begin(), v.end());
			LOG_COLLECTION(v,i);
        	int max = 0;
        	for (int t = 0; t < DAY_SECONDS; t++) {
				int crs = 0;
				for (int d = 0; ; d++) {
					vector<int>::iterator l = upper_bound(v.begin(), v.end(), 4*HOUR_SECONDS - 1 + d*DAY_SECONDS - t);
					vector<int>::iterator r = lower_bound(v.begin(), v.end(), 7*HOUR_SECONDS + 1 + d*DAY_SECONDS - t);
					crs += r-l;
					if (l == v.end())
						break;
				}
				if (crs > max)
                    max = crs;
        	}
        	out << max << endl;
        }
} task;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    task.solve(in, out);
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

  int main(){
    ll n;
    map<int,int> m;
    cin >> n;
    rep(i,n){
      int tmp;
      cin >> tmp;
      m[tmp]++;
    }
    int ans=0;
    for (auto q:m){
      if (q.first==q.second) continue;
      else if (q.second < q.first) ans+=q.second;
      else ans+=q.second-q.first;
    }
    cout << ans << endl; 
  }


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define INF 1000000000000000000
#define fn(i,n) for(int i=0;i<n;i+=1)
int h[100100];
int dp[100100]={0};
int fun(int n)
{
    if(n<1)return INF;
    if(dp[n]!=-1)
    return dp[n];
    int ans=min(fun(n-1)+abs(h[n]-h[n-1]),fun(n-2)+abs(h[n]-h[n-2]));
    dp[n]=ans;
    return dp[n];
}
signed main() {
    int n;cin>>n;
    for(int i=1;i<=n;i+=1){cin>>h[i];dp[i]=-1;}
    dp[1]=0;
    /*
    for(int i=1;i<=n;i+=1)
    {
        if(i>1)dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        if(i>2)dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }*/
    
    cout<<fun(n)<<endl;
    return 0;
}



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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int n, q;
    cin >> n >> q;
    string str;
    cin >> str;

    vector<int> s(n+1, 0);
    for (int i = 0; i < str.length(); ++i) {
        if (i+1 < n && str[i] == 'A' && str[i+1] == 'C') s[i+1] = s[i] + 1;
        else s[i+1] = s[i];
    }

    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        --l, --r;
        cout << s[r] - s[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+4;
const int mod = 1e9+7;
int a[N];
int dp[N];
int roll[N];
int n;
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	
	dp[0] = 1;
	roll[a[1]] = 1;
	for(int i=1;i<=n;i++)
	{

		dp[i] = roll[a[i]];
		
		if(a[i] != a[i+1])
			roll[a[i+1]] = (roll[a[i+1]] + dp[i]) % mod;
	}

	cout<<dp[n];
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n;
    cin >> n;
    v_int p(n);
    cin >> p;
    
    int ans = 0;
    irep2(i, 1, n-2) {
        if(p[i-1] < p[i] && p[i] < p[i+1]) {
            ans++;
        }
        if(p[i-1] > p[i] && p[i] > p[i+1]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
} /*atcoder*/



Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
  long long N,count=1;
  long long a[1000000];
  cin>>N;
  long long k,m;
  for (int i=0; i<N; i++){
  cin>>k;
  a[k]++;}
  m=a[0]+a[1]+a[2];
  for (int i=2; i<=100000; i++){
  if(a[i+1]-a[i-2]>0&&a[i-1]+a[i]+a[i+1]>=m){
  m=a[i-1]+a[i]+a[i+1];}}
  cout<<m<<endl;}


Measured memory_bytes: 2304
N = int(input())
# N = 86


def f(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    elif n == 2:
        return 3
    return 2 * f(n - 2) + f(n - 3)


def g(n):
    L = [0] * (n + 1)
    L[0] = 2
    L[1] = 1
    for i in range(2, n + 1):
        L[i] = L[i - 1] + L[i - 2]

    return L[-1]


print(g(N))


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

int main(){
    int y, m, d;
    char c1, c2;

    cin >> y >> c1 >> m >> c2 >> d;

    if (m<=4) {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }

    return 0;
}

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

int main(){
  int a, b, ans=0, count=0;
  cin >> a >> b;
  if(b==1) ans=0;
  else if(b/a==1 && b%a==0) ans=b/a;
  else{
    ans++;
    for(int i=1; ; i++){
      if(i<a){
        count++;
      }
      else if(i%a==1){
        ans++;
      }
      else{
        count++;
      }

      if(count==b) break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    long long n,x=0,max=0;
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='I'){
            x+=1;
        }
        else{
            x-=1;
        }
        if(max<x){
            max=x;
        }
    }
    cout<<max<<endl;
    return 0;
}


Measured memory_bytes: 3636
s = input()
t = input()

a=[]
b=[]

for i in range(len(s)):
  a.append(s[i])
  
for i in range(len(t)):
  b.append(t[i])
  

a.sort()
b.sort(reverse=True)

if a < b:
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;
char board[1010][1010];
int d[1010][1010];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int h,w;


int main(void){
    ll n,m,d;
    cin>>n>>m>>d;
    if(d==0){
        printf("%.9lf\n",(double)(m-1)/n);
    }
    else{
        printf("%.9lf\n",(double)2*(n-d)*(m-1)/(n*n));
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;
 
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)
 
typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;
 
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
 
int main() {
    int D; cin >> D;
    string ans = "Christmas";
    if (D>=22) {
        REP(i,25-D) {
            ans += " Eve";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
my ($n) = split(/\s+/, <>);

my $b=-int($n**0.2)-1;
for my $a (0..$n) {
    while (($a**5)-($b**5)>$n) {
	$b++;
    }
    if (($a**5)-($b**5)==$n) {
	print $a, " ", $b, "\n";
	exit;
    }
}


Measured memory_bytes: 5120
from functools import reduce

N = int(input())

strings = []

for _ in range(N):
    s = input()
    strings.append(reduce(lambda a, b: a + b, sorted(s)))

strings = sorted(strings)

ans = 0
counter = 1
for i in range(N - 1):
    if strings[i] == strings[i + 1]:
        counter += 1
    else:
        ans += counter * (counter - 1) / 2
        counter = 1

ans += counter * (counter - 1) / 2
        
print(int(ans))

Measured memory_bytes: 11972
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*

 */
int a[3];
int main(){
  REP(i,3)
    cin>>a[i];

  int b;
  REP(i,3){
    b+=a[2-i]*pow(10,i);
  }

  if(b%4)
    cout<<"NO\n";
  else
    cout<<"YES\n";


  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var xs = Slist();
            xs.Insert(0, 0);
            xs.Add(0);
            var mm = new List<int>();
            long sum = 0;
            for (var i = 0; i < N + 1; i++)
            {
                var tmp = Math.Abs(xs[i + 1] - xs[i]);
                sum += tmp;
                mm.Add(tmp);
            }
            for (var i = 0; i < N; i++)
            {
                var ans = sum - mm[i] - mm[i + 1];
                var tmp = Math.Abs(xs[i + 2] - xs[i]);
                WriteLine(ans+tmp);
            }
        }

    }
}


Measured memory_bytes: 27868
/* ----------------------- reclone_rk --------------------------------------------*/ 
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int mod=1e9+7;

#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define prq priority_queue<int>
#define prqp priority_queue<pair<int,int>>
#define vtr vector<int>
#define INF INT_MAX
#define NINF INT_MIN
#define endl "\n"
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pvtr vector<pair<int,int>>
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)

int gcd(int a, int b){ if(a == 0) return b; return gcd(b%a, a);}
int MOD(int n){ return ((n%mod)+mod)%mod;}
int power(int a,int b){ if(b==0)return 1LL;int s=power(a,b/2LL);s*=s;s%=mod;if(b&1LL)return (s*a)%mod;return s;}
int inv(int a){return power(a,mod-2);}
int nCr(int n,int r){if(r>n)return 0LL;if(n-r<r)r=n-r;int ans=1;for(int i=0;i<r;i++){ans*=(n-i);ans=MOD(ans);ans*=inv(i+1);ans=MOD(ans);}return ans;}

signed main()
{   
    int n;
    cin>>n;
    int rem = n%10;
    if(rem == 2 || rem == 4 || rem == 5 || rem == 7 || rem == 9)
        cout<<"hon"<<endl;
    else if(rem == 0 || rem == 1 || rem == 6 || rem == 8)
        cout<<"pon"<<endl;
    else
        cout<<"bon"<<endl;
	return 0;
}

Measured memory_bytes: 3620
#!/usr/bin/env python3

import sys
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from fractions import gcd                    # for Python3.4.3
import math

def main():
    mod = 10000007                  # 10^9+7
    inf = float('inf')
    input = sys.stdin.readline      # 改行文字が残ることに注意
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def ii():  return int(input())
    def mi():  return map(int, input().rstrip().split())
    def lmi(): return list(map(int, input().rstrip().split()))
    def li():  return list(input().rstrip())
    
    
    n, k = mi()
    v = lmi()
    # i ... トータルの操作の回数。0 to k 回が許されている
    # 2n 回以上操作を行う意味はない。(2n 回で任意のレパートリーにできる)
    ans = -inf
    k = min(2*n, k)
    for i in range(k+1):    # O(10**2)
        for get_num in range(math.ceil(i/2), min(i+1, n+1)):    # O(50)
            return_num = i - get_num
            # print(f"get{get_num} ret{return_num} tot{i}")
            for from_left in range(get_num+1):    # O(75)
                from_right = get_num - from_left
                # print(f"left{from_left} right{from_right}")
                if from_right == 0:
                    L = v[:from_left]
                else:
                    L = v[:from_left] + v[-from_right:]
                ans = max(ans, sum(sorted(L)[return_num:]))    # O(xlgx (x=0 to 100))
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	long long a,b;
	cin>>a>>b;
	if(fabs(a-b)>2018){
		cout<<0<<endl;
		return 0;
	}
	ll mi=10000;
	for(ll i=a;i<=b;i++){
		for(ll j=i+1;j<=b;j++){
			if(i*j%2019<mi){
				mi=i*j%2019;
			}
		}
	}
	cout<<mi<<endl;
	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main()
{
 cin>>n>>m;
 for (int i=1;i<=m;i++)
 {
 	int x;
 	cin>>x;
    n-=x;
    if(n<0) break;
 }
 if(n<0) cout<<-1;
 else cout<<n;
}

Measured memory_bytes: 3592
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back   
#define sz(a) ((int)a.size())
using namespace std;
typedef long long ll ; 
const ll inf = 1e18 ;
const int mod = 1e9 + 7;
const int N = 3e5 + 5; 
const int SZ = 101;
ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}


void solve(){
    int n ;
    cin >> n ;
    int a[n];
    for(int i = 0 ; i < n ; ++i) cin >> a[i];
    sort(a , a + n);
    int l = 0 , cur = 0 , prev = 0;
    while(l < n){
        int r = l ;
        while(r < n && a[r] == a[l]) r++;
        int cnt = (a[l] - prev) % 2;
        if(cnt)cur ^= (n - l);
        prev = a[l];
        l = r ; 
    }
    cout << (cur ? "first" : "second");
}

int main()
{
    ios::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);
    int TC = 1, t = 0;
    // cin >> TC ;
    while(t++ < TC)
    {
        // cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

Measured memory_bytes: 4032
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N,A,B;
	cin>>N>>A>>B;

	cout<<min((A*N),B)<<endl;
}

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

int main() {
    int n,m;
    cin >> n >> m;
    int a[n];
    int total=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        total+=a[i];
    }
    int count=0;
    int com;
    if(total%(4*m)==0){
        com=total/(4*m)-1;
    }
    else{
        com=total/(4*m);
    }
    for(int i=0;i<n;i++){
        if(a[i]>com) count++;
    }
    if(count>=m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

int main() 
{
    int a,b,n;
    cin >> n >> a >> b;

    cout << min(b, n*a) << endl;
    
    return 0;
}
    



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>

#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
using namespace std;

int main(){
  int N;
  cin >> N;
  ll a[200010];
  //int a[]={1,4,6,3,5};
  FOR(i, 0, N) cin >> a[i];
  FOR(i, 0, N) a[i] -= i+1;
  
  sort(a, a+N);
  
  ll m;
  if(N%2==0) m = (a[N/2] + a[N/2-1])/2;
  else m = a[N/2];
  
  ll ans1 = 0;
  ll ans2 = 0;
  ll ans3 = 0;
  
  FOR(i, 0, N) ans1+=abs(a[i]-m);
  FOR(i, 0, N) ans2+=abs(a[i]-m-1);
  FOR(i, 0, N) ans3+=abs(a[i]-m+1);
  
  cout << min({ans1, ans2, ans3}) << endl;
  
  //ll sum = 0;
  //FOR(i, 0, N) sum += a[i];
  //sum /= N;
    
  //int ans1 = 0;
  //int ans2 = 0;
  //int ans3 = 0;
  
  //FOR(i, 0, N) ans1+=abs(a[i]-sum);
  //FOR(i, 0, N) ans2+=abs(a[i]-sum-1);
  //FOR(i, 0, N) ans3+=abs(a[i]-sum+1);
  
  //cout << min({ans1, ans2, ans3}) << endl;

}

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

def main(N,K,A):
    A = sorted(A, key=lambda x:x[0])
    tmp = A[0][0]
    for a, b in A:
        tmp = a
        if(0<K-b):
            K -= b
        else:
            print(tmp)
            break
    
if __name__ == '__main__':
    N, K = map(int, input().split())
    A = [[int(i) for i in input().split()] for i in range(N)]
    main(N,K,A)

Measured memory_bytes: 23640
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  S = readline()
  T = readline()
  
  smax = 0
  for i in 1:length(S)-length(T)+1
    s = 0
    for j in 1:length(T)
      if S[i+j-1] == T[j] 
        s += 1
      end
    end
    if smax < s
      smax = s
    end
  end

  println(length(T)-smax)
end

main()


Measured memory_bytes: 182308
# ABC138D - Ki (main, dfs) 1504 ms
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def dfs(v: int, p: int, T: list, cnt: list) -> None:
    for u in T[v]:
        if u != p:  # p: parent -> skip
            cnt[u] += cnt[v]  # cumulative sum
            dfs(u, v, T, cnt)


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    N, Q = tuple(map(int, input().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # tree, (N+1: 1-idx -> 0-idx)
    for a, b in E:
        T[a] += [b]
        T[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1, T, cnt)
    print(*cnt[1:])


if __name__ == "__main__":
    main()

Measured memory_bytes: 265772
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  string s;
  cin >> s;
  set<char> st;
  rep(i,3) {
    st.insert(s[i]);
  }
  if (st.size() == 2) yn;
  return 0;
}

Measured memory_bytes: 256
open Base
open Stdio

(* Core.read_line is deprecated *)
let read_line () =
    (* Out_channel.(flush stdout); *)
    In_channel.(input_line_exn stdin)

let mapt2 ~f (a, b) = (f a, f b)

let et_size = ref 0

let n = Int.of_string @@ read_line ()

let sums = Array.create ~len:(n+1) 0
let neg_res = Array.create ~len:(n+1) 0L
let g_hd = Array.create ~len:(n+1) 0
let g_nx = Array.create ~len:(2*n) 0
let g_to = Array.create ~len:(2*n) 0
let g_len = ref 0
let g_add u v =
    g_len := !g_len + 1;
    g_nx.(!g_len) <- g_hd.(u);
    g_to.(!g_len) <- v;
    g_hd.(u) <- !g_len

let colors = read_line () |> String.split ~on:' ' |> List.map ~f:Int.of_string |> (List.cons 0) |> Array.of_list

let rec dfs ?(cur=1) ?(par=0) () =
    let et_in = !et_size in
    let memo = sums.(colors.(par)) in
    et_size := !et_size + 1;
    let rec loop e = if e = 0 then () else
        let ch = g_to.(e) in
        ((if ch = par then () else dfs ~cur:ch ~par:cur ()); loop g_nx.(e)) in
    loop (g_hd.(cur));
    let et_out = !et_size in
    et_size := !et_size + 1;

    sums.(colors.(cur)) <- sums.(colors.(cur)) + 1;
    let tree_size = (et_out - et_in + 1) / 2 in
    let component_size = Int64.of_int @@ tree_size - (sums.(colors.(par)) - memo) in
    neg_res.(colors.(par)) <- Int64.(neg_res.(colors.(par)) + component_size * (component_size + 1L) / 2L);
    sums.(colors.(par)) <- tree_size + memo

let _ =
    for i = 0 to n - 2 do
        let a, b = read_line () |> String.lsplit2_exn ~on:' ' |> mapt2 ~f:Int.of_string in
        g_add a b;
        g_add b a
    done

let _ =
    dfs ();
    let tree_size = !et_size / 2 in
    for i = 1 to n do
        let component_size = Int64.of_int @@ tree_size - sums.(i) in
        let n64 = Int64.of_int n in
        let res = Int64.(n64 * (n64 + 1L) / 2L - component_size * (component_size + 1L) / 2L - neg_res.(i)) in
        printf "%Ld\n" res
    done


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

using namespace std;

const int N = 2000000;

int n;
long long res;
long long a[N + 1];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	if(a[1]) { puts("-1"); return 0; }
	for(int i = 2; i <= n; i++)
		if(a[i] > a[i - 1] + 1)
			{ puts("-1"); return 0; }
	for(int i = n; i >= 1; i--)
		if(a[i] >= a[i + 1])
			res += a[i];
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<ld,ld> pdd;
typedef pair<double,ll> pdi;
typedef pair<double,pii> pdp;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<string,string> pss;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;
typedef complex<ld> point;
#define mod (ll)(1e9+7)
#define eps (1e-9)
#define oo (ll)(0x3f3f3f3f)
#define pi acos(-1)
#define MAXN (ll)(5e5+5)

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

    ll a,b;
    ll v,w;
    cin >> a >> v;
    cin >> b >> w;
    ll t;
    cin >> t;
    if(w>=v)
        db("NO")
    else
    {
        ll d=abs(a-b);
        v-=w;
        if(t*v>=d)
            db("YES")
        else
            db("NO")
    }

    return 0;
}


Measured memory_bytes: 3632
/*
 Sarthak Jain
*/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
  return (a<b)?a:b;
}
int max(int a,int b){
  return (a>b)?a:b;
}
int fp(int a,int b){
  if(b==0) return 1;
  int x=fp(a,b/2);
  x=(x*x)%mod;
  if(b&1) x=(x*a)%mod;
  return x;
}
const int N=10005;
int f[N]={0};

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

 for(int i=1;i*i<N;i++)
 {
  for(int j=1;j<N&&(i*i+j*j)<N;j++)
  {
    for(int k=1;k<N&&k<N;k++)
    {
      int x=i*i+j*j+k*k+i*j+j*k+k*i;
      if(x>=N)
        break;
      f[x]++;
    }
  }
 }


 int n;
 cin>>n;
 for(int i=1;i<=n;i++)
  cout<<f[i]<<endl;

}

Measured memory_bytes: 3684
N = int(input())
List = [int(input()) for _ in range(N)]
s_list = sorted(List,reverse=True)
Max1 = s_list[0]
Max2 = s_list[1]

for i in range(N):
    if List[i]==Max1:
        print(Max2)
    else:
        print(Max1)

Measured memory_bytes: 14240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define ve vector
const int INF = 2e9;
int main(){
    int n,m;
    cin >> n >> m;
    ve<int> a(m),b(m);
    ve<ve<int>> c(m);
    rep(i,m){
        cin >> a[i] >> b[i];
        rep(j,b[i]){
            int c0;
            cin >> c0;
            c0--;
            c[i].push_back(c0);
        }
    }
    ve<int> dp(1<<n,INF);
    dp[0] = 0;
    rep(i,m){
        int mask=0;
        for(int ci: c[i]){
            mask |= 1<<ci;
        }
        ve<int> p(1<<n);
        p = dp;
        rep(j,1<<n){
            dp[j|mask] = min(dp[j|mask],min(p[j|mask], p[j] + a[i]));
        }
    }
    if(dp[(int)(1<<n)-1] == INF)dp[(int)(1<<n)-1] = -1;
    cout << dp[(int)(1<<n)-1] << endl;
    return 0;
}

Measured memory_bytes: 384
n,m=map(int,input().split())
l=[-1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[n*(n-1)//2]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  s,t=0,0
  if x!=y:
    s,t=l[x],l[y]
    if s>t:
      l[x]=y
      l[y]+=s
    else:
      l[y]=x
      l[x]+=t
  c[i]=c[i+1]-s*t
for x in c[1:]:
  print(x)

Measured memory_bytes: 40184