akhauriyash/Code-Regression huggingface dataset:
from heapq import heappop, heappush, heapify
from collections import deque

class Graph():  #non-directed
    def __init__(self, n, edge, indexed=1):
        self.n = n
        self.edge = edge
        self.indexed = indexed
        self.graph = [[] for _ in range(n)]
        for e in edge:
            self.graph[e[0] - indexed].append((e[1] - indexed, e[2]))
            self.graph[e[1] - indexed].append((e[0] - indexed, e[2]))

    def dijkstra(self, s, INF=10**18, restore_to=None):
        dist = [INF for _ in range(self.n)]
        dist[s] = 0
        heap = [(0, s)]
        prev = [None for _ in range(self.n)]
        while heap:
            cost, node = heappop(heap)
            if dist[node] < cost:
                continue
            for adj, adjcost in self.graph[node]:
                if dist[node] + adjcost < dist[adj]:
                    dist[adj] = dist[node] + adjcost
                    prev[adj] = node
                    heappush(heap, (dist[adj], adj))
        if restore_to is not None:
            g = restore_to
            if dist[g] == INF:
                return dist, False
            path = [g]
            node = g
            while node != s:
                node = prev[node]
                path.append(node)
            return dist, path[::-1]
        return dist

def dist(p, q):
    px, py = p
    qx, qy = q
    return ((px - qx)**2 + (py - qy)**2)**0.5

xs, ys, xt, yt = map(int, input().split())
s = (xs, ys)
t = (xt, yt)

N = int(input())

barrier = [tuple(map(int, input().split())) for _ in range(N)]
edge = []

edge.append((0, N + 1, dist(s, t)))

for i in range(N):
    xi, yi, ri = barrier[i]
    pi = (xi, yi)
    d = max(dist(s, pi) - ri, 0)
    edge.append((0, i + 1, d))

for i in range(N):
    xi, yi, ri = barrier[i]
    pi = (xi, yi)
    d = max(dist(t, pi) - ri, 0)
    edge.append((N + 1, i + 1, d))

for i in range(N - 1):
    for j in range(i + 1, N):
        xi, yi, ri = barrier[i]
        xj, yj, rj = barrier[j]
        pi = (xi, yi)
        pj = (xj, yj)
        d = max(dist(pi, pj) - ri - rj, 0)
        edge.append((i + 1, j + 1, d))

g = Graph(N + 2, edge, 0)

print(g.dijkstra(0)[N + 1])

Measured memory_bytes: 171288
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using Graph = std::vector<std::vector<int>>;

/// LCA (Lowest Common Ancestor) by doubling.
///
/// The calculation order is as follows:
///
/// - Construction: O(N logN)
/// - Query: O(logN)
///
/// Usage example:
///
/// ```
/// int root = 0;
/// LowestCommonAncestor lca(G, root);
///
/// for (int q = 0; q < Q; ++q) {
///   int u, v;
///   std::cin >> u >> v;
///   std::cout << lca(u, v) << std::endl;
/// }
/// ```
class LowestCommonAncestor {
public:
  LowestCommonAncestor(const Graph &G, const int root) {
    // Get size
    N = G.size();
    M = 1; // 2^{M - 1} < N <= 2^M or M = ceil(log(N - 1)) + 1
    while ((1 << M) < N)
      ++M;

    // Reserve memory
    parent.assign(N, std::vector<int>(M, -1));
    depth.assign(N, -1);

    // Set depth and immediate parent
    dfs(G, root, -1, 0);

    // Seek ancestors by doubling
    for (int k = 1; k < M; ++k)
      for (int i = 0; i < N; ++i)
        if (parent[i][k - 1] != -1)
          parent[i][k] = parent[parent[i][k - 1]][k - 1];
  }

  int operator()(int u, int v) const {
    if (depth[u] > depth[v])
      std::swap(u, v);

    // Lift `v` by `depth[v] - depth[u]` generations to align the depth
    for (int k = 0; k < M; ++k)
      if ((depth[v] - depth[u]) & (1 << k))
        v = parent[v][k];

    // Find lowest common ancestor
    if (u == v)
      return u;
    for (int k = M - 1; k >= 0; --k) {
      if (parent[u][k] != parent[v][k]) {
        u = parent[u][k];
        v = parent[v][k];
      }
    }
    return parent[u][0];
  }

private:
  int N;                                // number of nodes
  int M;                                // number of doublings
  std::vector<std::vector<int>> parent; // parent[v][d] := 2^d-th parent of v
  std::vector<int> depth;

  // Set depth and immediate parent
  void dfs(const Graph &G, const int v, const int p, const int d) {
    parent[v][0] = p;
    depth[v] = d;
    for (auto c : G[v]) {
      if (c == p)
        continue;
      dfs(G, c, v, d + 1);
    }
  }
};

int main() {
  // Input
  int n;
  std::cin >> n;

  using Graph = std::vector<std::vector<int>>;
  Graph G(n);
  for (int i = 0; i < n; ++i) {
    int K;
    std::cin >> K;
    G[i].resize(K);
    for (int k = 0; k < K; ++k) {
      int j;
      std::cin >> j;
      G[i][k] = j;
    }
  }

  // Main
  int root = 0;
  LowestCommonAncestor lca(G, root);

  int Q;
  std::cin >> Q;
  for (int q = 0; q < Q; ++q) {
    int u, v;
    std::cin >> u >> v;
    std::cout << lca(u, v) << std::endl;
  }

  return 0;
}



Measured memory_bytes: 21800
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>


#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}





int main()
{

	string s;
	cin >> s;

	int a = s.size();


	string ans = "";
	for (int i = 0; i < a; i++) {
		ans = ans + "x";
	}

	cout << ans << endl;





	return 0;



}



Measured memory_bytes: 256
#include <iostream>
#include <vector>

const int INF = 1 << 30;

int main() {
    int N, M, X;
    std::cin >> N >> M >> X;

    std::vector<int> C(N);
    std::vector<std::vector<int>> A(N, std::vector<int>(M));

    for (int i = 0; i < N; i++) {
        std::cin >> C[i];
        for (int j = 0; j < M; j++) {
            std::cin >> A[i][j];
        }
    }

    int ans = INF;
    for (int bit = 0; bit < 1 << N; bit++) {
        int money = 0;
        std::vector<int> res(M);

        for (int i = 0; i < N; i++) {
            if ((bit & 1 << i) == 0) continue;

            money += C[i];

            for (int j = 0; j < M; j++) {
                res[j] += A[i][j];
            }
        }

        bool flag = true;
        for (int i = 0; i < M; i++) {
            if (res[i] < X) flag = false;
        }

        if (flag) ans = std::min(ans, money);
    }

    std::cout << (ans == INF ? -1 : ans) << "\n";
}

Measured memory_bytes: 3636
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
	char s;
	cin >> s;
	cout << (s == 'a' || s == 'i' || s == 'u' || s == 'e' || s == 'o' ? "vowel" : "consonant") << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N, M, Q = ds_in()

section = np.zeros((N, N), dtype=int)
for _ in range(M):
    p, q = ds_in()
    section[N-p, q-1] += 1

cumlist = np.cumsum(np.cumsum(section, axis=0), axis=1)

query = []
for _ in range(Q):
    query.append(ds_in())

for q in query:
    print(cumlist[N-q[0], q[1]-1])


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

#define int long long int 


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

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

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

    if ( abs(a - b) <= w ) { // 最初に重なってるかを判定してしまう
        cout << 0 << endl;
    } else if (b > a + w) {
        cout << b - (a + w) << endl;
    } else {
        cout << a - (b + w) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Word
import qualified Data.ByteString as BSW
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM

-- Input: s t
-- Output: arr
--   arr ! (i,j) == length of lcs of (drop i s, drop j t)
lcsTable2 :: BS.ByteString -> BS.ByteString -> U.Vector Word16
lcsTable2 s t = U.create $ do
  let !m = BS.length s
      !n = BS.length t
      !n' = n+1
  arr <- UM.replicate ((m+1) * n') 0
  forM_ [m-1,m-2..0] $ \ !i -> do
    let !x = BSW.index s i
    forM_ [n-1,n-2..0] $ \ !j -> do
      let !y = BSW.index t j
      if x == y
        then do l2 <- UM.read arr $ (i+1)*n'+(j+1)
                UM.write arr (i*n'+j) (l2 + 1)
        else do l0 <- UM.read arr $ (i+1)*n'+j
                l1 <- UM.read arr $ i*n'+(j+1)
                UM.write arr (i*n'+j) (max l0 l1)
  return arr

main = do
  s <- BS.getLine
  t <- BS.getLine
  -- BS.length s <= 3000, BS.length t <= 3000, BS.all isAsciiLower s, BS.all isAsciiLower t
  let !table = lcsTable2 s t
      !m = BS.length s
      !n = BS.length t
      !n' = n+1
  let recon !i !j | i >= m || j >= n = Nothing
                  | x == y = let !i' = i+1 ; !j' = j+1
                             in Just (x, (i', j'))
                  | table U.! ((i+1)*n'+j) >= table U.! (i*n'+(j+1)) = reconY y (i+1) j
                  | otherwise = reconX x i (j+1)
        where x = BSW.index s i
              y = BSW.index t j
      reconX !x !i !j | j >= n = Nothing
                      | x == y = let !i' = i+1 ; !j' = j+1
                                 in Just (x, (i', j'))
                      | table U.! ((i+1)*n'+j) >= table U.! (i*n'+(j+1)) = reconY y (i+1) j
                      | otherwise = reconX x i (j+1)
        where y = BSW.index t j
      reconY !y !i !j | i >= m = Nothing
                      | x == y = let !i' = i+1 ; !j' = j+1
                                 in Just (x, (i', j'))
                      | table U.! ((i+1)*n'+j) >= table U.! (i*n'+(j+1)) = reconY y (i+1) j
                      | otherwise = reconX x i (j+1)
        where x = BSW.index s i
      (result, _) = BSW.unfoldrN (fromIntegral $ table U.! 0) (\(!i,!j) -> recon i j) (0,0)
  BS.putStrLn result


Measured memory_bytes: 19580
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        while (true) {
            int H = scan.nextInt(), W = scan.nextInt();
            if (H == 0 && W == 0) {
                break;
            }

            for (int h = 0; h < H; h++) {
                if (h == 0 || h == H - 1) {
                    for (int w = 0; w < W; w++) {
                        System.out.print("#");
                    }
                } else {
                    System.out.print("#");
                    for (int i = 0; i < W - 2; i++) {
                        System.out.print(".");
                    }
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 36836
a=sorted([int(input())for _ in[0]*int(input())])[:4]
p=[]
for i in range(3):
 for d in a[i+1:4]:
  c=a[i]
  p+=[c*10**len(str(d))+d,d*10**len(str(c))+c]
print(sorted(p)[2])


Measured memory_bytes: 6024
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;

char rigHT[11]={'y','h','n','u','j','m','i','k','o','l','p'};
int main(){
  char a[40];
  while(1){
    fill(a,a+40,0);
    scanf("%s",a);
    if(a[0]=='#') break;

    int len = strlen(a);
    int res=0;
    int te=0;
    rep(i,11){
      if(rigHT[i]==a[0]) te=1;
    }
    reg(i,1,len-1){
      bool mama=true;
      rep(j,11){
        if(a[i]==rigHT[j]){mama=false; break;}
      }
      if(te==1 && !mama) continue;
      else if(te==1 && mama){res++; te=0;}
      else if(te==0 && mama) continue;
      else if(te==0 && !mama){ res++ ; te=1;}
    }
    printf("%d\n",res);
  }

  return 0;

}

Measured memory_bytes: 3160
//Date: 18-08-2020 //Author: Rishabh Paul

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

// long long solve() {
// 	int n;
// 	char c;
// 	scanf("%d\n", &n);
// 	map<int ,int> f;
// 	f[0] = 1;
// 	int s = 0;
// 	long long ans = 0LL;
// 	for (int i = 0; i < n; i++) {
// 		scanf("%c", &c);
// 		s += (c - '0') - 1;
// 		ans += f[s]++;
// 	}
// 	return ans;
// }

// int main () {
// 	int t;
// 	scanf("%d", &t);
// 	while(t--) {
// 		printf("%lld\n", solve());
// 	}
// 	return 0;
// }


// int main () {
// 	string s;
// 	cin >> s;
// 	if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S') {
// 		cout << 0 << "\n"; return 0;
// 	}
// 	if (s[1] == 'R') {
// 		if (s[0] == 'R' && s[2] == 'R') {
// 			cout << 3 << "\n"; return 0;
// 		}
// 		if (s[0] == 'R' || s[2] == 'R') {
// 			cout << 2 << "\n"; return 0;
// 		}
// 		cout << 1 << "\n"; return 0;
// 	}
// 	cout << 1 << "\n"; return 0;
// }


int main () {
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	int ans = 0;
	vector<int>::iterator ip; 
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				vector<int> t;
				t.push_back(a[i]);
				t.push_back(a[j]);
				t.push_back(a[k]);
				sort(t.begin(), t.end());
				if (t[0] + t[1] > t[2]) {
					ip = unique(t.begin(), t.end());
					t.resize(distance(t.begin(), ip));
					if (t.size() == 3) {
						ans++;
					}
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for(long long i=0; i<(long long)c; i++)
int main() {
	int x,n,t;

	cin>>x>>n;
	if (n==0){
		cout <<x<<endl;
		return 0;
	}
	vector<int>a(102);
	rep(i,102){
		a[i]=i;
	}
	rep(i,n){
		cin >>t;
		a[t]=0;
	}
//	sort(a.begin(),a.end());
	int smin=102;
	t=0;
	rep(i,102){
		if (abs(x-a[i])<smin){
			smin=abs(x-a[i]);
			t=a[i];
//			cout <<"smin="<<smin<<" t="<<t<<endl;
		}
//		else if (abs(x-a[i])==smin){
//			if (a[i]<t)	t=a[i];
//			cout <<"smin="<<smin<<" t="<<t<<endl;
//		}
	}
	cout << t<<endl;

	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
using ll = long long;
using namespace std;
int main(){
  ll n;
  cin >> n;
  vector<pair<ll,ll>> p;
  vector<ll> vec;
  for(ll i=0;i<n;i++){
      ll x,y,h;
      cin >> x >> y >> h;
      if(h>0){
      p.push_back(make_pair(x,y));
      vec.push_back(h);
      }
  }
  bool hantei1=0;
  if(p.size()==1){
      cout<<p[0].first<<" "<<p[0].second<<" "<<vec[0]<<endl;
      return 0;
  }
  for(ll i=0;i<101;i++){
      for(ll j=0;j<101;j++){
          ll h = vec[0]+abs(i-p[0].first)+abs(j-p[0].second);
          bool hantei=1;
          for(ll k=1;k<vec.size();k++){
              if(h !=  vec[k]+abs(i-p[k].first)+abs(j-p[k].second)){
                  hantei=0;
                  break;
              }
          }
          if(hantei){
              cout<< i <<" "<<j<<" "<<h<<endl;
              hantei1=1;
              break;
          }
      }
      
  }
}


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

int main(){
  int s;
  cin >> s;
  vector<int> A(1000000);
  A[0] = s;
  int i = 0;
  while(1){
    if(A[i]%2 == 0){
      A[i+1] = A[i]/2;
    }
    else{
      A[i+1] = 3*A[i] + 1;
    }
    rep(j,i){
      if(A[i] == A[j]){
        cout << i+1 << endl;
        return 0;
      }
    }
    ++i;
  }
  return 0;
}


Measured memory_bytes: 4096
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, K, S;
ll arr[100005];

int main() {
	scanf("%lld %lld %lld", &N, &K, &S);
	if(S * 2 <= 1e9) {
		int i = 0;
		while(K--) {
			arr[i] = S;
			i++;
		}
		while(i < N) {
			arr[i] = 2 * S;
			i++;
		}
	}
	else {
		int j = 0;
		while(K--) {
			arr[j] = S;
			j++;
		}
		while(j < N) {
			arr[j] = 1;
			j++;
		}
	}
	for(int i = 0; i < N; i++) {
		cout << arr[i] << " ";
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

double edge[1002][1002];
double x[1002],y[1002],r[1002];

double dist[1002];
bool visit[1002];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>x[0]>>y[0]>>x[1]>>y[1];
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>x[i+1]>>y[i+1]>>r[i+1];
	for(int i=0;i<=n+1;i++)
		for(int j=0;j<=n+1;j++)
			edge[i][j]=max(0.0,sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j]);
	dist[0]=0;
	for(int i=1;i<=1001;i++)
		dist[i]=1e20;
	int last;
	while(true){
		last=-1;
		for(int i=0;i<=n+1;i++)
			if(!visit[i])
				if(last==-1||dist[last]>dist[i])
					last=i;
		visit[last]=true;
		for(int i=0;i<=n+1;i++)
			dist[i]=min(dist[i],dist[last]+edge[i][last]);
		if(last==1)	break;
	}
	cout<<fixed<<setprecision(12)<<dist[1]<<endl;
}


Measured memory_bytes: 8192
import 'dart:io';

main(List<String> args){
  List nk=stdin.readLineSync().split(" ").map((n) => int.parse(n)).toList();
  List check = List.generate(nk[0], (index) => false);
  for(int i=0;i<nk[1];i++){
    int n = int.parse(stdin.readLineSync());
    List a = stdin.readLineSync().split(" ").map((b) => int.parse(b)).toList();
    for(int j=0;j<n;j++){
      check[a[j]-1]=true;
    }
  }
  int ans=0;
  for(int i=0;i<nk[0];i++){
    if(!check[i]){
      ans++;
    }
  }
  print(ans);
}

Measured memory_bytes: 14324
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
using namespace std;
int a[100010];
int b[100010];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        b[a[i]]++;
        b[a[i]-1]++;
        b[a[i]+1]++;
    }
    int max_=-1;
    for(int i=0;i<100010;i++)
    {
        if(b[i]>max_)
        {
            max_=b[i];
        }
    }
    printf("%d\n",max_);
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    string s; cin >> s;
    bool fd = 1;
    int ans;
    int num = (s.size() % 2 == 0 ? s.size() / 2 - 1 : s.size() / 2);
    REP(i, num){
        fd = 1;
        REP(j, i){
            if(s[j] != s[j + i + 1]) fd = 0; 
        }
        if(fd) ans = (i + 1) * 2;
    }
    cout << ans << endl;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define PI (acos(-1))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define MAXN 1123456
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;

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

  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i,0,n) cin >> a[i];
  sort(all(a));
  reverse(all(a));
  ll ans= 0;
  rep(i,k,n) {
    ans += a[i];
  }
  cout<<ans<<endl;


}

Measured memory_bytes: 1792
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    S = S[::-1]
    idx = 0
    ans = "YES"
    while idx <= len(S) - 1:
        is_ok = False
        if S[idx:idx + 5] in ("maerd", "esare"):
            is_ok = True
            idx += 5
        if S[idx:idx + 6] == "resare":
            is_ok = True
            idx += 6
        if S[idx:idx + 7] == "remaerd":
            is_ok = True
            idx += 7

        if not is_ok:
            ans = "NO"
            break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9248
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)1E9+7
#define i_5 (ll)1E9+5
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

/////////////////////////////////////////////////////
bool check(ll a,ll b){
    while(a>0&&b>0){
        if((a&1)&(b&1))return false;
        a/=2;
        b/=2;
    }
    return true;
}


int main(){
    int n;cin>>n;
    int a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=0;
    int s=0,t=0;//[s,t]
    ll sum=a[0];
    while(t<=n-1){
        while(t<=n-2){
            if(check(sum,a[t+1])){
                sum+=a[t+1];
                t++;
            }else break;
        }
        ans+=t-s+1;
      //  cout<<s<<" "<<ans<<endl;
        sum-=a[s];
        s++;
        if(s>t){
            t=s;
            sum+=a[t];
        }
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"
#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"

int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll min(ll a,ll b){return (a<b?a:b);}
ll max(ll a,ll b){return (a>b?a:b);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int main(){
  int N,A,B; cin>>N>>A>>B;
  cout << min(N*A,B);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL n;

int main()
{
	in >> n;
	std::vector<LL>a(n);
	rep(i, n) in >> a[i];
	std::sort(a.begin(), a.end());
	LL maxIdx = -1, maxNum = -114514;
	rep(i, n - 1)
	{
		if (maxNum < std::min(a[i], a[n - 1] - a[i]))
		{
			maxNum = std::min(a[i], a[n - 1] - a[i]);
			maxIdx = i;
		}
	}
	out << a[n - 1] << " " << a[maxIdx] << std::endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//無限大
const ll INF = 1LL << 60;


//------------------------------------------------
int main() {
    
    int N,W;
    cin >> N >> W;

    //Since W may be too BIG (10^9), use value as DP-index
    //value max
    int sumv_max = N*1000;

    //DP initialize
    int dp[N+1][sumv_max+1];
    rep(i,N+1) rep(j,sumv_max+1) dp[i][j] = W+1;

    //Baggage info
    int wi,vi;

    //--DP--
    for( int i = 1; i< N+1; ++i){
        //read i-th information
        cin >> wi >> vi;
        //give out
        chmin(dp[i][vi], wi);
        rep(j_sumv,sumv_max+1){
            //if exist Before-State : add
            if (j_sumv-vi>=0) chmin(dp[i][j_sumv], dp[i-1][j_sumv-vi] + wi);
            //not add
            chmin(dp[i][j_sumv], dp[i-1][j_sumv]);
        }
    }
    //----


    //rep(j_sumv,sumv_max) cout << dp[N][j_sumv] << " ";
    //cout << dp[N][sumv_max] << endl;

    //answer
    int ans =0;
    for(int j_sumv = sumv_max; j_sumv > 0; --j_sumv){
        if(dp[N][j_sumv]<=W and dp[N][j_sumv]>0){
            ans = j_sumv;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 39680
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
vector<int> ans;
 
void dfs(int i,int now){
ans.push_back(i);
if (i*now<=1e3) dfs(i*now,now);
}
 
void pre(){
for (int i=2;i*i<=1e3;++i) dfs(i*i,i);
}
 
int main(){
pre();
ans.push_back(1);
sort(ans.begin(),ans.end());
int n=read();
write(*--upper_bound(ans.begin(),ans.end(),n));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i , x , y) for(register int i = (x) , _## i = ((y) + 1) ; i < _## i ; i ++)
#define Rep(i , x , y) for(register int i = (x) , _## i = ((y) - 1) ; i > _## i ; i --)
using namespace std ;
#define int long long
using ll = long long ;
using pii = pair < int , int > ;
const static int _ = 1 << 20 ;
char fin[_] , * p1 = fin , * p2 = fin ;
inline char gc() { return (p1 == p2) && (p2 = (p1 = fin) + fread(fin , 1 , _ , stdin) , p1 == p2) ? EOF : * p1 ++ ; }
inline int read() {
	bool sign = 1 ; char c = 0 ; while(c < 48) ((c = gc()) == 45) && (sign = 0) ;
	int x = (c & 15) ; while((c = gc()) > 47) x = (x << 1) + (x << 3) + (c & 15) ;
	return sign ? x : -x ;
}
template < class T > void print(T x , char c = '\n') {
	(x == 0) && (putchar(48)) , (x < 0) && (putchar(45) , x = -x) ;
	static char _st[100] ; int _stp = 0 ;
	while(x) _st[++ _stp] = x % 10 ^ 48 , x /= 10 ;
	while(_stp) putchar(_st[_stp --]) ; putchar(c) ;
}
template < class T > void cmax(T & x , T y) { (x < y) && (x = y) ; }
template < class T > void cmin(T & x , T y) { (x > y) && (x = y) ; }
int solve(int n) {
	int cnt = 0 ;
	cnt += (n / 10) ; n /= 10 ;
	while(n) {
		cnt += (n / 5) ;
		n /= 5 ;
	}
	return cnt ;
}
signed main() {
#ifdef _WIN64
	freopen("testdata.in" , "r" , stdin) ;
#endif
	int n = read() ;
	if(n & 1) print(0) ;
	else print(solve(n)) ;
	return 0 ;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
int s[200];
int top=0;
void push(int a){
    if(top+1<200){
        top++;
        s[top]=a;
    }
}
int pop(){
    if(top!=0)
        top--;
    return s[top+1];
}
int main()
{
    char input[10];
    int left,right;
    int r=0;
    //scanf("%s",input)!=EOF
    while(1){
        cin>>input;
    if(cin.eof())break;
        if(input[0]=='+')
        {
            left=pop();
            right=pop();
            r=left+right;
            push(r);
        }
        else if(input[0]=='-')
        {
            right=pop();
            left=pop();
            r=left-right;
            push(r);
        }
        else  if(input[0]=='*')
        {
            left=pop();
            right=pop();
            r=left*right;
            push(r);
        }
        else
        {
            r=atoi(input);
            push(r);
        }
    }
    printf("%d",pop());
    printf("\n");
    return 0;
}



Measured memory_bytes: 3208
#include <stdio.h>

int main(void)
{
	int a;
	char b;
	
	scanf("%c",&b);
	
	if(b=='A')printf("T\n");
	if(b=='T')printf("A\n");
	if(b=='G')printf("C\n");
	if(b=='C')printf("G\n");
	
  return 0;
}


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

#include <cstdlib> 
void func();

int main(){
    func();
}

void func(){
    int N;cin >> N;
    int t,x,y;
    int tt = 0,xx = 0,yy = 0;
    bool ans = true;
    for(int i = 0; i < N; i++){
        cin >> t >> x >> y;
        int tmp = abs(x-xx)+abs(y-yy)-(t-tt);
        if((tmp&1)==0 && tmp<=0){}
        else{ans = false;}
        xx = x;yy = y;tt = t;
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a;
    int b;
    scanf("%d %d",&a,&b);
    if(a<=5){
        printf("0\n");
    }else if(13<=a){
        printf("%d\n",b);
    }else{
        printf("%d\n",b/2);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 20005
using namespace std;
typedef long long ll;
ll ri[N],n;
int main()
{
    scanf("%lld",&n);
    ll i,x;
    for(i=1;i<=n;i++){
        scanf("%lld",&x);
        ri[x]=i;
    }
    for(i=1;i<=n;i++){
        printf("%lld ",30000*i);
    }
    printf("\n");
    for(i=1;i<=n;i++){
        printf("%lld ",30000*(n-i)+ri[i]);
    }
}


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

int main(){
	int k,x,y,n;

	cin >> n >> k;
	cin >> x >> y;
	int i,sum =0;
	for(i=0;i<n;i++){
		sum += y;
	}
	for(i=0;i<k && i<n;i++){
		sum -= y-x;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
class Official_House
    def initialize
        @house1 = Array.new(3){Array.new(10,0)}
        @house2 = Array.new(3){Array.new(10,0)}
        @house3 = Array.new(3){Array.new(10,0)}
        @house4 = Array.new(3){Array.new(10,0)}
        @line = "####################"
    end
    
    def access(b, f, r, v)
        if b == 1 then
            @house1[f-1][r-1] += v 
        elsif b == 2 then
            @house2[f-1][r-1] += v 
        elsif b == 3 then
            @house3[f-1][r-1] += v 
        elsif b == 4
            @house4[f-1][r-1] += v 
        end
    end
    
    def display
        @house1.each do |floor|
            puts " #{floor.join(' ')}"
        end
        puts @line
        @house2.each do |floor|
            puts " #{floor.join(' ')}"
        end
        puts @line
        @house3.each do |floor|
            puts " #{floor.join(' ')}"
        end
        puts @line
        @house4.each do |floor|
            puts " #{floor.join(' ')}"
        end
    end
end

counts = gets.to_i
lines = readlines.map(&:chomp).map{|line| line.split.map(&:to_i)}
house = Official_House.new
lines.each do |line|
    b, f, r, v = line
    house.access(b, f, r, v)
end
house.display


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

int main(void) {
    int N,i,j; 
    scanf("%d",&N);
    double A[10],B[10];
    for(i=0;i<N;i++){
        scanf("%lf %lf",&A[i],&B[i]);
    }
    double sum=0.0;
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            sum+=sqrt((B[i]-B[j])*(B[i]-B[j])+(A[i]-A[j])*(A[i]-A[j]));
        }
    }
    printf("%.8lf\n",sum/(double)N);

    return 0;
}

Measured memory_bytes: 128
import numpy as np
from math import sqrt

def main():
    with open(0) as f:
        Q = int(f.readline())
        Query = [tuple(map(int, line.split())) for line in f.readlines()]
    
    p_table = makePtable(10**5)
    p_set = set(p_table)
    Like2017 = [p for p in p_table if (p+1)//2 in p_set]
    #データベースを累積和で作成
    database = np.array([0] * (10**5+1))
    for i in Like2017:database[i] = 1
    database = database.cumsum(axis=0)
    
    for l,r in Query:
        print(database[r+1] - database[l-1])

def makePtable(N):
    table = list(range(2,N+1))
    result = []
    p = 2
    while p < sqrt(N):
        p = table[0]
        result.append(p)
        table = [x for x in table if x % p != 0]
    return result + table

main()

Measured memory_bytes: 47588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <map>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i > (b); --i)
#define SZ(a) a.size()
#define ll long long
#define ull unsigned long long
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N;
    int A;
    int B;
    int C;
    int D;
    char S[200010];

    cin >> N >> A >> B >> C >> D;
    FOR(i, 0, N){
        cin >> S[i];
    }

    int pat = 0;
    //パターン１、２、３の選別
    if(A<B && B<C && C<D){
        pat = 1;
    }else if(A<B && B<D && D<C){
        pat = 2;
    }else if(A<C && C<B && B<D){
        pat = 3;
    }

    if(pat == 0){
        //エラー。場合分けできていない。
        cout << "error" << endl;
    }


    string ret = "Yes";
    if(pat == 1){
        //パターン１の場合
        FOR(i,A+1,D){
            if(S[i-1] == '#' && S[i] == '#'){
              ret = "No";
              break;
            }
        }
    }
     else if(pat == 2){
        //パターン２の場合
         FOR(i,A+1,C){
            if(S[i-1] == '#' && S[i] == '#'){
              ret = "No";
              break;
            }
        }       
        if(ret == "Yes"){
            ret = "No";
            FOR(i,B,D+1){
                if(S[i-2] == '.' && S[i-1] == '.' && S[i] == '.'){
                    ret = "Yes";
                    break;
                }
            }
        }
    }   
    else if(pat == 3){
        //パターン３の場合
        FOR(i,A,C){
            if(S[i-1] == '#' && S[i] == '#'){
              ret = "No";
              break;
            }
        }
        if(ret == "Yes"){
            FOR(i,B,D){
                if(S[i-1] == '#' && S[i] == '#'){
                    ret = "No";
                    break;
                }
            }
        }
    }

    
    cout << ret << endl;


    //文字列確認
    /*
    FOR(i, 0, N){
        cout << S[i] << " ";
    }
    cout <<endl;
    */

	return 0;
}

Measured memory_bytes: 512
n=int(input())
a = [input() for _ in range(n)]
a.sort()
dict = {}
count = 0
for i in range(n):
  k = a[i]
  if (k in dict):
    count-=dict[k]
    dict[k]=1-dict[k]
    count+=dict[k]
  else:
    dict[k]=1
    count+=1
print(count)

Measured memory_bytes: 101188
# B - Qualification simulator
N,A,B = map(int,input().split())
S = input()
domestic,foreign = 0,0

for i in range(N):
    s = S[i]
    if s=='a':
        if domestic+foreign<A+B:
            print('Yes')
            domestic += 1
        else:
            print('No')
    elif s=='b':
        if domestic+foreign<A+B and foreign<B:
            print('Yes')
            foreign += 1
        else:
            print('No')
    else:
        print('No')

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

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

    int n; cin >> n;
    vector<int> cnt(100000);
    rep(i, n) {
        int a; cin >> a;
        cnt[a]++;
    }
    int ans = 0;
    for (int i = 2; i < 100000; i++) ans = max(ans, cnt[i]+cnt[i-1]+cnt[i-2]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 100005
#define NTL -1

struct node
{
     int p,l,r;
}t[maxn];
int n,d[maxn];

void print(int u)
{
    int  i,c;
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<t[u].p<<", ";
    cout<<"depth = "<<d[u]<<", ";

    if(t[u].p==NTL) cout<<"root, ";
    else if(t[u].l==NTL) cout<<"leaf, ";
    else cout<<"internal node, ";
    cout<<"[";
    for(i=0,c=t[u].l;c!=NTL;i++,c=t[c].r)
    {
        if(i) cout<<", ";
        cout<<c;
    }
    cout<<"]"<<endl;
}
int rec (int u,int p)
{
    d[u]=p;
    if(t[u].r!=NTL) rec(t[u].r,p);
    if(t[u].l!=NTL) rec(t[u].l,p+1);
}
int main()
{
    int i,j,d,v,c,l,r;
    cin>>n;
    for(i=0;i<n;++i) t[i].p=t[i].l=t[i].r=NTL;
    for(i=0;i<n;++i)
    {
        cin>>v>>d;
        for(j=0;j<d;++j)
        {
            cin>>c;
            if(j==0) t[v].l=c;
            else t[l].r=c;
            l=c;
            t[c].p=v;
        }
    }
    for(i=0;i<n;++i)
        {
            if(t[i].p==NTL) r=i;
        }
        rec(r,0);
        for(i=0;i<n;++i) print(i);
    return 0;
}

Measured memory_bytes: 7760
n, l = (int(xi) for xi in input().split())

a = int(n*(l-1)+n*(n+1)/2)

# print(a)
if 0<1-l<n+1: print(a)
if 1-l<1: print(a-(l+1-1))
if n<1-l: print(a-(l+n-1))


Measured memory_bytes: 9056
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))

N = int(input())
xy = []
field = defaultdict(int)
for _ in range(N):
    x, y = inpl()
    xy.append((x,y))
    field[(x,y)] = 1
xy.sort()

pq = set()
for i in range(N):
    for j in range(i+1,N):
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        p, q = x2-x1, y2-y1
        pq.add((p,q))

ans = N
for p, q in pq:
    removed = defaultdict(int)
    cost = 0
    for x, y in xy:
        if removed[(x,y)]:
            continue
        else:
            removed[(x,y)] = 1
            cost += 1
            while True:
                x += p
                y += q
                if field[(x,y)]:
                    removed[(x,y)] = 1
                else:
                    break
    if cost < ans:
        ans = cost

print(ans)

Measured memory_bytes: 48240
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int H, W;
		while (true) {
			H = sc.nextInt();
			W = sc.nextInt();
			if (H == 0) break;
			int aH = 999;
			int aW = 999;
			for (int i = 1; i <= 150; ++i) {
				for (int j = i+1; j <= 150; ++j) {
					if (compare(H, W, i, j) && compare(i, j, aH, aW)) {
						aH = i;
						aW = j;
					}
				}
			}
			System.out.println(aH + " " + aW);
		}
	}

	static boolean compare(int h1, int w1, int h2, int w2) {
		int d1 = h1 * h1 + w1 * w1;
		int d2 = h2 * h2 + w2 * w2;
		return d1 == d2 ? h1 < h2 : d1 < d2;
	}

}

Measured memory_bytes: 20588
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <iomanip>
#include <queue>
#include <deque>
#include <sstream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <map>
#include <utility>
using namespace std;

#define s(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define ss(n) scanf("%s",&n)
#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795

int hps[100001];

bool can(ll count, int n, int a, int b) {
	ll need = 0;
	for(int i = 0; i < n; i++) {
		ll hp = hps[i];
		hp-= b*count;
		if(hp > 0) {
			if(hp%(a-b) == 0) {
				need+= hp/(a-b);
			} else {
				need+= hp/(a-b)+1;
			}
		}
	}
	if(need <= count) {
		return true;
	}
	return false;
}

int binary(int n,int a, int b,int from, int to) {
	if(from >= to) {
		return from;
	}
	int mid = (from+to)/2;
	if(can(mid,n,a,b)) {
		return binary(n,a,b,from,mid);
	} else {
		return binary(n,a,b,mid+1,to);
	}
}

int main() {
	int n,a,b;
	cin >> n >> a >> b;
	for(int i = 0; i < n; i++) {
		cin >> hps[i];
	}
	//cout << can(685714286,n,a,b);
	cout << binary(n,a,b,1,1000000001);
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <math.h>
using namespace std;

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define PB push_back
#define putn(x,n) cout<< fixed<< setprecision(n)<< x << endl;
typedef long long ll;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	vector<int> d;
	cin>>n;
	int x;
	rep(i,0,n){
		cin>>x;
		d.PB(x);
	}
	sort(d.begin(),d.end());
	
	x=1;
	rep(i,1,n){
		if(d[i]>d[i-1])x++;
	}
	cout<<x<<endl;
		

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

/*関数f*/
int f(int n){
	if(n % 2 == 0)	return n / 2;
	else	return n * 3 + 1;
}

int main(void){
	int s, i, n, m = 0, a[10000];
/*s入力*/
	do{
		scanf("%d", &s);
	}while(s < 0 || s > 100);

	a[0] = s;
/*aの中身*/
	for(i = 1; m == 0; i++){
		a[i] = f(a[i - 1]);
		for(n = 0; n < i; n++){
			if(a[n] == a[i])	m = i + 1;
		}
			
	}
	printf("%d\n", m);

	return 0;
}

Measured memory_bytes: 128
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


class UnionFind:
    def __init__(self,n):
        self.par = [i for i in range(n+1)]  # 親のノード番号
        self.rank = [0]*(n+1)
        self.X = [1]*(n+1)

    def find(self,x):  # xの根のノード番号
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self,x,y):  # x,yが同じグループか否か
        return self.find(x) == self.find(y)

    def unite(self,x,y):  # x,yの属するグループの併合
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            x,y = y,x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.par[y] = x
        self.X[x] += self.X[y]


N,M = MI()
UF = UnionFind(N)
for i in range(M):
    a,b = MI()
    if not UF.same_check(a,b):
        UF.unite(a,b)

print(max(UF.X))


Measured memory_bytes: 90492
#include <bits/stdc++.h>
using ll = long long;
constexpr int DEBUG = 0;
using namespace std;
int main() {
    string s;
    cin >> s;
    
    int n = s.size();
    if (n < 4) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    if (stoi(s.substr(0, 4)) % 2019 == 0)
        ans++;
    
    vector<ll> m(2019, 0);
    int fir = stoi(s.substr(0, 4));
    m[(2019 - (fir * 10 % 2019)) % 2019]++;
    int sec = stoi(s.substr(1, 3));
    m[(2019 - (sec * 10 % 2019)) % 2019]++;
    for (int i = 4; i < n; i++) {
        if (DEBUG >= 1) {
            cout << "\n" << s.substr(0, i) << endl;
            for (int j = 0; j < 2019; j++) {
                if (m[j] != 0)
                    cout << j << ":" << m[j] << endl;
            }
        }
        
        int c = s[i] - '0';
        if (m[c] > 0) {
            ans += m[c];
        }
        vector<ll> m2(2019, 0);
        for (int j = 0; j < 2019; j++) {
            int id = (j * 10 - c * 10 + 2019) % 2019;
            m2[id] = m[j];
        }
        int nxt = stoi(s.substr(i-2, 3));
        m2[(2019 - (nxt * 10 % 2019)) % 2019]++;
        m = m2;        
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3760
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author jcg
 */

#include <iostream>

#include <iostream>

class ADodecagon
{
public:
    void solve(std::istream& in, std::ostream& out)
    {
        int N;
        in >> N;
        out << 3 * N * N << '\n';
    }
};


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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

const ll prime = 10000000000 + 7;
const ld PI = 2 * acos(0.0);

int main() {

	ld a, b, x;
	cin >> a >> b >> x;
	ld t, c;

	if (2 * x < (a * a * b)) {
		c = ld(a * b * b) / ld(2.0 * x);
		t = atan(c);
		t = t * ld(180) / PI;
	}
	else {
		c = ld(2.0 * (a * a * b - x)) / ld(a * a * a);
		t = atan(c);
		t = t * ld(180) / PI;
	}

	cout << fixed << setprecision(10) << t << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
#define N 500000
#define AEN 1000000000
 
int merge(int *,int,int,int);
void mergeSort(int *,int,int);
 
int n,s[N],count=0,tmp[N],x[N];
 
int main()
{
 
  int i,x;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
 
    scanf("%d",&s[i]);
 
  }
 
  mergeSort(s,0,n-1);
 
  for(i=0;i<n-1;i++){
 
    printf("%d ",s[i]);
 
  }
  printf("%d\n",s[n-1]);
 
  printf("%d\n",count);
 
  return 0;
 
}
 
 
 
void mergeSort(int A[],int left,int right){
 
  int mid,i,j,k;
 
  if(left>=right) return;
 
  mid=(left+right)/2;
 
  mergeSort(A,left,mid);
  mergeSort(A,mid+1,right);
 
  for(i=left;i<=mid;i++){
    tmp[i]=A[i];}
 
  for(i=mid+1,j=right;i<=right;i++,j--){
    tmp[i]=A[j];
  }
 
  i=left;
  j=right;
 
  for(k=left;k<=right;k++){
 
    if(tmp[i]<=tmp[j]) A[k]=tmp[i++];
    else A[k]=tmp[j--];  
 
    count++;
  }
}

Measured memory_bytes: 4508
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;
string s;
string dp[6100];
int ps[6100];
int go[6100];
vector<int> pa, pb;

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> s;
	for (int i = 0; i < 2 * n; ++i) {
		if (s[i] == 'a') {
			ps[i] = pa.size();
			pa.push_back(i);
		}
		else {
			ps[i] = pb.size();
			pb.push_back(i);
		}
	}
	for (int i = 0; i < n; ++i)
		go[pa[i]] = pb[i], go[pb[i]] = pa[i];
	dp[2 * n] = "";
	for (int i = 2 * n - 1; i >= 0; --i) {
		dp[i] = dp[i + 1];
		if (go[i] < i)
			continue;
		if (s[i] == 'b') {
			string cur;
			int pos = i;
			int cnt = 0;
			for (int j = i; j < 2 * n; ++j) {
				if (s[j] == 'b')
					cur += 'b', pos = j + 1, ++cnt;
				else if (go[j] >= i) {
					pos = j + 1;
					cur += 'a';
					--cnt;
					if (cnt == 0)
						break;
				}
			}
			dp[i] = max(dp[i], cur + dp[pos]);
		}
		else {
			dp[i] = max(dp[i], "ab" + dp[go[i] + 1]);
		}
	}
	cout << dp[0] << "\n";
	return 0;
}




Measured memory_bytes: 14720