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


int main()
{
	int x, n;
	cin >> x >> n;
	vector<bool> is_in(101, false);
	for (int i = 0; i < n; ++i)
	{
		int p;
		cin >> p;
		is_in[p] = true;
	}
	int left = x, right = x;
	while (is_in[x])
	{
		left--;
		right++;
		if (!is_in[right]) x = right;
		if (!is_in[left]) x = left;
	}
	cout << x << endl;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
// #pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define isSquare(x) (sqrt(x)*sqrt(x) == x)
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(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;

int main(){
    iosetup;
    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;
    while(Q--){
        int k; cin >> k;
        ll cntd = 0, cntm = 0, cntdm = 0, ans = 0; 
        rep(i, 0, N){
            if(S[i] == 'D') cntd++;
            if(S[i] == 'M'){
                cntm++;
                cntdm += cntd;
            }
            if(S[i] == 'C') ans += cntdm;
            if(i >= k - 1){
                if(S[i-(k-1)] == 'D'){
                    cntd--;
                    cntdm -= cntm;
                }
                if(S[i-(k-1)] == 'M') cntm--;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1948
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<string.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define fi first
#define se second
#define vec vector
const double eps=1e-6;
const int inf=0x3f3f3f3f;
#define N int(1e5+5)

ll q,h,s,d,n;


void solve(){
	while(scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n)!=EOF){
		s=min(4*q,min(2*h,s));
		ll ret=0;
		if(2*s<=d){
			ret=s*n;
		}
		else {
			ret=(n/2)*d+(n%2)*s;
		}
		printf("%lld\n",ret);
	}
}

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


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

int main(){
  int N, K;
  cin >> N >> K;
  
  int d;
  int X;
  set<int> S;
  for(int i = 0; i < K; i++){
    cin >> d;
    for(int j = 0; j < d; j++){
      cin >> X;
      S.insert(X);
    }
  }
  
  cout << N - S.size() << endl;
}




Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  double x;
  int n;
  cin >> n >>x;
  int a[n];
  int m;
  for(int i=0;i<n;i++)
  {
    cin >> m;
    a[i]=m;
  }
  sort(a,a+n);
  int count=0;
  for(int i=0;i<n;i++)
  {
    x=x-a[i];
    if(x>=0){count++;}
  }
  if(x>0){count--;}
  cout<< count <<endl;
}

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

int main(void){

    ll a,b;
        cin>>a>>b;
    if( (a>=1&&a<=9) && (b>=1&&b<=9) ) cout<<a*b;
    else cout<<-1;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

template <typename M>
struct SegmentTree{
    using T = typename M::type;

    int numLeaves;
    std::vector<T> data;
    
    SegmentTree(int n){
        numLeaves = 1;
        while(numLeaves < n){
            numLeaves *= 2;
        }
        
        data.resize(numLeaves * 2);
        std::fill(data.begin() + numLeaves, data.end(), M::identity());
        
        for(int i=numLeaves-1;i>0;--i){
            data[i] = M::bop(data[i*2], data[i*2+1]);
        }
    }

    template <typename F>
    SegmentTree(int n, F f){
        numLeaves = 1;
        while(numLeaves < n){
            numLeaves *= 2;
        }

        data.resize(numLeaves * 2);
        for(int i=0;i<n;++i){
            data[i + numLeaves] = std::move(f(i));
        }
        std::fill(data.begin() + numLeaves + n, data.end(), M::identity());

        for(int i=numLeaves-1;i>0;--i){
            data[i] = M::bop(data[i*2], data[i*2+1]);
        }
    }

    void set(int k, T v){
        k += numLeaves;
        data[k] = v;
        
        while(k > 1){
            k /= 2;
            data[k] = M::bop(data[k*2], data[k*2+1]);
        }
    }
    
    T product(int l, int r){
        l += numLeaves;
        r += numLeaves;
        
        T pl = M::identity(), pr = M::identity();
        for(;l<r;l/=2,r/=2){
            if(l & 1){
                pl = M::bop(pl, data[l]);
                l += 1;
            }
            if(r & 1){
                r -= 1;
                pr = M::bop(data[r], pr);
            }
        }
        
        return M::bop(pl, pr);
    }
    
    T at(int i){
        return data[i + numLeaves];
    }
};

struct M{
    using type = int;
    static type identity(){
        return 0;
    }
    static type bop(type &m1, type &m2){
        return m1 | m2;
    }
};

SegmentTree<M> seg(500100);

int N, Q;

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

  scanf("%d", &N);

  for(int i=0;i<N;++i){
      char c;
      scanf(" %c", &c);

      seg.set(i, 1 << (c - 'a'));
  }

  scanf("%d", &Q);

  for(int i=0;i<Q;++i){
      int t;
      scanf("%d", &t);

      if(t == 1){
          int i;
          char c;
          scanf("%d %c", &i, &c);
          i -= 1;

          seg.set(i, 1 << (c - 'a'));
      }else{
          int l, r;
          scanf("%d %d", &l, &r);
          l -= 1;

          int ans = __builtin_popcount(seg.product(l, r));
          printf("%d\n", ans);
      }
  }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,Q;

template<class V,int NV> class SegTree_2 {
public:
	vector<V> val;
	SegTree_2(){val.resize(NV*2,1LL<<60);};
	
	V getval(int entry) {
		entry += NV;
		ll ret=val[entry];
		while(entry>1) entry>>=1, ret=min(ret,val[entry]);
		return ret;
	}
	
	void update(int x,int y, V v,int l=0,int r=NV,int k=1) {
		if(l>=r) return;
		if(x<=l && r<=y) val[k]=min(val[k],v);
		else if(l < y && x < r) {
			update(x,y,v,l,(l+r)/2,k*2);
			update(x,y,v,(l+r)/2,r,k*2+1);
		}
	}
};

SegTree_2<ll,1<<20> st;
vector<ll> C;
ll S[202020],T[202020],X[202020],D[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	C.push_back(-1LL<<60);
	C.push_back(1LL<<60);
	FOR(i,N) {
		cin>>S[i]>>T[i]>>X[i];
		C.push_back(S[i]-X[i]);
		C.push_back(T[i]-X[i]);
	}
	FOR(i,Q) {
		cin>>D[i];
		C.push_back(D[i]);
	}
	sort(ALL(C));
	C.erase(unique(ALL(C)),C.end());
	FOR(i,N) {
		x=lower_bound(ALL(C),S[i]-X[i])-C.begin();
		y=lower_bound(ALL(C),T[i]-X[i])-C.begin();
		st.update(x,y,X[i]);
	}
	
	
	FOR(i,Q) {
		x=lower_bound(ALL(C),D[i])-C.begin();
		ll ret=st.getval(x);
		if(ret>=1LL<<50) {
			cout<<-1<<endl;
		}
		else {
			cout<<ret<<endl;
		}
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

template<class c> auto try_out(c a) -> decltype(cerr << a, 0);
char try_out(...);

struct debug {
#ifdef LOCAL
template<class c, class d> debug& operator << (pair<c, d> e) {
	return *this << "(" << e.first << ", " << e.second << ")";
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) != 1, debug&>::type operator << (c a) {
	cerr << boolalpha << a;
	return *this;
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) == 1, debug&>::type operator << (c a) {
	*this << "[";
	for (auto it = a.begin(); it != a.end(); ++it)
		*this << ","[1 - (it != a.begin())] << *it;
	return *this << "]";
}
#else
template<class c> debug& operator << (c) {
	return *this;
}
#endif
};

#define aty(x) " [" << #x ": " << x << "] "

using ll = long long;



bool good(char c)
{
    return c == 'A' || c == 'C' || c == 'G' || c == 'T';
}

int main() {
	
	string s;
    cin >> s;
    
    int ans = 0;
    int ans2 = 0;
    
    bool fl = false;
    
    for (int i = 0; i < (int) s.size(); ++i) 
    {
        if (good(s[i])) {
            if (!fl) {
                fl = true;
            } 
            ans2++;
        }
        else {
            if (fl) {
                ans = max(ans2, ans);
                fl = false;
            }
            ans2 = 0;
        }
    }
    
    ans = max(ans, ans2);
    
    cout << ans;
	
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll n;sc(n);
 ll a[n+10];
 rep(i,0,n){
  sc(a[i]);
  a[0]=gcd(a[0],a[i]);
 }
 pr(a[0]);

  return 0;}

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

Measured memory_bytes: 3060
from math import sqrt


def isprime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(sqrt(n)) + 1, 2):
        if n % i == 0:
            return False
    return True

result = 0
for i in range(int(input())):
    result += isprime(int(input()))
print(result)

Measured memory_bytes: 6808
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll n;
ll solve(vector<ll>g,vector<ll>s,vector<ll>b){
    vector<ll>dp(n+1,0);
    ll m=0;
    rep(i,n+1){
        if(i==0)continue;
        dp[i]=i;
        if(i-g[0]>=0)chmax(dp[i],dp[i-g[0]]+g[1]);
        if(i-s[0]>=0)chmax(dp[i],dp[i-s[0]]+s[1]);
        if(i-b[0]>=0)chmax(dp[i],dp[i-b[0]]+b[1]);
        chmax(m,dp[i]);
    }
    vector<ll>dp2(m+1,0);
    ll ans=0;
    rep(i,m+1){
    if(i==0)continue;
        dp2[i]=i;
        if(i-g[1]>=0)chmax(dp2[i],dp2[i-g[1]]+g[0]);
        if(i-s[1]>=0)chmax(dp2[i],dp2[i-s[1]]+s[0]);
        if(i-b[1]>=0)chmax(dp2[i],dp2[i-b[1]]+b[0]);
        chmax(ans,dp2[i]);
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n;
    vector<ll>g(2),s(2),b(2);
    cin>>g[0]>>s[0]>>b[0];
    cin>>g[1]>>s[1]>>b[1];
    cout<<solve(g,s,b)<<endl;
    return 0;
}

Measured memory_bytes: 195584
import sys
x = int(input())

for i in range(10000):
  a = pow(i, 5)
  for j in range(10000):
    b = pow(j, 5)
    if a-b == x:
      print(i, j)
      sys.exit()
    elif a+b == x:
      print(i, -j)
      sys.exit()


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

using namespace std;

int main() {

	int n;
	cin >> n;

	int oold = 1;
	int old = 1;
	int neww;

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

	for (int i = 2; i <= n; i++) {
		neww = old + oold;
		oold = old;
		old = neww;
	}

	cout << neww << endl;

	return 0;

}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

bool f(vector<pair<int, char>> a, int i, int n) {
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	if (a[0].first > a[1].first + n - i) {
		cout << a[0].second << " " << i << endl;
		return true;
	}

	return false;
}

signed main() {
	for (int n; cin >> n&&n;) {
		vector<char> c(n); rep(i, 0, n) { cin >> c[i]; }
		vector<pair<int, char>> a(26, pair<int, char>(0, 0));
		bool TIE = true;
		rep(i, 0, n) {
			a[c[i] - 'A'].first++;
			a[c[i] - 'A'].second = c[i];
			if (f(a, i + 1, n)) {
				TIE = false;
				break;
			}
		}
		if (TIE)cout << "TIE" << endl;
	}
	return 0;
}

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

using namespace std;

using ll = long long;

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

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (auto &&x : a) cin >> x;

    vector<vector<bool>> dp(2, vector<bool>(k + 1, false));
    for (int i = 1; i <= k; ++i) {
        for (int j = 0; j < 2; ++j) {
            bool flag = false;
            for (int l = 0; l < n; ++l) {
                if (i - a[l] < 0) break;
                flag |= !dp[1 - j][i - a[l]];
            }
            if (0 <= i - a[0]) dp[j][i] = flag;
        }
    }

    cout << (dp[0][k] ? "First" : "Second") << endl;

    return 0;
}


Measured memory_bytes: 384
//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
#define debug(x) cerr << #x << " : " << x;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 7;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	int N = 0, W = 0, E = 0, S = 0;
	for (int i = 0; i < s.size(); i++)
		if(s[i] == 'N')
			N = 1;
		else
		if(s[i] == 'E')
			E = 1;
		else
		if(s[i] == 'W')
			W = 1;
		else
			S = 1;
	if((N + S) % 2 || (E + W) % 2)
		return cout << "No", 0;
	cout << "Yes";
}

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

int main(){

    int a, b , N, K, i,j,tmp;
    int p[1001];
    int price=0;
    scanf("%d %d",&a,&b);
    N=a;
    K=b;
    for(i=0;i<N;i++){
        scanf("%d ",&p[i]);
    }

    for (i=0; i<N; ++i) {
        for (j=i+1; j<N; ++j) {
        if (p[i] > p[j]) {
            tmp =  p[i];
            p[i] = p[j];
            p[j] = tmp;
            }
        }
    }

    for(i=0;i<K;i++){
        price = price + p[i];
    }

    printf("%d",price);

}

Measured memory_bytes: 1672
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9 // INF = Infinity 無限　最小値を求めるときによく使う　
int main() {
  //入力
  int n,t;
  cin >> n >> t;
  vector<int> c(n),d(n);
  rep(i,n) cin >> c.at(i) >> d.at(i);

  //処理部分
  int ans = INF;//無限で初期化しておく(実用上は十分大きい数)
  rep(i,n){
    // 時間内につくものについてコストの最小値をとる
    if(d.at(i)<=t){
      ans = min(ans,c.at(i));
    }
  }
  // 時間内につくものがないなら最小値の更新はされてないはず
  if(ans==INF){
    cout <<  "TLE" << endl;
  }else{
    cout << ans << endl;
  }
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

import collections
def solve(S: str):
    count_dict = collections.defaultdict(int)
    for s in S:
        count_dict[s] += 1
    if len(count_dict)==2:
        for s in S:
            if count_dict[s]!=2:
                print('No')
                exit()
        else:
            print('Yes')
    else:
        print('No')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define BUG(x) cout << #x << " = " << x << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto i:x) cout << i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 0.00000001
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

int a, b;

int main() {
  ios::sync_with_stdio(false);
  cin >> a >> b;
  a += b;
  a %= 24;
  cout << a;
}

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

int main() {
  vector<pair<int, int>> po;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int h, m;
    cin >> h >> m;
    po.push_back(make_pair(h, m));
  }
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int h, m;
    cin >> h >> m;
    po.push_back(make_pair(h, m));
  }

  sort(po.begin(), po.end());
  po.erase(unique(po.begin(), po.end()), po.end());

  for (int i = 0; i < po.size(); ++i) {
    printf("%d:%02d%c", po[i].first, po[i].second, (i + 1 == po.size() ? '\n' : ' '));
  }
}



Measured memory_bytes: 3156
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
	int k, n;
	char s[52];
	scanf("%d%d", &n, &k);
	scanf("%s", s);
	if (s[k - 1] >= 'a'&&s[k - 1] <= 'c')s[k - 1] = s[k - 1] - 32;
	if(s[k - 1] >= 'A'&&s[k - 1] <= 'C')s[k - 1] = s[k - 1] + 32;
	printf("%s\n", s);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{

    int a;
    int b;
    scanf("%d", &a);
    scanf("%d", &b);
    if (a * b % 2 == 0)
    {
        printf("Even");
    }
    else
    {
        printf("Odd");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>

using namespace std;

int main() {
	string s;
	getline(cin,s);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] >= 'A'&&s[i] <= 'Z')s[i] += 32;
		else if(s[i] >= 'a'&&s[i] <= 'z')s[i] -= 32;
	}
	cout << s << endl;
	return 0;
}

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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    rep (i, 5) {
        int x;
        cin >> x;
        if (x == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3572
x = int(input())
dp = [0]*(x + 105 + 1)
dp[100] = 1 
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1

for i in range(100,x-105+50):
    for j in range(100,106):
        dp[i+j] = max(dp[i] , dp[i+j])

print(dp[x])

Measured memory_bytes: 9512
#include <iostream>

using namespace std;

int main(){
  int a;
  int b;
  cin >> a >> b;
  string s = "";
  string t = "";
  for(int i = 0; i < b; i++){
    s += (char) (a + '0');
  }
  for(int i = 0; i < a; i++){
    t += (char) (b + '0');
  }
  if ( a > b ){
    cout << t;
  }
  else {
    cout << s;
  }
  return 0;
}

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

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

    ll limit = n;
    vector<ll> ans;
    for (ll i = 2; i * i < limit; i++)
    {
        while (n % i == 0)
        {
            n = n / i;
            ans.push_back(i);
        }
    }
    if (n > 1)
    {
        ans.push_back(n);
    }

    cout << limit << ":";
    for (ll value : ans)
    {
        cout << " " << value;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3152
pub struct UnionFind {
    data: Vec<i32>,
}

impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        UnionFind { data: vec![-1; n] }
    }

    pub fn unite(&mut self, x: usize, y: usize) -> bool {
        let x = self.root(x);
        let y = self.root(y);
        if x != y {
            let (x, y) = if self.data[x] <= self.data[y] {
                (x, y)
            } else {
                (y, x)
            };
            self.data[x] += self.data[y];
            self.data[y] = x as i32;
        }
        x != y
    }

    pub fn same(&mut self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }

    pub fn size(&mut self, x: usize) -> u32 {
        let r = self.root(x);
        (-self.data[r]) as u32
    }

    pub fn root(&mut self, x: usize) -> usize {
        if self.data[x] < 0 {
            x
        } else {
            let nx = self.data[x] as usize;
            let r = self.root(nx);
            self.data[x] = r as i32;
            r
        }
    }
}
fn main() {
    let (n, m): (usize, usize) = readln();
    let p: Vec<usize> = readln();
    let v: Vec<(usize, usize)> = readlns(m);
    let mut uf = UnionFind::new(n);
    for (x, y) in v {
        uf.unite(x - 1, y - 1);
    }
    let mut ans = 0;
    for (idx, x) in p.into_iter().enumerate() {
        if uf.same(idx, x - 1) {
            ans += 1;
        }
    }
    println!("{}", ans);
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(readln());
    }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T>
where
    T: FromLn,
{
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


Measured memory_bytes: 10492
n=int(input())
V=list(map(int,input().split()))
V2=[{},{}]

for i,v in enumerate(V):
  m = i%2
  V2[m][v]=V2[m].get(v,0)+1
v0n,v0o,v1n,v1o = [],[],[],[]
for v in V2[0]:
  v0n.append(v)
  v0o.append(V2[0][v])
for v in V2[1]:
  v1n.append(v)
  v1o.append(V2[1][v])

#if len(v0n)==1 and len(v1n)==1:
#  if v0n[0] == v1n[0]:
#    print(n//2)
#  else:
#    print(0)
#  exit()
import numpy as np
v0a = np.array(v0o).argsort()[::-1]
v1a = np.array(v1o).argsort()[::-1]

s0 = sum(v0o)
s1 = sum(v1o)
total = s0+s1-v0o[v0a[0]]-v1o[v1a[0]]
if v0n[v0a[0]]!=v1n[v1a[0]]:
  print(total)
  exit()
else:
  if len(v0o) == 1:
    d0 = v0o[v0a[0]]
  else:
    d0 = v0o[v0a[0]] - v0o[v0a[1]]
  if len(v1o) == 1:
    d1 = v1o[v1a[0]]
  else:
    d1 = v1o[v1a[0]] - v1o[v1a[1]]
  print(total + min(d0,d1))


Measured memory_bytes: 38096
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int n , K;
string s;
deque<int> v;

int main(){
  cin >> n >> K >> s;
  for(auto ch : s) v.pb(ch=='A'?0:1);
  bool rev=false;
  int times=0;
  if(K<=2*n) times=K;
  else times=2*n+(K&1);
  rep(i,0,times) {
    int c=rev^v.front();
    v.pop_front();
    if(c==0) v.push_front(rev^1);
    else rev^=1,v.push_back(rev);
  }
  while(sz(v)) {
    putchar("AB"[rev^v.front()]);
    v.pop_front();
  }
  return 0;
}


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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
    ll n,k;
    cin>>n>>k;

    ll a;
    a=n;
    ll co=0;
    while(a>0){
        a /= k;
        co++;
    }

    cout<<co<<endl;


}

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

int main(){
    int x,y,z,count;
    cin>>x>>y>>z>>count;
    vector<long long> a(x);
    vector<long long> b(y);
    vector<long long> c(z);
    int p;
    p=x*y*z;
    int o;
    for(int i=0;i<x;i++){
        cin>>a[i];
    }
    for(int i=0;i<y;i++){
        cin>>b[i];
    }
    for(int i=0;i<z;i++){
        cin>>c[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    priority_queue<long long> ans;
    for(int i=0;i<x;i++){
        for(int j=0;j<y;j++){
            if(i*j>3000)break;
            for(int k=0;k<z;k++){
                ans.push(a[x-1-i]+b[y-1-j]+c[z-1-k]);
                if((i+1)*(j+1)*(k+1)>3000)break;
            }
        }
    }
    int big=3000;
    for(int i=0;i<count;i++){
        cout<<ans.top()<<endl;
        ans.pop();
    }
    return 0;
}

Measured memory_bytes: 1404
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long mod=1e9+7;

using namespace std;

int main(){
	
	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]%=mod;
	}
	vector<long long> s(n);
	long long sum=0;
	for(int i=n-1;i>=0;i--){
		sum+=a[i];
		sum%=mod;
		s[i]=sum;
	}
	long long ans=0;
	for(int i=1;i<n;i++){
		ans+=a[i-1]*s[i]%mod;
	}
	ans%=mod;
	cout << ans << endl;
	return 0;
}


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

using CP = complex<long double>;
#define X real()
#define Y imag()
const long double PI = acos(-1);
const long double EPS = 1e-10;
// conj(x) : complex conjugate,(0,1)->(0,-1)
// abs(x) : dist between(0,0) and x
// norm(x) : abs(x) * abs(x)
// arg(x) : argment
long double dot(CP a, CP b) { return (a * conj(b)).X; }
long double cross(CP a, CP b) { return (a * conj(b)).Y; }
long double corner(CP a, CP b) {
  //[0,pi]
  return acos(dot(a, b) / (abs(a) * abs(b)));
}

CP intersection(CP a, CP b, CP c, CP d) {
  return a + (b - a) * (cross(d - c, c - a) /
                        cross(d - c, b - a));
}

bool on_seg(CP a, CP b, CP p) {
  // if not use end point, dot(a - p, b - p) < 0
  return abs(cross(a - p, b - p)) <= 1e-10 &&
         dot(a - p, b - p) < 0;
}

// crossing lines? (a,b) and (c,d)
bool iscross(CP a, CP b, CP c, CP d) {
  // parallel
  if(abs(cross(a - b, c - d)) <= 1e-10) {
    return on_seg(a, b, c) || on_seg(a, b, d) ||
           on_seg(c, d, a) || on_seg(c, d, b);
  }
  CP isp = intersection(a, b, c, d);
  return on_seg(a, b, isp) && on_seg(c, d, isp);
}

struct line {
  CP s, t;
};

bool asc(const CP &l, const CP &r) {
  long double disl = abs(l - CP(-100, -100)),
              disr = abs(r - CP(-100, -100)), argx, argy;
  if(disl != disr) return disl < disr;
  argx = arg(l - CP(-100, -100)),
  argy = arg(r - CP(-100, -100));
  return argx < argy;
}

long long n;
vector<line> v;
vector<CP> p;

long long solve();

int main() {
  while(1) {
    cin >> n;
    if(n == 0) break;
    v.resize(n);
    for(int i = 0; i < n; ++i) {
      int x, y, x2, y2;
      cin >> x >> y >> x2 >> y2;
      v[i] = {CP(x, y), CP(x2, y2)};
    }
    cout << solve() << endl;
  }
  return 0;
}

long long solve() {
  p.clear();
  long long res = n + 1;
  for(int i = 0; i < n; ++i)
    for(int j = i + 1; j < n; ++j)
      if(iscross(v[i].s, v[i].t, v[j].s, v[j].t))
        p.push_back(
            intersection(v[i].s, v[i].t, v[j].s, v[j].t));
  sort(p.begin(), p.end(), asc);
  n = p.size();
  for(int i = 0; i < n;) {
    int id = i, cnt = 0;
    while(i < n && abs(p[i] - p[id]) < EPS) ++i;
    cnt = i - id;
    cnt *= 2;
    for(int j = 1; j <= 100; ++j)
      if(j * (j - 1) == cnt) res += j - 1;
  }
  return res;
}


Measured memory_bytes: 3224
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

ll dp[60][60][2510];  // dp[i][j][k] : i枚目のカードまででj枚選んで合計をkにする場合の数

int main() {
    ll n, A;
    cin >> n >> A;

    vl x(n);
    rep(i, n) {
        cin >> x[i];
    }

    dp[0][0][0] = 1;
    rep(i, n) {
        exrep(j, 0, n) {
            exrep(k, 0, 2500) {
                dp[i+1][j][k] += dp[i][j][k];
                if(j+1 <= n && k + x[i] <= 2500) {
                    dp[i+1][j+1][k + x[i]] += dp[i][j][k];
                }
            }
        }
    }

    ll ans = 0;
    exrep(j, 1, n) {
        ans += dp[n][j][j*A];
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 53768
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define sint(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;


typedef pair<int,int>P;

const int MAX_N = 100005;

int n,m,p;

int main()
{
    while(1){
        cin >> n >> m >> p;
        if(n == 0){
            break;
        }
        vector<int> vec(n);
        rep(i,n){
            cin >> vec[i];
        }
        if(vec[m-1] == 0){
            cout << "0\n";
            continue;
        }
        int sm = accumulate(all(vec),0);
        cout << (int)((double)sm*(100-p)/vec[m-1]) << "\n";
    }
}

Measured memory_bytes: 3088
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
int main()
{
	int i,j,k,n,m;
	scanf("%d",&n);
	if(n<=111)
	{
		printf("111");
	}
	else if(n<=222)
	{
		printf("222");
	}
	else if(n<=333)
	{
		printf("333");
	}
	else if(n<=444)
	{
		printf("444");
	}
	else if(n<=555)
	{
		printf("555");
	}
	else if(n<=666)
	{
		printf("666");
	}
	else if(n<=777)
	{
		printf("777");
	}
	else if(n<=888)
	{
		printf("888");
	}
	else
	{
		printf("999");
	}
}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(read())

pre_lis = []
for i in range(1,10):
    pre_lis.append(str(i))
    
ct = 9
if K <= 9:
    print(pre_lis[K-1])
else:
    new_lis = []
    flag = False
    while ct < K:
        for num in pre_lis:
            pre_num = int(num[-1])
            for i in range(10):
                if abs(pre_num-i) <= 1:
                    new_lis.append(num + str(i))
                    ct+=1
                    if ct == K:
                        print(new_lis[-1])
                        flag = True
                        break
            pre_lis = new_lis
            if flag:
                break
        if flag:
            break

Measured memory_bytes: 10136
V,E,start = map(int,input().split())
node_edges = [[] for _ in range(V)]
for i in range(E):
    s,g,cost = map(int,input().split())
    node_edges[s].append([cost,g])
import heapq
n = V
def dijkstra_heap(s,node_edges):
    '''
    node_edgesはindがノード番号、valueが[コスト,行先node],[コスト,行先node]..]というindノードからのエッジのリスト
    ノードの入力は0-indexedに修正してから用いる
    returnはノードごとの最小コストを格納したリスト
    '''
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [False] * n #True:未確定
    d[s] = 0
    used[s] = True
    edgelist = []
    # 始点がスタートになってるedgeをヒープキューに追加
    for e in node_edges[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        # ヒープキューからコスト最小のedgeをpop
        # heappopは要素リストの0要素目で最小を管理する
        minedge = heapq.heappop(edgelist)
        # 該当edgeの行き先が確定済みになってなければこれを通って処理が続く
        if used[minedge[1]]:
            continue
        v = minedge[1]
        # 該当edgeの行き先のコストを更新
        d[v] = minedge[0]
        used[v] = True
        for e in node_edges[v]:
            if not used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d
ls = dijkstra_heap(start,node_edges)
for i in range(n):
    value = ls[i]
    if value == float('inf'):
        value = "INF"
    print(value)


Measured memory_bytes: 106952
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while( true ){
			int n = Integer.parseInt(scan.next());
			if( n <= 0 ){
				break;
			}
			int max = 0, min = 1000, sum = 0;
			int temp = 0;
			for( int i = 0; i < n; i++ ){
				temp = Integer.parseInt(scan.next());
				if( temp > max ){
					max = temp;
				}
			if( temp < min ){
					min = temp;
				}
				sum += temp;
			}
			
			System.out.println((sum-max-min)/(n-2));
		}
		return;
	}
}

Measured memory_bytes: 20304
//@author :  |< U $ |-|
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#include<unordered_map>
#define ll long long
#define vi vector<long long>
#define pb push_back
#define pop pop_back
#define pi pair<long long ,long long>
#define vp vector<pair<long long,long long> >
#define mkp make_pair
#define in(i,n) for(i=0;i<n;i++)
#define fon(i,n,m) for(i=n;i<m;i++)
#define rfon(i,n,m) for(i=n;i>=m;i--)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// #define map map<long long,long long>
#define inm1(b)  memset(b,-1,sizeof(b))
#define in0(b) memset(b,0,sizeof(b))
#define ininf(b) memset(b,1000000001,sizeof(b))
#define MOD         1000000007
#define I 1000000000000000001
#define t(a) cout<<a<<" "<<endl
#define tt(a,b) cout<<a<<" "<<b<<endl
#define th(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define TakeInput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
using namespace std;
ll gcd(ll a, ll b) {  if (a == 0)  return b; return gcd(b % a, a); }

ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}



int main(){
    jaldi
    // #ifndef ONLINE_JUDGE
    // TakeInput
    // #endif
    

    string a,b;
    cin>>a>>b;

    ll i,j,n,m=0;
    n=a.length();
    in(i,n){
        if(a[i]!=b[i])
            m++;
    }
    cout<<m;
}











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


int main(){
  int a,b;
  cin >> a >> b;
  if((a+b)%2 == 0) cout << (a+b)/2 << endl;
  if((a+b)%2 == 1) cout << (a+b)/2+1 << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int x, ans = 0;
    cin >> x;
    ans = x / 11 * 2;
    if(x % 11 >= 1) ans++;
    if(x % 11 >= 7) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, a;
    cin >> n;
    vector<ll> ans(n, 0LL), p;
    vector<pair<ll, ll> > v;
    for(int i=0;i<n;i++){
    	cin >> a;
    	v.push_back({a, i});
    }
    sort(be(v));
    p.pb(0LL);
    for(auto& i:v) p.pb(i.first);
    ll i = n, idx = INF;
    while(i > 0) {
    	ll id = lower_bound(be(p), p[i]) - p.begin();
    	i = id - 1;
    	idx = min(idx, v[i].second);
    	ans[idx] += (n - i) * (p[id] - p[i]);
    }
    for(int i=0;i<n;i++) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 5232
#include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <utility>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int a[5];

bool four_card() {
  if (a[0] == a[1]) {
    return a[1] == a[2] && a[2] == a[3];
  } else {
    return a[1] == a[2] && a[2] == a[3] && a[3] == a[4];
  }
}

bool straight() {
  if (a[0] == 1 && a[1] == 10 && a[2] == 11 && a[3] == 12 && a[4] == 13)
    return true;
  for (int i = 0; i < 4; i++)
    if (a[i] != a[i+1] - 1)
      return false;
  return true;
}

bool full_house() {
  int b = a[0];
  int c = a[4];
  if (b != a[1] || c != a[3])
    return false;
  return b == a[2] || c == a[2];
}

bool three_card() {
  if (a[0] == a[1]) {
    return a[1] == a[2];
  } else if (a[1] == a[2]) {
    return a[2] == a[3];
  } else {
    return a[2] == a[3] && a[3] == a[4];
  }
}

bool two_pair() {
  set<int> se;
  for (int i = 0; i < 5; i++)
    se.insert(a[i]);
  return se.size() == 3;
}

bool one_pair() {
  set<int> se;
  for (int i = 0; i < 5; i++)
    se.insert(a[i]);
  return se.size() == 4;
}

int main() {
  string s[7] = {
    "four card", "full house", "straight", "three card", "two pair", "one pair", "null"
  };

  char c;
  while (cin >> a[0]) {
    for (int i = 1; i < 5; i++)
      cin >> c >> a[i];
    sort(a, a + 5);
    string res;
    if (four_card()) {
      res = s[0];
    } else if (full_house()) {
      res = s[1];
    } else if (straight()) {
      res = s[2];
    } else if (three_card()) {
      res = s[3];
    } else if (two_pair()) {
      res = s[4];
    } else if (one_pair()) {
      res = s[5];
    } else {
      res = s[6];
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1212
N, Y = list(map(int, input().split()))

flag = False
for x in range(N+1):
  for y in range(N-x+1):
    z = N - x - y
    if Y == 10000 * x + 5000 * y + 1000 * z:
      print(x, y, z)
      flag = True
      quit()
if ~flag:
  print("-1 -1 -1")

Measured memory_bytes: 3060
def main():
  def f(i,x):
    while i<=n:
      b[i]+=x
      i+=i&-i
  def g(i):
    s=0
    while i:
      s+=b[i]
      i-=i&-i
    return s
  (n,q,*w),a,*t=[map(int,t.split())for t in open(0)]
  b=[0]*-~n
  *map(f,range(1,n+1),a),
  for q,l,r in t:
    if q:w+=g(r)-g(l),
    else:f(l+1,r)
  print(' '.join(map(str,w)))
main()

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#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 For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i];
    }
    
    int ans = 0, m = 0;
    rep(i, n) {
        if (m <= data[i]) ans++;
        m = max(m, data[i]);
    }
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	VL a(n);
	rep(i, n) {
		cin >> a[i];
	}
	VL dp(n, 1000); // i日目までの利益
	rep(i, n) {
		REP(j, i + 1, n) {
			chmax(dp[j], dp[i]);
			ll x = dp[i] / a[i];
			ll rem = dp[i] % a[i];
			// cout << x << " " << y << " " << rem << endl;
			chmax(dp[j], x * a[j] + rem);
		}
		REP(j, i + 1, n) chmax(dp[j], dp[i]);
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

int main() {
	int n, c;
	cin >> n >> c;
	vector<vector<int>> d(c, vector<int>(c)), col(n, vector<int>(n));
	rep(i, c) rep(j, c) cin >> d[i][j];
	rep(i, n) rep(j, n) {
		cin >> col[i][j];
		col[i][j]--;
	}
	vector<int> mod0(c), mod1(c), mod2(c);
	rep(nextc, c) {
		rep(i, n) {
			rep(j, n) {
				int nowc = col[i][j];
				if((i+j) % 3 == 0) {
					mod0[nextc] += d[nowc][nextc];
				} else if((i+j) % 3 == 1) {
					mod1[nextc] += d[nowc][nextc];
				} else {
					mod2[nextc] += d[nowc][nextc];
				}
			}
		}
	}
	int ans = 1001001001;
	for(int c0 = 0; c0 < c; c0++) {
		for(int c1 = 0; c1 < c; c1++) {
			for(int c2 = 0; c2 < c; c2++) {
				if(c0 == c1 || c1 == c2 || c2 == c0) continue;
				int now = mod0[c0] + mod1[c1] + mod2[c2];
				ans = min(ans, now);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int32_t main()
{
	fastIO
	inp_out();
	int n; 
	cin >> n; 
	vi a(n); 
	int xr = 0; 
	for(int i = 0; i < n;  ++ i)
	{
		cin >> a[i]; 
		xr ^= a[i]; 
	}

	for(int i = 0; i < n;  ++ i)
		cout << (xr ^ a[i]) << " "; 


	return 0;
}

Measured memory_bytes: 4764
import math

cnt = 0

N, D = map(int, input().split())
X = []
for l in range(N):
    X.append(list(map(int, input().strip().split())))

for i in range(0, N - 1):
    for j in range(i + 1, N):
        sum = 0
        for k in range(0, D):
            sum += (X[i][k] - X[j][k])**2
        if math.sqrt(sum) == int(math.sqrt(sum)):
            cnt += 1
print(cnt)

Measured memory_bytes: 3064