akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int F(ll A, ll B) {
    return max(to_string(A).length(), to_string(B).length());
}

int main() {
    ll N;
    cin >> N;
    int min = to_string(N).length();
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            int result = F(i, N / i);
            if (min > result) {
                min = result;
            }
        }
    }
    cout << min << endl;
    return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

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

    cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end())
         << "\n";
    return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end()) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ri register int
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=2e6+3;
ll ans=0;
ll jie[N],ni[N];
struct node{
    int x,y,fl;
    void init(int a,int b,int c){
        x=a,y=b,fl=c;
    }
}p[20];
int tot;
int x3,y3,x4,y4;
int xx[10],yy[10];
ll qm(ll x,ll y){
    ll ret=1;
    while(y){
        if(y&1) ret=ret*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return ret;
}
ll C(int n,int m){
    return jie[n]*ni[m]%mod*ni[n-m]%mod;
} 
ll G(int x1,int y1,int x2,int y2){
    ll A=abs(x2-x1),B=abs(y2-y1);
    return C(A+B,B);
}
ll sol(int x1,int y1,int x2,int y2,int f1,int f2){
    ll ret=0;
    for(ri x=x3;x<=x4;++x){
        ret=(ret+G(x1,y1,x,y4)*G(x,y4+1,x2,y2)%mod*(x+y4+1))%mod;//注意这里的x+y4+1的+1 
        ret=(ret-G(x1,y1,x,y3-1)*G(x,y3,x2,y2)%mod*(x+y3)%mod+mod)%mod;
    }
    for(ri y=y3;y<=y4;++y){
        ret=(ret+G(x1,y1,x4,y)*G(x4+1,y,x2,y2)%mod*(x4+y+1))%mod; 
        ret=(ret-G(x1,y1,x3-1,y)*G(x3,y,x2,y2)%mod*(x3+y)%mod+mod)%mod;
    } 
    ret=ret*(f1*f2);

    return ret;
}
int main(){
    int x,y;
    for(ri i=1;i<=6;++i)scanf("%d",&xx[i]);
    for(ri i=1;i<=6;++i)scanf("%d",&yy[i]);
    jie[0]=1;
    for(ri i=1;i<=N-2;++i) jie[i]=jie[i-1]*i%mod;
    ni[N-2]=qm(jie[N-2],mod-2);
    for(ri i=N-3;i>=0;--i) ni[i]=ni[i+1]*(i+1)%mod;

    x3=xx[3],y3=yy[3],x4=xx[4],y4=yy[4];
    p[1].init(xx[1]-1,yy[1]-1,1);p[2].init(xx[2],yy[1]-1,-1);//注意这里是这样的 
    p[3].init(xx[1]-1,yy[2],-1);p[4].init(xx[2],yy[2],1);

    p[5].init(xx[5],yy[5],1);p[6].init(xx[6]+1,yy[5],-1);
    p[7].init(xx[5],yy[6]+1,-1);p[8].init(xx[6]+1,yy[6]+1,1);

    for(int i=1;i<=4;++i){
        for(int j=5;j<=8;++j){
            ans=(ans+sol(p[i].x,p[i].y,p[j].x,p[j].y,p[i].fl,p[j].fl)+mod)%mod;
        }  
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 31488
import heapq
n,m = map(int,input().split())
hq = []
ab = []
for i in range(n):
    ab.append([int(_) for _ in input().split()])
ab.sort(key = lambda x:(x[0],-x[1]))
ab.append([m+1,-1])
now = 1
ans = 0
idx = 0
while now <= m:
    while ab[idx][0] <= now:
        heapq.heappush(hq,-ab[idx][1])
        idx += 1
    if hq != []:
        ans -= heapq.heappop(hq)
    now += 1
print(ans)

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

int main(){
    int n,ans=0,now;
    cin >> n;
    vector<int> a(n);

    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }

    now = 0;
    for(int i = 0; i < n; ++i){
        now = a.at(now)-1;
        if(now == 1){
            cout << (i + 1) << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3152
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >>s;
    int n=s.size();
    int a;
    int z;
    for (int i=0; i<n; i++){
        if (s[i]=='A'){
            a=i;
            break;
        }
    }
    for (int i=0; i<n; i++){
        if (s[n-i-1]=='Z'){
            z=i;
            break;
        }
    }
    cout << n-a-z;
}

Measured memory_bytes: 640
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n, m; cin >> n >> m;
  vector<vector<ll>> G(n);
  rep(i, m) {
    ll a, b; cin >> a >> b; --a, --b;
    G[a].pb(b);
  }
  vector<bool> m1(n, false);
  vector<ll> m2(n);
  function<ll(ll)> dp = [&](ll v) {
    if (m1[v]) return m2[v];
    ll res = 0;
    each(to, G[v]) {
      chmax(res, dp(to)+1);
    }
    return m1[v] = true, m2[v] = res;
  };
  ll ans = 0;
  rep(i, n) chmax(ans, dp(i));
  cout << ans << endl;
}


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

int main () {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i+K < N; i++) {
        if (A[i] < A[i+K]) {
            puts("Yes");
        }
        else {
            puts("No");
        }
    }
}

Measured memory_bytes: 4824
import java.util.*;
import java.awt.geom.*;
public class Main {
	//0945 start
	//0952 WA
	ArrayList<Integer> list;
	int MAX = 10000;

	private void doit(){
		Scanner sc = new Scanner(System.in);
		eratos();
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int count = 0;
			int len = list.size();
			for(int i = 0; i < len; i++){
				int sum = list.get(i);
				if(sum == n){
					count++;
				}
				for(int j = i + 1; j < len; j++){
					sum += list.get(j);
					if(sum == n){
						count++;
						break;
					}
					if(sum > n ){
						break;
					}
				}
			}
			System.out.println(count);
		}
	}

	private void eratos() {
		boolean [] isprime = new boolean[MAX + 1];
		Arrays.fill(isprime, true);
		isprime[0] = false;
		isprime[1] = false;
		list = new ArrayList<Integer>();
		for(int i = 2;i<= MAX; i++){
			if(isprime[i]){
				list.add(i);
				for(int j = i + i; j <= MAX; j+= i){
					isprime[j] = false;
				}
			}
		}
	}

	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=5e3+5;
char s[N],t[N];
int dp[N][N];
int main()
{
    scanf("%s%s",s+1,t+1);
    int n=strlen(s+1),m=strlen(t+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
    {
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        if(s[i]==t[j]) dp[i][j]=dp[i-1][j-1]+1;
    }
    string ans="";
    while(n&&m)
    {
        if(s[n]==t[m]&&dp[n][m]==dp[n-1][m-1]+1)
            ans+=s[n],n--,m--;
        else if(dp[n][m]==dp[n-1][m]) n--;
        else m--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}


Measured memory_bytes: 59264
my @data = <STDIN>;
chomp $data[0];
my @split = split(/ /, $data[0]);
my $itemNum = $split[0];
my $selectMin = $split[1];
my $selectMax = $split[2];
chomp $data[1];
my @itemList = split(/ /, $data[1]);

@itemList = sort {$b <=> $a} @itemList;

my %cnt;
foreach my $key (@itemList){
	$cnt{$key}=$cnt{$key}+1;
}

#print @itemList;

my $max=-1;
my $pat=0;
for $selectNum ($selectMin..$selectMax) {
	my $sum=0;
	for($j = 0;$j < $selectNum; $j++) {
		$sum+=$itemList[$j];
	}
	if($max < $sum/$selectNum) {
		$max = $sum/$selectNum;

		my $useCount=0;
		for (0..$selectNum-1) {
			if($itemList[$_] == $itemList[$selectNum-1]) { $useCount++; }
		}
		my $totalCount=0;
		for (@itemList) {
			if($_ == $itemList[$selectNum-1]) { $totalCount++; }
		}

		my $addPattern=1;
		for(1..$useCount) {
			$addPattern=$addPattern*($totalCount+1-$_);
			$addPattern=$addPattern/$_;
		}
		$pat = $addPattern;
	} elsif($max == $sum/$selectNum) {

		my $useCount=0;
		for (0..$selectNum-1) {
			if($itemList[$_] == $itemList[$selectNum-1]) { $useCount++; }
		}
		my $totalCount=0;
		for (@itemList) {
			if($_ == $itemList[$selectNum-1]) { $totalCount++; }
		}

		my $addPattern=1;
		for(1..$useCount) {
			$addPattern=$addPattern*($totalCount+1-$_);
			$addPattern=$addPattern/$_;
		}
		$pat += $addPattern;
	}
}

print $max, "\n";
print $pat, "\n";


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

bool isM(int i){
  return 1 <= i && i <= 12;
}


int main(){
  string s;
  cin >> s ;
  int intof0 = '0';
  int int0 = (s.at(0) -intof0)* 10 + (s.at(1) - intof0);
  int int1 = (s.at(2) -intof0)* 10 + (s.at(3) - intof0);
  
  //YY ...  <= 12 || ==0
  //MM ...  0 < && <1 
  if(isM(int0) && !isM(int1)){
    cout << "MMYY"<< endl;
  }
  else if(isM(int0) && isM(int1)){
    cout << "AMBIGUOUS"<< endl;
  }
  else if(!isM(int0) && isM(int1)){
    cout << "YYMM"<< endl;
  }
  else if(!isM(int0) && !isM(int1)){
    cout << "NA "<< endl;
  }
  
  return 0;
  
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long k,h,a,p,i,n;
cin>>n>>k;
long long arr[n];
long long s=0;
for(i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);
for(i=0;i<n-k;i++)
s+=arr[i];
cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 
#include <cctype>

using namespace std;

int selectionSort(int A[], int N) {
    int minv, temp;
    int count = 0;
    for (int i = 0; i < N - 1; i++) {
        minv = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[minv]) {
                minv = j;
            }
        }
        temp    = A[i];
        A[i]    = A[minv];
        A[minv] = temp;
        if (i != minv) count++;
    }

    return count;
}

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

    int count = selectionSort(A, N);

    for (int i = 0; i < N; i++) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;

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


Measured memory_bytes: 3088
K,N=map(int,input().split())
A = list(map(int, input().split())) 
l=[0]*N
#print(A[0])
ans=0
B=sorted(A)
#print(B[0])
for i in range(N-1):
  l[i]=B[i+1]-B[i]
l[N-1]=K-B[N-1]+B[0]
#print(l[2])
lsort=sorted(l)
for i in range(N-1):
  ans+=lsort[i]
print(ans)

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    cout << std::min(C, B / A) << endl;
    return 0;
}

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

int solve(vector<int> &A,int n,int i,int m){
    if(m==0) return true;
    if(i>=n) return false;
    return (solve(A,n,i+1,m)||solve(A,n,i+1,m-A[i]));
}

int main(){
    int n,q;
    cin>>n;
    vector<int> A(n);
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    cin>>q;
    vector<int> m(q);
    for(int i=0;i<q;i++){
        cin>>m[i];
    }
    for(int i=0;i<q;i++){
        if(solve(A,n,0,m[i])){
            cout<<"yes"<<endl;
        }
        else cout<<"no"<<endl;
    } 
}


Measured memory_bytes: 3076
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int mod = 1000000007;
const int N = 4005;
const int M = 8000; 
using namespace std;

int f[N + 505][N + 505], a[200005], b[200005], fac[M << 1], inv[M << 1], base, ans, n; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int fpow(int x, int y)
{
	int res = 1;
	while(y)
	{
		if(y & 1)
			res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;
		y >>= 1; 
	}
	return res; 
}

int C(int n, int m) { return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod; }

int main()
{
	n = read <int> (), base = 2002;
	for(int i = (fac[0] = 1); i <= M; i++)
		fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[M] = fpow(fac[M], mod - 2);
	for(int i = M - 1; i >= 0; i--)
		inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
	for(int i = 1; i <= n; i++)
	{
		a[i] = read <int> (), b[i] = read <int> ();
		f[base - a[i]][base - b[i]]++; 
	}
	for(int i = 1; i <= base + 2000; i++)
		for(int j = 1; j <= base + 2000; j++)
			f[i][j] = (1ll * f[i][j] + f[i - 1][j] + f[i][j - 1]) % mod;
	for(int i = 1; i <= n; i++)
	{
		ans = (1ll * ans + f[base + a[i]][base + b[i]]) % mod;
		ans = (1ll * ans - C(2 * a[i] + 2 * b[i], 2 * a[i])) % mod; 
	}
	ans = (ans + mod) % mod;
	ans = 1ll * ans * 500000004 % mod;
	printf("%d\n", ans); 
	return 0; 
}


Measured memory_bytes: 73856
#include<bits/stdc++.h>
using namespace std;
int N;
const char ahha[3]={":("};
int main()
{
	scanf("%d",&N);
	bool flag=false;
	for(int i=1;i<=N;i++)
	{
		float f=i*1.08;
		if(floor(f)==N)
		{
			printf("%d\n",i);
			flag=true;
			break;
		}
	}
	if(!flag)
	{
		printf("%s\n",ahha);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
// Not for Rating """"""""""I'm in Love with Experience :)""""""""""""""""""
void solve()
{
    ll N;cin>>N;
    std::vector<ll> A,B,C;
    int x;
    for(ll i=0;i<N;++i)
    {
        cin>>x;A.push_back(x);
    }
    for(ll i=0;i<N;++i)
    {
        cin>>x;B.push_back(x);
    }
    C=B;
    sort(C.begin(),C.end());
    ll a=0,b=0,c=0;
    do{
        c++;
        if(C==A)a=c;
        if(C==B)b=c;
    }while(next_permutation(C.begin(),C.end()));
    cout<< abs(b-a);
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int T=1;while(T--){solve();}return 0;
}/*Solved By:- RITIK AGARWAL*/

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

using namespace std;


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

  int n;
  cin >> n;
  int res = 0;
  for (int i = 1; i <= n; i += 2) {
    int sum = 0;
    for (int j = 1; j <= i; ++j) {
      if (i%j == 0) ++sum;
    }
    if (sum == 8) ++res;
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
def main():
  n = (input())
  if n[-1]== '3':
    print('bon')
  elif n[-1] == '0' or n[-1] ==  '1' or n[-1] == '6' or n[-1] == '8':
    print('pon')
  else:
    print('hon')
    
    
if __name__ == '__main__':
  main()
  

Measured memory_bytes: 9092
H,W,K = map(int, input().split())

# dp[h][w]
dp = []
for _ in range(H+1):
    dp.append([0] * W)

dp[0][0] = 1

for h in range(1,H+1):
    for w in range(0,W):
        a = 0
        b = 0
        c = 0
        
        Q = W-1
        for bit in range(1<<Q):
            invalid = False
            cur_seq = False
            for i in range(Q):
                on = (bit >> i) & 1
                if on & cur_seq:
                    invalid = True
                    break
                cur_seq = on

            # if there is sequential bar, then the combination is invalid
            if invalid:
                continue

            connected = False
            # if the combination has connection with w then count a or c
            # otherwise, inc b
            for i in range(Q):
                on = (bit >> i) & 1
                if on:
                    x = i
                    y = i+1
                    if x == w-1:
                        connected = True
                        a += 1
                    elif y == w+1:
                        connected = True
                        c += 1
            if not connected:
                b += 1

        cnt = 0
        if a > 0:
            cnt += a * dp[h-1][w-1]
        if b > 0:
            cnt += b * dp[h-1][w]
        if c > 0:
            cnt += c * dp[h-1][w+1]

        dp[h][w] = cnt

print(dp[H][K-1] % 1000000007)

Measured memory_bytes: 44652
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int>wari;
  int n,m;
  cin>>n>>m;

  ll res=0;

  rep(i,n)
  {
    int a;
    cin>>a;
    res+=a;
    while(a>=1)
    {
      wari.push_back(a-(a>>1));
      a>>=1;
    }
  }
  sort(all(wari),greater<int>());
//for(auto i:wari)cout<<i<<endl;
  rep(i,min((int)wari.size(),m))res-=wari[i];
  cout<<res<<endl;
  return 0;

}


Measured memory_bytes: 18536
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int n, h, m = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &h);
        if (m - h > 1) {
            printf("No\n");
            return 0;
        }
        m = max(m, h);
    }
    printf("Yes\n");
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  queue<int> q;
  q.push(a[0]);
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ans += q.front();
    q.pop();
    q.push(a[i]);
    q.push(a[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4764
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10

vector<int > A;
vector<int> seen;
int N;





int main() {
	cin >> N;
	A.assign(N, 0);
	seen.assign(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i] *= -1;
	}
	vector<int> b;
	b.push_back(A[0]);
	for (int i = 1; i < N; i++) {
		auto p = upper_bound(b.begin(), b.end(), A[i]);
		if (p == b.end()) {
			b.push_back(A[i]);
		}
		else {
			*p = A[i];
		}
	}
	cout << b.size() << endl;






	return 0;
}


Measured memory_bytes: 1660
// 深さ優先探索　計算量：O(N+M)

#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007

using namespace std;

const int limit = 50;

int n,m;
int a[limit],b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v) {
    visited[v] = true;
    for (int v2 = 0; v2 < n; ++v2) {
        if (graph[v][v2] == false) continue; // vからv2へ路があるなら次の処理へ
        if (visited[v2] == true) continue; // v2を訪れたことがないならv2へ進みdfs
        dfs(v2);
    }
}

int main(){
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    int ans = 0;
    for (int i = 0; i < m; i++)
    {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false; // 1つ目の辺を取り除く
        for (int j = 0; j < n; j++)
        {
            visited[j] = false; // visitedを初期化
        }
        dfs(0);
        bool bridge = false;
        for (int j = 0; j < n; j++)
        {
            if(visited[j] == false) bridge = true; // 訪れていない点が1つでも存在する => ”橋”が存在する
        }
        if(bridge) ans++;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true; //取り除いた辺を元に戻す
        
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[1000000];
int pre[1000000];
int suf[1000000];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)cin>>a[i],pre[i]=max(a[i],pre[i-1]);
    for (int i=n;i>=1;i--)suf[i]=max(suf[i+1],a[i]);
    for (int i=1;i<=n;i++) {
        cout<<max(pre[i-1],suf[i+1])<<endl;
    }
}

Measured memory_bytes: 10624
import collections
def main4():
    n = int(input())
    l = []
    for i in range(n):
        s = input()
        l.append((sorted(s)))
    l.sort()
    dd = collections.defaultdict(int)
    k = []
    for i in range(n):
        k.append(''.join(l[i]))
    res = 0
    for i in range(n):
        dd[k[i]]+=1
    for i in dd.values():
        res += (i*(i-1))//2
    print(res)

if __name__ == '__main__':
    main4()


Measured memory_bytes: 45984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
struct pref{
    int num,p,y;
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    ll n;
    cin >> n;
    vector<string> A(n);
    map<string,ll> B; 
    REP(i,n){
        cin >> A[i];
        sort(A[i].begin(), A[i].end());
        B[A[i]]++;
    }
    ll cnt= 0;
    for(auto x: B){
        cnt+= x.second*(x.second-1)/2;
    }
    cout << cnt << endl;
}

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

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define reP(i, x, n) for(int i=x; i<n; i++)
#define aLL(x) x.begin(), x.end()
#define pB push_back
#define eB emplace_back
#define tRav(a, x) for(auto& a: x)
#define fI first
#define sE second
#define lB lower_bound
#define uB upper_bound
#define MOD 1000000007

typedef vector<int> vec;
typedef long long ll;
typedef unsigned long long ull;

int main(){
	int h, w;cin>>h>>w;
	vector<string> ch(h);
	reP(i, 0, h)
	cin>>ch[i];
	vector<vector<int>> dp(h, vector<int>(w));
	reP(i, 0, h)
	reP(j, 0, w){
		if(i+j==0)
			dp[0][0]=(ch[0][0]=='#');
		else{
			dp[i][j]=(int)1e9;
		if(i) dp[i][j]=min(dp[i][j], dp[i-1][j]+(ch[i-1][j]=='.' and ch[i][j]=='#'));
		if(j) dp[i][j]=min(dp[i][j], dp[i][j-1]+(ch[i][j-1]=='.' and ch[i][j]=='#'));
	}
	}
	cout<<dp[h-1][w-1]<<endl;
}

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

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

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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N, ans=0, tmp=0;
vector<ll> A;
string S;

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    tmp = A[0];
    for(int i=1;i<N;i++) {
        if(tmp<A[i]) {
            tmp = A[i];
        }
        else {
            ans += tmp-A[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5340
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;
 
//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!
 
// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(1e9 + 7)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long
 
//////////////////////
const int N = 100005;


int32_t main() {
 
    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);
	
	int tt = 1;
	// cin/ >> tt;
	while(tt--) {
		int k,x;
		cin >> k >> x;
		if(k*500 >= x) cout << "Yes\n";
		else cout << "No\n";
	}
}


Measured memory_bytes: 256
a,b,c=map(int,input().split())
if(a==b and a==c):
    print("0")
    exit()
elif(a==c or a==b or b==c):
    if(a==b):
        print(abs(b-c))
    if(a==c):
        print(abs(b-a))
    if(b==c):
        print(abs(a-b))
else:
    count=0
    l=[a,b,c]
    num=min(l)
    l.remove(min(l))
    num2=min(l)
    count+=abs(num2-num)
    l.remove(min(l))
    count+=abs(num2-l[0])
    print(count)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
  public static double ex(double ox, double oy, double x1, double y1, double x2, double y2){
      double vx1 = x1-ox;
      double vy1 = y1-oy;
      double vx2 = x2-ox;
      double vy2 = y2-oy;
      return vx1*vy2-vx2*vy1;
  }
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      while(sc.hasNext()){
          double[][] p = new double[3][2];
          for(int i=0;i<3;i++){
              p[i][0] = sc.nextDouble();
              p[i][1] = sc.nextDouble();
          }
          double px = sc.nextDouble();
          double py = sc.nextDouble();

          boolean f = true;
          boolean g = true;
          for(int i=0;i<3;i++){
              double ex = ex(p[i][0], p[i][1], p[(i+1)%3][0], p[(i+1)%3][1], px, py);
              if(ex >= 0){
                  f = false;
              }
              if(ex <= 0){
                  g = false;
              }
          }
          System.out.println(f||g?"YES":"NO");
      }
  }
}
//by Tuvshee 10.05.2012
//A Point in a Triangle

Measured memory_bytes: 12000
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        rep(i, n){
          par[i] = i;
          rank[i] = 0;
          diff_weight[i] = SUM_UNITY;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); 
        w -= weight(y);
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind<int> uf(N);
    rep(i, M) {
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        if (uf.issame(l, r)) {
            int diff = uf.diff(l, r);
            if (diff != d) {
                cout << "No" << endl;
                return 0;
            }
        }
        else uf.merge(l, r, d);
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1536
#coding;utf-8
n=int(input())
data=[]
check=True
data.append(input())
for i in range(1,n):
  data.append(input())
  for j in range(i):
    if(data[i]==data[j]):
      check=False
  if(data[i-1][len(data[i-1])-1]!=data[i][0]):
    check=False
if(check==False):
  print("No")
else:
  print("Yes")


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cstdio>
using namespace std;
int main(){
	int n,a[10000],b[10000],i,Acount=0,Bcount=0;
	while(cin>>n){
		if(n==0)break;
		for(i=0;i<n;i++){
			cin>>a[i]>>b[i];
			if(a[i]>b[i])Acount+=a[i]+b[i];
			else if(a[i]<b[i])Bcount+=a[i]+b[i];
			else {
				Acount+=a[i];
				Bcount+=b[i];
			}
		}
		cout<<Acount<<" "<<Bcount<<endl;
		Acount=0;
		Bcount=0;
	}
	return 0;
}

Measured memory_bytes: 3048
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
while(1)
{
	srand((unsigned int)time(NULL));
	int d,n,m; scanf("%d%d%d",&d,&n,&m); if(!d) return 0;
	vector<int>vec; vec.clear();
	vec.pb(0);
	for(int i=2;i<=n;i++)
	{
		int x; scanf("%d",&x);
		vec.pb(x);
	}
	sort(vec.begin(),vec.end()); int s=vec.size();
	for(int i=0;i<s;i++)
	{
		vec.pb(vec[i]+d);
	}
	ll ret=0LL;
	for(int i=1;i<=m;i++)
	{
		int x; scanf("%d",&x);
		int lb=upper_bound(vec.begin(),vec.end(),x)-vec.begin();
		lb--;
		int ub=lower_bound(vec.begin(),vec.end(),x)-vec.begin();
		ret+=1LL*min(x-vec[lb],vec[ub]-x);
	}
	printf("%lld\n",ret);
}
}

Measured memory_bytes: 2100
N = int(input())
h = list(map(int,input().split()))
dp = [100010]*N
dp[0] = 0
for i in range(1,N):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N-1])

Measured memory_bytes: 13924
#include<stdio.h>
int main(){
    int n,i,x[100];
    scanf("%d",&n);

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

    for(i=n-1;i>=0;i--){
        if(i!=0){
            printf("%d ",x[i]);
        }else if(i==0){
            printf("%d",x[i]);
        }
    }

    printf("\n");

    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
void dfs(vector <int> adj[],int vis[],int u,int dp[])
{
  vis[u]=1;
  
  for(int i=0;i<adj[u].size();i++)
  {
  	if(vis[adj[u][i]]==0)
    {
      dfs(adj,vis,adj[u][i],dp);
    }
    dp[u]=max(dp[u],1+dp[adj[u][i]]);
  }
  
}
int main()
{
  int n;
  cin>>n;
  int e;
  cin>>e;
  
	vector <int> adj[n+1];
  for(int i=1;i<=e;i++)
  {
  	int x,y;
    cin>>x>>y;
    adj[x].push_back(y);
   // adj[y].push_back(x);
  }
  int vis[n+1];
  int dp[n+1];
  memset(vis,0,sizeof(vis));
  memset(dp,0,sizeof(dp));
  for(int i=1;i<=n;i++)
  {
    if(vis[i]==0)
      dfs(adj,vis,i,dp);
  }
  int mx=INT_MIN;
  for(int i=1;i<=n;i++)
  {
    if(dp[i]>mx)
      mx=dp[i];
  }
  cout<<mx<<endl;
  return 0;
  
}

Measured memory_bytes: 9856
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

int G[50][50] = {0};
const int mmod = 1000000007;

	int inv_mod(int a, int b) {
		if (a == 1) return b;
		int div = mmod / a + 1;
		return inv_mod((a * (long long)div) % mmod, (b * (long long)div) % mmod);
	}

vector<int> gnext[1003];
int v[1003],vtime;
int up[1003];

vector<int> bcc[1003];
int bcc_cnt;
int cut_vertex[1003];

pair<int,int> mystack[1003];
int top;

void dfs(int nod, int par) {
    up[nod] = v[nod] = ++vtime;
    for(int i = 0; i < gnext[nod].size(); i++){
        int next = gnext[nod][i];
        if(v[next] == 0) {
            mystack[top++] = make_pair(nod,next);
            dfs(next, nod);
            if(up[next] >= v[nod]) {
                do {
                    bcc[bcc_cnt].push_back(mystack[--top].second);
                } while( mystack[top] != make_pair(nod,next));
                bcc[bcc_cnt ++].push_back(nod);
                cut_vertex[nod] ++;
            }
            up[nod] = min(up[nod], up[next]);
        } else if(next != par)
            up[nod] = min(up[nod], v[next]);
    }
    if(par == -1 && cut_vertex[nod] == 1)
        cut_vertex[nod] = 0;
}

int neck(int k, int n) {
  int res = 0;
  for (int d=1; d<=n; d++) {
    if (n % d) continue;
    int phi = 1;
    for (int e=2; e<d; e++) if (__gcd(e, d) == 1) phi ++;
    for (int i=0; i<n/d; i++)
      phi = (phi * 1LL * k) % mmod;
    res = (res + phi) % mmod;
  }
  return (res * 1LL * inv_mod(n, 1)) % mmod;
}

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

  for (int i=0; i<m; i++) {
    int a, b;
    cin >> a >> b;
    G[a-1][b-1] = G[b-1][a-1] = 1;
    gnext[a-1].push_back(b-1);
    gnext[b-1].push_back(a-1);
  }
  for (int i=0; i<n; i++)
    if (!up[i])
      dfs(i,-1);

//  for (int i=0; i<n; i++) printf("%d\n", cut_vertex[i]);
  int res = 1;
  for (int i=0; i<bcc_cnt; i++) {
    int sz = bcc[i].size();
    int mm = 0;
    for (int j=0; j<sz; j++)
      for (int k=j+1; k<sz; k++)
        mm += G[bcc[i][j]][bcc[i][k]];
//    printf("%d %d => ", sz, mm);
    if (sz - 1 == mm) {
      for (int j = 0; j < mm; j ++) res = (res * 1LL * k) % mmod;
    }
    else if (sz == mm) {
      res = (res * 1LL * neck(k, sz)) % mmod;
    } else {
      for (int i=1; i<=mm; i++) {
        res = (res * 1LL * (k + i - 1)) % mmod;
        res = (res * 1LL * inv_mod(i, 1)) % mmod;
//        printf("%d %d\n", k+i-1, i);
      }
    }
//    printf("%d\n", res);
  }
  cout << res << endl;
}


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

typedef long long ll;

const int N = 2000006;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	
	if(n < 600)cout<<8;
	else if(n < 800) cout<<7;
	else if(n < 1000) cout<<6;
	else if(n < 1200) cout<<5;
	else if(n < 1400) cout<<4;
	else if(n < 1600) cout<<3;
	else if(n < 1800) cout<<2;
	else cout<<1;
	
	return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>
#include <limits.h> 

int main(){

	int s;
	int min, max;
	long sum;
	int t;
	

	scanf( "%d", &s );
	
	
	min = INT_MAX; 
	max = INT_MIN; 
	sum = 0;


	while( s > 0 ){
	
		scanf( "%d", &t );
	
		if( min > t ) min = t;
		if( max < t ) max = t;
		sum += t;

		s--;
	}


	printf( "%d %d %ld\n", min, max, sum );


	return 0;

}

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

int main() {
	int n;
	while(cin >> n, n) {
		vector<vector<int> > v(n);
		for(int i = 0; i < n; i++) {
			int f; cin >> f;
			v[i].resize(f);
			for(int j = 0; j < f; j++) {
				cin >> v[i][j];
			}
			sort(v[i].rbegin(), v[i].rend());
		}
		vector<long long> met(n);
		for(int i = 0; i < n; i++) met[i] = 1ll << i;
		int res = -1;
		for(int t = 0; t <= 30; t++) {
			long long a = 0, b = 0;
			for(int i = 0; i < n; i++) {
				while(v[i].size() && v[i].back() <= t) {
					v[i].pop_back();
					b |= (1ll << i);
					a |= met[i];
				}
			}
			for(int i = 0; i < n; i++) {
				if(b & (1ll << i)) met[i] |= a;
				if(met[i] == (1ll << n) - 1) {
					res = t;
				}
			}
			if(res >= 0) break;
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 3036
#include <stdio.h>

int map[50][50];
int w,h;
int a,b,i,j;
int count;

void visit(int x, int y) {

  // printf("check map[%d][%d] = %d\n",x,y,map[x][y]);

 if(map[x][y] == 1){
   map[x][y] = 0;


   if(x  < w-1) {
     //     printf("check right\n");
     visit(x+1,y);
   }if(x > 0) {
     // printf("check left\n");
     visit(x-1,y);
   }if(y > 0) {
     // printf("check down\n");
     visit(x,y-1);
   }if(y < h - 1) {
     //printf("check ue\n");
     visit(x,y+1);
   }if(x < w-1 && y < h-1) {
     // printf("check migi ue\n");
     visit(x+1,y+1);
   } if(x > 0 && y > 0 ) {
     // printf("check hidari sita\n");
     visit(x-1,y-1);
   } if(x > 0 && y < h-1) {
     // printf("check hidari ue");
     visit(x-1,y+1);
   } if(x < w-1 && y > 0) {
     //printf("check migi sita\n");
     visit(x+1,y-1);
   } 
 }



}


int main() {


 while(1) {
   count = 0;
   scanf("%d %d",&w,&h);

   if(w==0 && h == 0) break;


   for(i=0;i<h;i++) {
     for(j=0;j<w;j++) {
   scanf("%d",&a);
   map[j][i] = a;
     }
   }

   for(i=0;i<h;i++) {
     for(j=0;j<w;j++) {
   if(map[j][i] == 1) {
     count++;
     visit(j,i);
    
   }
     }
   }



   /* / check cord
   for(i=0;i<h;i++) {
     for(j=0;j<w;j++) {
   printf("%d ",map[j][i]);
     }
     printf("\n");
   }
   */

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


 }

 return 0;

}

Measured memory_bytes: 716
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(void){
	int n;
	int cnt=0;
    unsigned int a[100001]={};
    int b[100002]={};
    unsigned int c;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> c;
		if(n<c){cnt++;continue;}
		else if(b[c]>=c){
			cnt++;
		}else{
			b[c]++;
		}
		a[i]=c;
	}

	for(int i=0; i<=n; i++){
		if(b[a[i]]<a[i]){
			cnt += b[a[i]];
			b[a[i]]=0;
		}
	}

	cout << cnt << endl;


	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>


int main(int argc, char **argv){
	int a = 0;
	int b = 0;

	std::cin >> a >> b;

	std::cout << a / b << " " << a % b << " " 
		<< std::fixed << std::setprecision(6) <<
		(double)a / b << std::endl;
	
	return 0;
}

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

using namespace std;

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

    int64_t sum = 0;
    for (int i = 1; i <= N; i++) {
        if (!(!(i % 3) || !(i % 5))) {
            sum += i;
        }
    }

    cout << sum << endl;

    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  int N, M = 0;
  cin >> N;
  string S;
  map<string, int> MA;
  while (cin >> S) M = max(M, ++MA[S]);
  for (auto ma : MA) if (ma.second == M) cout << ma.first << "\n";  
}

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

int X[500][500];
int Y[500][500];

int main() {
	int H,W,cnt;
	cin>>H>>W;
	cnt=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>X[i][j];
			if(X[i][j]%2==0)X[i][j]=-1;
			else X[i][j]=1;
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(X[i][j]<1){
				
			}
			else if(j==(W-1)){
				if(i==(H-1))break;
				else {
					X[i][j]*=-1;
					X[i+1][j]*=-1;
					Y[i][j]=2;
					//cout<<i+1<<" "<<j+1;
					//cout<<i+2<<" "<<j+1<<endl;
					cnt++;
				}
			}else{
				X[i][j]*=-1;
				X[i][j+1]*=-1;
				Y[i][j]=1;
				//cout<<i+1<<" "<<j+1;
				//cout<<i+1<<" "<<j+2<<endl;
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(Y[i][j]==2){
				cout<<i+1<<" "<<j+1<<" "<<i+2<<" "<<j+1<<endl;
			}else if(Y[i][j]==1){
				cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4096
#include "bits/stdc++.h"
using namespace std;
int N, M;
vector<pair<int,int>>adj[100005];
int dist[100005];
bool vis[100005];
bool dfs(int u, int cur){
  if(vis[u]){
    if(dist[u] != cur)
      return 0;
    return 1;
  }

  vis[u] = 1;
  dist[u] = cur;
  bool ret = 1;
  for(auto v : adj[u])ret &= dfs(v.first, cur + v.second);
  return ret;
}
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;

  while(M--){

    int u, v, w;
    cin >> u >> v >> w;

    adj[u].push_back(make_pair(v,w));
    adj[v].push_back(make_pair(u,-w));

  }
  bool f = 1;
  for(int i = 1; i <= N; i++)if(!vis[i])f &= dfs(i,0);
  cout  << ( f ? "Yes\n" : "No\n");
}


Measured memory_bytes: 12160
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, P> PP;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  while(cin>>N>>M,N||M) {
    vector<PP> data(M);
    bool vir[N+1]; CLR(vir);
    vir[1] = true;
    FOR(i,0,M) {
      ll t;
      int s, d;
      cin >> t >> s >> d;
      data[i] = PP(t, P(s, d));
    }
    sort(data.begin(), data.end());
    FOR(i,0,M) {
      if(vir[data[i].second.first]) {
        vir[data[i].second.second] = true;
      }
    }
    int ans = 0;
    FOR(i,1,N+1) {
      ans += vir[i];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3376
// AtCoder ABC109: B - 1 Dimensional World's Tale
// 2019.9.12 bal4u

#include <stdio.h>
#include <stdlib.h>

int N, M, X, Y;
int main()
{
	int i, x, y, mi, ma;
	
	scanf("%d%d%d%d", &N, &M, &X, &Y);
	if (X >= Y) goto No;
	ma = X, mi = Y;
	for (i = 0; i < N; i++) {
		scanf("%d", &x);
		if (x > ma) ma = x;
	}
	for (i = 0; i < M; i++) {
		scanf("%d", &y);
		if (y < mi) mi = y;
	}
	if (ma < mi) puts("No War");
	else {
No:		puts("War");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

string s;
ll m[30];
ll ans = INF;
int main(){
  cin >> s;
  rep(i,26){
    ll t = 0;
    rep(j,s.size()){
      if(s[j] == 'a' + i){
        m[i] = max(m[i],t);
        t = 0;
      }
      else{
        t++;
      }
    }
    if(t == s.size()) continue;
    m[i] = max(m[i],t);
    ans = min(ans,m[i]);
  }
  cout << ans << endl;
}


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

int A[100005];

int partition(int p, int r) {
    int x = A[r];
    int i = p - 1;
    for (int j=p; j<r; j++) {
        if (A[j] <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i + 1;
}

int main() {
    int n;
    cin >> n;
    for (int i=0; i<n; i++) cin >> A[i];
    int idx = partition(0, n-1);
    for (int i=0; i<n; i++) {
        if (i == idx) cout << "[";
        cout << A[i];
        if (i == idx) cout << "]";
        cout << (i != n-1 ? " " : "\n");
    }
}


Measured memory_bytes: 3372
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string S, T; int pos;
int solve() {
	if (T[pos] == '0') { pos++; return 0; }
	if (T[pos] == '1') { pos++; return 1; }
	if (T[pos] == '2') { pos++; return 2; }
	if (T[pos] == '-') { pos++; return 2 - solve(); }
	if (T[pos] == '(') {
		pos++; int a = solve(); char c = T[pos];
		pos++; int b = solve(); pos++;
		if (c == '+') return max(a, b);
		if (c == '*') return min(a, b);
	}
	return 0;
}
int main() {
	while (true) {
		cin >> S;
		if (S == ".") break;
		int ret = 0;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					T = S;
					for (int l = 0; l < S.size(); l++) {
						if (S[l] == 'P') T[l] = i + 48;
						if (S[l] == 'Q') T[l] = j + 48;
						if (S[l] == 'R') T[l] = k + 48;
					}
					pos = 0;
					if (solve() == 2) {
						ret++;
					}
				}
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

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

int n,k,cnt,t;
long long ans=0;

int main(){
    scanf("%d%d",&n,&k);
    cnt=n/k;
    t=n%k;
    for (int i=1;i<=n;i++){
    	int mod=i%k,p=cnt,pp,x1,x2;
    	if ((2*mod)%k!=0) continue;
    	if (mod==0){
    		ans+=(long long)cnt*cnt;
    		continue;	
    	}
    	pp=k-mod;
    	if (t!=0 && mod<=t) x1=cnt+1;
    	  else if (t!=0 && mod>t) x1=cnt;
    	    else if (t==0) x1=cnt;
    	if (t!=0 && pp<=t) x2=cnt+1;
    	  else if (t!=0 && mod>t) x2=cnt;
    	    else if (t==0) x2=cnt;
    	ans+=(long long)x1*x2;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll r, g, b, n;
    cin >> r >> g >> b >> n;
    ll ans = 0;
    rep(i, n / r + 1) {
        rep(j, (n - i * r) / g + 1) {
            ll remain = n - i * r - j * g;
            if (remain % b == 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256