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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = 1e15;

struct Edge{
  LL to, cost;

  Edge(LL t, LL c): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
typedef vector< vector<Edge> > Graph;

void Dijkstra(const Graph& edges, vector<LL>& d, int s){
  using Type = PLL;
  priority_queue<Type, vector<Type>, greater<Type> > pq;
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  pq.push(MP(0,s));

  while(!pq.empty()){
	Type pii = pq.top(); pq.pop();
	int v = pii.second;
	if(d[v] < pii.first) continue;
	for(unsigned int i=0;i<edges[v].size();++i){
	  const Edge& e = edges[v][i];
	  if(d[e.to] > d[v] + e.cost){
		d[e.to] = d[v] + e.cost;
		pq.push(MP(d[e.to], e.to));
	  }
	}
  }
}

int idx(int u, int v, int flag){
  return (u * 50 + v) * 2 + flag;
}

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

  int N, M;
  cin >> N >> M;

  VL xs(M), ys(M), ts(M);
  REP(i,M){
	cin >> xs[i] >> ys[i] >> ts[i];
	--xs[i];
	--ys[i];
  }

  LL V, A, B, C;
  cin >> V >> A >> B >> C;
	
  Graph G(500*50*2);
  REP(i,M){
	REP(k,C){
	  G[idx(xs[i], k, 0)].EB(idx(ys[i], (A*k+B)%C, 0), k*ts[i]);
	  G[idx(ys[i], k, 0)].EB(idx(xs[i], (A*k+B)%C, 0), k*ts[i]);
	  G[idx(xs[i], k, 1)].EB(idx(ys[i], (A*k+B)%C, 1), k*ts[i]);
	  G[idx(ys[i], k, 1)].EB(idx(xs[i], (A*k+B)%C, 1), k*ts[i]);
	}
  }
  REP(k,C)
	G[idx(N-1, k, 0)].EB(idx(N-1, k, 1), 0);

  VL d(500*50*2);
  Dijkstra(G, d, idx(0, V, 0));

  LL ans = INF;
  REP(k,C)
	mini(ans, d[idx(0, k, 1)]);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 29292
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 30000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 998244353LL
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long powering(long long now,long long now_go){
	long long ans = 1;
	while (now_go != 0) {
		if (now_go % 2 == 1) {
			ans *= now;
			ans %= MAX_MOD;
		}
		now *= now;
		now %= MAX_MOD;
		now_go /= 2;
	}
	return ans;
}
vector<long long> calc(vector<long long> a, vector<long long> b) {
	long long k = sqrt(a.size());
	vector<long long> ans;
	for (int i = 0; i < k; ++i) {
		for (int q = 0; q < k; ++q) {
			//ans[i][q]を計算する
			long long geko = 0;
			for (int t = 0; t < k; ++t) {
				geko += a[i * k + t] * b[t * k + q];
				geko %= MAX_MOD;
 			}
			ans.push_back(geko);
		}
	}
	return ans;
}
vector<long long> powered(vector<long long> a, long long n) {
	vector<long long> ans = a;
	n--;
	while (n != 0) {
		if (n % 2 == 1) {
			ans = calc(ans, a);
		}
		a = calc(a, a);
		n /= 2;
	}
	return ans;
}
long long inv(long long now) {
	return powering(now, MAX_MOD - 2LL);
}
int main() {
	int n, k;
	cin >> n >> k;
	if (k == 1) {
		cout << 0 << endl;
		return 0;
	}
	n -= k;
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		
		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();
		int l = 0;
		int r = w;
		int u = h;
		int d = 0;
		for(int  i = 0;i < n;i++){
			int x = sc.nextInt();
			int y = sc.nextInt();
			int a = sc.nextInt();
			if(a == 1){
				l = Math.max(l, x);
			}else if(a == 2){
				r = Math.min(r, x);

			}else if(a == 3){
				d = Math.max(d, y);

			}else if(a == 4){
				u= Math.min(u,y);
			}
		}
		
		
		
		if((l >= r && (r != 0) ) ||( d >= u)  && (u != 0) ){
			System.out.println(0);
		}else{
			System.out.println( (u-d) * (r-l)   );
		}
		
		
				
	}
}

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

using namespace std;


const int INF=1e9;
const int MAX_V=1000;

int main(){

	int count=0;
	
	string s;
	cin>>s;

	for(int i=0;i<s.size();i++){
		if(s[i]=='1')count++;
	}

	cout<<count<<endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>
#include <iomanip>

using namespace std;

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

  vector<double> P = {0.0};

  for (int n=0; n<N; ++n) {
    int p;
    cin >> p;
    P.push_back((1+p)/2.0 + P.back());
  }

  double ans = 0.0;
  for (int n=K; n<=N; ++n) {
    ans = max(ans, P[n]-P[n-K]);
  }

  cout << scientific << setprecision(10) << ans << endl;

  return 0;
}


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

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

  if(a[k-1]!=2LL){
    cout << "-1" << endl;
    return 0;
  }
  long long l=2,r=2;
  for(int i=k-1;i>=0;i--){
    if(l%a[i]!=0&&(l-(l%a[i])+a[i])>r){
      cout << "-1" << endl;
      return 0;
    }else{
      l=((l+a[i]-1)/a[i])*a[i];
      r=(r/a[i])*a[i]+a[i]-1;
    }
  }
  cout << l <<" "<< r << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

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

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;


void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//最大公約数を返す関数.
long long int gcd(long long int x, long long int y){
    if (x < y) swap(x,y);
    while (y > 0){
        long long int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main() {
	int n;
	cin >> n;
	long long int ans = 0;
	rep(i,n){
		rep(j,n){
			rep(k,n){
				ans += gcd(gcd(i + 1, j + 1), k + 1);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
D,N = map(int,input().split())
count = 0

if(D == 0):
   count = N//100
   print(N + count)
elif(D == 1):
   #count = 100*N//10000
   count = N//100
   print(100*(N + count))
elif(D == 2):
   #count = 10000*N//1000000
   count = N//100
   print(10000*(N + count))
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;


typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define Pi 3.14159265
#define double
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

bool compare(pii a, pii b){
    if(a.first==b.first)return a.second<b.second;
    return a.first>b.first;
}

const int mod = 1e9 + 7;
const ll inf = ll(1e18);

ll modexp(ll x,ll n,ll k){
    if(n==0)return k;
    if(n%2==0)return modexp((x*x)%mod,n/2,k);
    return (x*modexp((x*x)%mod,n/2,k))%mod;
}

vi g[100000];map<pii,int> col;int ans=0;

void dfs(int s,int pc,int p){
    int colour=1;
    fr(i,g[s]){
        if(i==p)continue;
        else{
            if(colour==pc)colour++;
            col[{s,i}]=colour;col[{s,i}]=colour;
            ans=max(ans,colour);
            dfs(i,colour,s);
            colour++;
        }
    }
}
int main(){
    fastio;
    //clock_t tm = clock();
    int t,r,c,k,n,l,x,y,q;string s;
    vii a;
    cin>>n;
    f(i,0,n-1){
        cin>>x>>y;x--;y--;
        a.pb({x,y});g[x].pb(y);g[y].pb(x);
    }
    dfs(0,-1,-1);
    cout<<ans<<endl;
    f(i,0,n-1){
        cout<<col[a[i]]<<endl;
    }
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

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

int main(){
	/*input*/
	int n, d;	cin >> n >> d;
	/*calculation*/
	int ans = 0;
	if(n%(2*d + 1)){
		ans += n/(2*d + 1) + 1;
	}else{
		ans += n/(2*d + 1);
	}
	/*output*/
	cout << ans << endl;
}


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

int main() {
  int a, b, c, d, p;
  cin >> a >> b >> c >> d >> p;

  int ratex = a * p;
  int ratey = b;
  if (p >= c) ratey += d * (p - c);
  int rate = min(ratex, ratey);

  cout << rate << endl;

  return 0;
}

Measured memory_bytes: 3080
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iterator>
#include <valarray>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <tuple>
#include <initializer_list>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef tuple<int, int> tii;
template<typename T> ostream &operator<<(ostream &os, set<T> const &s) { if (s.size() == 0) return os << "{}"; os << "{"; decltype(s.begin()) iter; for (iter = s.begin(), ++iter; iter != s.end(); ++iter) { --iter; os << *iter << ", "; ++iter; } --iter; os << *iter << '}'; return os; }
template<typename T> ostream &operator<<(ostream &os, multiset<T> const &s) { if (s.size() == 0) return os << "{}"; os << "{"; decltype(s.begin()) iter; for (iter = s.begin(), ++iter; iter != s.end(); ++iter) { --iter; os << *iter << ", "; ++iter; } --iter; os << *iter << '}'; return os; }
template<typename T, typename U> ostream &operator<<(ostream &os, map<T, U> const &mp) { if (mp.size() == 0) return os << "{}"; os << "{" << endl; decltype(mp.begin()) iter; for (iter = mp.begin(), ++iter; iter != mp.end(); ++iter) { --iter; os << "  {" << iter->first << ", " << iter->second << "}," << endl; ++iter; } --iter; os << "  {" << iter->first << ", " << iter->second << "}" << endl << '}'; return os; }
template<typename T> ostream &operator<<(ostream &os, vector<T> const &v) { os << '['; rep(i, v.size()-1) os << v[i] << ", "; if (v.size() > 0) os << v[v.size()-1]; cerr << ']'; return os; }
template<typename T, unsigned N, unsigned Last> struct TuplePrinter { static void print(ostream &os, T const& v) { os << std::get<N>(v) << ", "; TuplePrinter<T, N + 1, Last>::print(os, v); } };
template<typename T, unsigned N> struct TuplePrinter<T, N, N> { static void print(ostream &os, T const &v) { os << std::get<N>(v); } };
template<typename... Types> ostream& operator<<(ostream &os, tuple<Types...> const &v) { os << "("; TuplePrinter<tuple<Types...>, 0, sizeof...(Types) - 1>::print(os, v); os << ")"; return os; }
template<typename T> void _dbg(T const &t) { cerr << t << endl; }
template<typename T, typename... Args> void _dbg(T const &t, Args... args) { cerr << t << " "; _dbg(args...); }
template<typename... Args> void __dbg(const char *fn, int l, Args... args) { cerr << "[" << fn << ":" << l << "] "; _dbg(args...); }
#define dbg(...) __dbg(__func__, __LINE__, __VA_ARGS__)

const ll infty = 1223372036854775807;
const double eps = 1e-8;

int main() {
	int a, b;
	cin >> a >> b;
	cout << max(0, a - 2 * b) << endl;
	return 0;
}

Measured memory_bytes: 256
N,M = list(map(int,input().split()))

WAs = [0]*(N+1)
alreadyACed = set()
AC_num = 0

for i in range(M):
    p,S = list(input().split())
    if p in alreadyACed:
        continue
    else:
        if S == "WA":
            WAs[int(p)] += 1
        elif S == "AC":
            AC_num += 1
            alreadyACed.add(p)
WA_num = 0
for i in range(N+1):
    if str(i) in alreadyACed:
        WA_num += WAs[i]

print(AC_num,WA_num)

Measured memory_bytes: 14828
n,m=input().split()
N = int(n)
M = int(m)
w_list = []
v_list = []
w1_values = []
w2_values = []
w3_values = []
w4_values = []
sum_w1_values = []
sum_w2_values = []
sum_w3_values = []
sum_w4_values = []
sum_v1 = 0
sum_v2 = 0
sum_v3 = 0
sum_v4 = 0

for i in range(N):
	w,v = input().split()
	w = int(w)
	v = int(v)
	w_list.append(w)
	v_list.append(v)

w1 = w_list[0]
for j in range(N):
	if(w_list[j] == w1):
		w1_values.append(v_list[j])

	elif(w_list[j] == w1+1):
		w2_values.append(v_list[j])

	elif(w_list[j] == w1+2):
		w3_values.append(v_list[j])

	elif(w_list[j] == w1+3):
		w4_values.append(v_list[j])

w1_values.sort()
w1_values.reverse()
w2_values.sort()
w2_values.reverse()
w3_values.sort()
w3_values.reverse()
w4_values.sort()
w4_values.reverse()

for p in range(len(w1_values)):
	sum_v1 += w1_values[p]
	sum_w1_values.append(sum_v1)

for q in range(len(w2_values)):
	sum_v2 += w2_values[q]
	sum_w2_values.append(sum_v2)

for r in range(len(w3_values)):
	sum_v3 += w3_values[r]
	sum_w3_values.append(sum_v3)

for s in range(len(w4_values)):
	sum_v4 += w4_values[s]
	sum_w4_values.append(sum_v4)


sum_w1_values.insert(0,0)
sum_w2_values.insert(0,0)
sum_w3_values.insert(0,0)
sum_w4_values.insert(0,0)

max_value = 0
count = 0
for w in range(len(sum_w4_values)):
	for x in range(len(sum_w3_values)):
		for y in range(len(sum_w2_values)):
			for z in range(len(sum_w1_values)):
				count = w+x+y+z
				weight = (w1)*z + (w1+1)*y +(w1+2)*x + (w1+3)*w
				if(count<=N and weight<=M and max_value<(sum_w1_values[z] + sum_w2_values[y] + sum_w3_values[x] + sum_w4_values[w])):
					max_value = sum_w1_values[z] + sum_w2_values[y] + sum_w3_values[x] + sum_w4_values[w]


print(max_value)

Measured memory_bytes: 3192
#include<iostream>
#include<string>
using namespace std;
int main(){
  long long a;
  string b;
  int c;
  cin>>a>>b;
  
  long long ans=0;
  ans+=a*(b[0]-'0');
  ans+=a*(b[2]-'0')/10;
  c=a*(b[2]-'0')%10*10;
  ans+=a*(b[3]-'0')/100;
  c+=a*(b[3]-'0')%100;
  ans+=c/100;
  
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int main() {
  ll k, l, cnt, a[100], ans = 0LL;
  string s;
  cin >> s >> k;
  l = s.length();
  cnt = 0LL;
  for (int i = 0; i < l; i++) {
    if (s[i] == s[0]) {
      cnt++;
    }
  }
  if (cnt == l) {
    cout << l * k / 2LL << endl;
    return 0;
  }
  for (ll i = 0LL; i < l; i++) {
    if (i == 0) {
      a[i] = 0;
    } else if (s[i] == s[i - 1]) {
      a[i] = a[i - 1];
    } else {
      a[i] = i;
      if (a[i - 1] != 0 || s[0] != s[l - 1]) {
        ans += (i - a[i - 1]) / 2LL * k;
      } else {
        ans += i / 2LL;
      }
    }
  }
  if (s[l - 1] == s[0]) {
    ans += (l - a[l - 1]) / 2LL;
    cnt = 0LL;
    for (int i = 0; i < l; i++) {
      if (a[i] == 0 || a[i] == a[l - 1]) {
        cnt++;
      }
    }
    ans += cnt / 2LL * (k - 1LL);
  } else {
    ans += (l - a[l - 1]) / 2LL * k;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def dfs(a,count,seen):
    nseen=seen[:]
    ans=0
    nseen[a] = 1;
    if count==n-1:
        return 1
    else:
        for i in g[a]:
            if not seen[i]:
                ans+=dfs(i,count+1,nseen)
        return ans
n,m=map(int,input().split())
g=[[]*n for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)
seen=[0]*n
print(dfs(0,0,seen))


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

int main() {
	int sum = -50;
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	sum += min(a, min(b, c)) + min(d, e);
	cout << sum << endl;
}

Measured memory_bytes: 3100
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

int main() {
	ll N; cin >> N;
	vector<ll> a(N); rep(i, N) cin >> a[i];

	map<ll, ll> p;
	rep(i, N) {
		p[a[i]]++;
	}

	ll ans = 0;
	auto begin = p.begin(), end = p.end();
	for (auto it = begin; it != end; it++) {
		ll key = it->first, value = it->second;
		if (value - key > 0) ans += (value - key);
		else if (value - key != 0) ans += value;
	}

	cout << ans << endl;
}

Measured memory_bytes: 7040
n, k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
book = Hash.new(0)
a.each do |x|
  book[x] += 1
end
ball = book.values.sort!
puts ball[0...(ball.size - k)].inject(:+) || 0

Measured memory_bytes: 32624
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n: i32 = iter.next().unwrap().parse().unwrap();
    println!("{}", ((n - 1) / 111 + 1) * 111);
}


Measured memory_bytes: 4352
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
x=[a, b, c, d, e, f, g, h, i]
y=[False, False, False, False, False, False, False, False, False]
z=[[0, 1, 2], [3, 4, 5], [6, 7, 8],[0,3,6], [1, 4 ,7], [2, 5, 8], [0, 4, 8], [2, 4,6]]

N = int(input())
for p in range(N):
  n = int(input())
  for q in range(9):
    if n == x[q]:
      y[q]=True
  for r in range(8):
    if y[z[r][0]] and y[z[r][1]] and y[z[r][2]]:
      print('Yes')
      exit()
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int a;
  cin >> a;
  vector<vector<int>> z(a);
  vector<int> mm;
   for(int i = 0;i < a;i++){
     int m = 0;
     cin >> m;
     for(int j = 0;j < m;j++){
       int p;
     cin >> p;
       int t;
     cin >> t;
       p *= t*2-1;
     z.at(i).push_back(p);}
   }
  int ans = 0;
  for(int bit = 0;bit < (1<<a);bit++){
    int q = 1;
    for(int j = 0;j < a;j++){
      for(int k = 0;k < z.at(j).size();k++){
      if(bit & (1<<j)){
        if(z.at(j).at(k) < 0){
      if(bit & (1 << abs(z.at(j).at(k))-1)){
        q = 0;}}
          else{if(!(bit & 1 << abs(z.at(j).at(k))-1)){
            q = 0;}}
         }
         }
    }
         if(q==1){ans = max(__builtin_popcount(bit),ans);
                 mm.push_back(bit);}
         }
         cout << ans << endl;
      
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;

int n;
int x[110], y[110], h[110];

int main(){
	cin >> n;
	for (int i = 0; i < n; i++)cin >> x[i] >> y[i] >> h[i];
	for (int i = 0; i < n; i++)if (h[i] != 0)swap(x[i], x[0]), swap(y[i], y[0]), swap(h[i], h[0]);
	for (int cx = 0; cx <= 100; cx++){
		for (int cy = 0; cy <= 100; cy++){
			bool flag = 1;
			int H = h[0] + abs(x[0] - cx) + abs(y[0] - cy);
			for (int i = 0; i < n; i++)if (h[i] != max(H - abs(x[i] - cx) - abs(y[i] - cy), 0))flag = 0;
			if (flag){
				printf("%d %d %d\n", cx, cy, H);
			}
		}
	}
}

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

//arc095_b
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(a.rbegin(), a.rend());
    int p = a[0];
    int q;
    int t = p;
    for(int i=1;i<n;i++){
        if(abs(a[i]-p/2) < t){
            t = abs(a[i]-p/2);
            q = a[i];
        }
    }
    cout<<p<<" "<<q<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
int fac[N], facw[N];
int n, m, A, B;
int ckn(int k1, int n1)
{
	if(k1 > n1) return 0ll;
	int res = fac[n1];
	res = (res * facw[n1 - k1] % MOD * facw[k1]);
	return res % MOD;
}
int powe(int x, int y)
{
	if(!y) return 1ll;
	int mid = powe(x, y/2);
	if(y % 2) return mid * mid % MOD * x % MOD;
	return mid * mid % MOD;
}
signed main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	fac[0] = 1ll; FOR(i, 1, N - 1) fac[i] = fac[i - 1] * i % MOD;
	FOR(i, 0, N - 1) facw[i] = powe(fac[i], MOD - 2);
	//cout << ckn(2, 4) << '\n'; return 0;
	cin >> n >> m >> A >> B;
	int sum = 0ll;
	for(int i = B + 1; i <= m; ++i)	{
		sum = (sum + ckn(i - 1, i + n - A - 2) * 1ll * ckn(m - i, m - i + A - 1)) % MOD;
	} 
	cout << sum;
}

Measured memory_bytes: 16000
import java.awt.*;
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        String s = in.next();
        long r = s.chars().filter(i -> i == 'R').count();
        long g = s.chars().filter(i -> i == 'G').count();
        long b = s.chars().filter(i -> i == 'B').count();

        long ans = r * g * b;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int k = j + (j - i);
                if (k >= n) {
                    break;
                }
                if (s.charAt(i) != s.charAt(j) && s.charAt(i) != s.charAt(k) && s.charAt(j) != s.charAt(k)) {
                    ans--;
                }
            }
        }

        out.println(ans);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 31772
using System;

namespace AOJ.Volume0
{
    class CaesarCipher
    {
        public static void Main()
        {
            // アルファベットのリストを作成
            char[] alpha = new char[26];
            int alpha_int = (int)'a';
            for (int i = 0; i < 26; i++)
            {
                alpha[i] = (char)alpha_int;
                alpha_int++;
            }

            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                // 改行を取り除く
                input.Trim();

                // 1文字ずつずらして復号
                // 26文字ずらすと元の文字に戻ってしまうのでずらすのは25文字まで
                // 最初から暗号化されていないケースを考慮して0文字ずらすケースも含める
                string test = "";
                for (int i = 0; i <= 25; i++)
                {
                    test = "";
                    for (int j = 0; j < input.Length; j++)
                    {
                        char bef = input[j];
                        char aft = '_';
                        // リストから検索してずらす
                        for (int k = 0; k < 26; k++)
                        {
                            if (alpha[k] == bef)
                            {
                                aft = alpha[k + i >= 26 ? k + i - 26 : k + i];
                                break;
                            }
                        }
                        // 初期値の'_'のままならアルファベット以外なのでそのまま
                        if (aft == '_') { aft = bef; }
                        test += aft;
                    }
                    // すべての文字を変換したら"the"、"this"、"that"を検索
                    if (test.IndexOf("the") >= 0 ||
                        test.IndexOf("this") >= 0 ||
                        test.IndexOf("that") >= 0)
                    {
                        // 見つかったら復号完了
                        break;
                    }
                }

                Console.WriteLine(test);
            }
        }
    }
}

Measured memory_bytes: 6324
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;
ll mod=1000000007;
ll dp[1000009][2][2];
ll finds(ll in,ll f,ll f1)
{

    if(in>n)return 0;
    //cout<<"yo "<<in<<" "<<f<<" "<<f1<<endl;
    if(in==n && f==1 && f1==1)
        return 1;
      

    if(dp[in][f][f1]!=-1)
        return dp[in][f][f1];
    ll ans=0;
    for(int i=0;i<=9;i++)
    {
        if(i==0)
        {
            ans+=(finds(in+1,1,f1)%mod);
            ans%=mod;
        }
        else if(i==9)
        {
            ans+=(finds(in+1,f,1)%mod);
            ans%=mod;
        }
        else {ans+=(finds(in+1,f,f1)%mod); ans%=mod;}

    }
    return dp[in][f][f1]=ans%mod;

}
int main()
{
    //IOS;
    //ll t;cin>>t;while(t--)
    {
        memset(dp,-1,sizeof dp);
        ll a,b,c,d,i,j,k,l,m,sum=0,temp=0,f=0,cnt=0;
        cin>>n;
        cout<<finds(0,0,0)<<endl;


    }
}


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

// while[x][y] = マス(x, y)を右上とした長方形に
//               含まれている(白マス-黒マス)の総数
int white[1000][1000];
int main() {
    int N, K;
    cin >> N >> K;

    // 黒マスを指定する条件の数
    int bnum = 0;
    // まずは2K * 2Kの範囲に絞る
    for (int i = 0; i < N; ++i) {
        int x, y, z;
        char sc;
        cin >> x >> y >> sc;
        x %= K * 2;
        y %= K * 2;
        z = (sc == 'W');
        // K * Kの範囲に絞る
        // 座標をKで割った値の偶奇で色が変わる
        z += x / K + y / K;
        z %= 2;
        x %= K;
        y %= K;
        white[x][y] += (z ? 1 : -1);
        if (z == 0)
            ++bnum;
    }

    // 2次元imosの要領で展開
    for (int x = 0; x < K; ++x) {
        for (int y = 1; y < K; ++y) {
            white[x][y] += white[x][y - 1];
        }
    }

    for (int x = 1; x < K; ++x) {
        for (int y = 0; y < K; ++y) {
            white[x][y] += white[x - 1][y];
        }
    }

    int ans = 0;
    for (int x = 0; x < K; ++x) {
        for (int y = 0; y < K; ++y) {
            // (x, y)を右上の頂点とした長方形を白く塗るパターン
            int w = white[K - 1][K - 1] - white[x][K - 1] - white[K - 1][y] +
                    white[x][y] * 2 + bnum;

            ans = max(ans, max(w, N - w));
        }
    }

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

Measured memory_bytes: 4096
#pragma GCC optimize("Ofast") 
#include<algorithm>
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long 
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    SYNC
    int n,a,b,c;
    in(n);
    int dp[n+1][3];
    dp[0][1]=0;
    dp[0][2]=0;
    dp[0][3]=0;
    l(i,1,n+1)
    {
        in(a)>>b>>c;
        dp[i][1]=a+max(dp[i-1][2],dp[i-1][3]);
        dp[i][2]=b+max(dp[i-1][1],dp[i-1][3]);
        dp[i][3]=c+max(dp[i-1][2],dp[i-1][1]);
    }
    o(max(dp[n][1],max(dp[n][2],dp[n][3])));
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;

int N;
int ruisekiwa[100000 + 10];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		ruisekiwa[a]++, ruisekiwa[b + 1]--;
	}
	for (int i = 1; i <= 100005; i++) {
		ruisekiwa[i] += ruisekiwa[i - 1];
	}
	int ans = 1;
	for (int i = 0; i <= 100005; i++) {
		if (i - 1 <= ruisekiwa[i])ans = max(ans, i);
	}
	cout << ans - 1 << endl;
	return 0;
}


Measured memory_bytes: 3476
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;


int main(){
    int n,k,ans=0;
    cin >> n >> k;
    k=k*2;
    vector<vector<int>> a(k,vector<int>(k,0)),b(2*k+1,vector<int>(2*k+1,0)),c(2*k+1,vector<int>(2*k+1,0));
    rep(i,n){
        int f,g;
        char s;
        cin >> f >> g >> s;
        if (s=='W') {
            a.at(f%k).at(g%k)--;
            if ((f%k>=k/2 && g%k<k/2) || (f%k<k/2 && g%k>=k/2)) ans++;
        }
        else {
            a.at(f%k).at(g%k)++;
            if ((f%k>=k/2 && g%k>=k/2) || (f%k<k/2 && g%k<k/2)) ans++;
        }
    }
    rep(i,2*k){
        rep(j,2*k){
                b.at(j+1).at(i)=b.at(j).at(i)+a.at(j%k).at(i%k);
                c.at(i).at(j+1)=c.at(i).at(j)+a.at(i%k).at(j%k);
        }
    }
    int u=ans;
    rep(j,k){
        rep(i,k){
            u+=-(b.at(k/2+j).at(i)-b.at(j).at(i))+(b.at(k+j).at(i)-b.at(k/2+j).at(i));
            u+=(b.at(k/2+j).at(i+k/2)-b.at(j).at(i+k/2))-(b.at(k+j).at(i+k/2)-b.at(k/2+j).at(i+k/2));
            ans=max(u,ans);
        }
        u+=-(c.at(j).at(k/2)-c.at(j).at(0))+(c.at(j).at(k)-c.at(j).at(k/2));
        u+=(c.at(j+k/2).at(k/2)-c.at(j+k/2).at(0))-(c.at(j+k/2).at(k)-c.at(j+k/2).at(k/2));
        ans=max(u,ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 143360
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

#define pb push_back
#define mp make_pair

#ifdef ONLINE_JUDGE
#define link renamelink
#define next renamenext
#define prev renameprev
#endif

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef long double ld;

inline void EnableFileIO(const string& fileName, bool local = 0) {
  if (fileName.empty()) return;
  if (local) {
    freopen((fileName + ".in").c_str(), "r", stdin);
    freopen((fileName + ".out").c_str(), "w", stdout);
    return;
  }
#ifdef ONLINE_JUDGE
  freopen((fileName + ".in").c_str(), "r", stdin);
  freopen((fileName + ".out").c_str(), "w", stdout);
#endif
}

const int INF = (1 << 30) - 1;
const LL LINF = (1LL << 61) - 1;
const double EPS = 1e-10, PI = acos(-1);
const int N=100;

int n,p;

int main() {
  // srand((int)time(0));
  // printf("Hello, world!\n");
  // EnableFileIO("");
  
  cin>>n>>p;
  LL f0=1,f1=0;
  for(int i=0;i<n;i++) {
    int a;
    cin>>a;
    a%=2;
    if(!a) {
      f0*=2;
      f1*=2;
    } else {
      LL g0=f1,g1=f0;
      f0+=g0;
      f1+=g1;
    }
  }
  
  if(p) {
    cout<<f1<<endl;
  } else {
    cout<<f0<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int N;

	scanf("%d",&N);

	if(N == 1){

		printf("Hello World\n");

	}else{

		int A,B;
		scanf("%d %d",&A,&B);
		printf("%d\n",A+B);
	}

	return 0;
}


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

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

    int A, B;
    cin >> A >> B;

    int cnt = 0;
    for (int i=A; i<=B; ++i) {
        if (i % 10 == i / 10000 && (i / 10) % 10 == (i / 1000) % 10) {
            cnt ++;
        }
    }   

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int x,y,z;
  cin>>x>>y>>z;
  x = x - z;
  cout << x / (y + z) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n;
    cin >> n;
    cout << (n + 1) / 2 << '\n';
}


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

using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }

    mint &operator/=(const mint a) { return *this *= a.inv(); }

    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

struct UnionFind {
    vector<int> d;

    UnionFind(int n = 0) : d(n, -1) {}

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int size(int x) { return -d[find(x)]; }
};

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    ll n;
    cin >> n;
    for (ll i = -1e3; i <= 1e3; ++i) {
        for (ll j = -1e3; j <= 1e3; ++j) {
            ll a = i * i * i * i * i, b = j * j * j * j * j;
            if (a - b == n) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

#define IL inline 
IL int read() {
	char ch = getchar(); int u = 0, f = 1;
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { u = (u << 1) + (u << 3) + ch - 48; ch = getchar(); }
	return u * f; 
}

const int maxn = 5e5 + 10;
int dis[maxn]; bool flag[maxn];
set<int>F[maxn];
vector<pair<int,int> >e[maxn];

int main() {
#ifdef Edgration
	freopen("1.in", "r", stdin);
#endif
	int n = read(), m = read();
	for (int i = 1; i <= m; ++i) {
		int x = read(), y = read(), c = read();
		e[x].push_back(make_pair(y, c)); e[y].push_back(make_pair(x, c));
	}	
	priority_queue<pair<int,int> >q;
	q.push(make_pair(0, 1)); 
	memset(dis, 0x3f, sizeof dis); dis[1] = 0;
	while (!q.empty()) {
		int u = q.top().second; q.pop();
		if (flag[u]) continue;
		flag[u] = 1;
		for (int i = 0; i < e[u].size(); ++i) {
			int v = e[u][i].first; int w = e[u][i].second;
			int c = F[u].count(w) ? 0 : 1;
			if (dis[v] > dis[u] + c) {
				dis[v] = dis[u] + c;
				F[v].clear();
				F[v].insert(w);
				q.push(make_pair(-dis[v], v));
			}
			else if (dis[v] == dis[u] + c) F[v].insert(w);
		}
	}
	cout << (dis[n] == 0x3f3f3f3f ? -1 : dis[n]) << endl;
	return 0;
}

Measured memory_bytes: 53620
x,y=gets.split.map!(&:to_i)
max=1009
for i in 1..1009
  if (i*0.08).to_i==x && (i*0.1).to_i==y
    if max>i
      max=i
    end
  end
end
if max==1009
  puts -1
else
  puts max
end


Measured memory_bytes: 14336
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    char op;

    while(1) {
        cin >> a >> op >> b;
        if (op == '?') {
            break;
        } else if (op == '+') {
            cout << a + b << '\n';
        } else if (op == '-') {
            cout << a - b << '\n';
        } else if (op == '*') {
            cout << a * b << '\n';
        } else {
            cout << a / b << '\n';
        }
        }
        return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> vec(N, 0);
    for (int i = 0; i < N; ++i)
    {
        cin >> vec.at(i);
    }
    int count = 0, itr = 0;
    while (vec.at(itr) != 2)
    {
        itr = vec.at(itr) - 1;
        ++count;
        if(count > N){
            cout << -1 << endl;
            return 0;
        }
    }
    count++;
    cout << count << endl;
}

Measured memory_bytes: 3788
n = gets.to_i
counts = {}
counts.default = 0
(1..n).each{|val|
    s = val.to_s
    next if s[-1] == '0'
    counts[[s[0].to_i, s[-1].to_i]] += 1
}

answer = 0
(1..9).each{|a|
    (1..9).each{|b|
        answer += counts[[a, b]] * counts[[b, a]]
    }
}
puts answer

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

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    int sum = a + b + c;
    if(sum <= 21) cout << "win" << endl;
    else cout << "bust" << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

const int N = 20;
const int MASK = (1 << 16) + 5;

int n;
bool vis[MASK];
ll a[N][N], group[MASK], dp[MASK];

int Check(int mask, int pos) {
  return mask & (1 << pos);
}

ll fun(int mask) {
  if (mask == (1 << n) - 1) {
    return 0;
  }
  ll &tmp = dp[mask];
  if (vis[mask]) {
    return tmp;
  }
  vis[mask] = 1, tmp = -1e18;
  int cur = mask ^ ((1 << n) - 1);
  //cerr << "CURMASK: " << mask << " SUBMASK OF: " << cur << endl;
  for (int i = cur; i > 0; i = (i - 1) & cur) {
    tmp = max(tmp, fun(mask | i) + group[i]);
  }
  return tmp;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%lld", &a[i][j]);
    }
  }
  int mask = 1 << n;
  for (int i = 0; i < mask; i++) {
    for (int j = 0; j < n; j++) {
      if (Check(i, j)) {
        for (int k = 0; k < n; k++) {
          if (Check(i, k)) {
            group[i] += a[j][k];
          }
        }
      }
    }
    group[i] /= 2;
    //cerr << i << ": " << group[i] << endl;
  }
  printf("%lld", fun(0));
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, K;
    cin >> N >> K;

    rep(i, N) {
        int A;
        cin >> A;
    }

    int ans = 1;
    N -= K;
    ans += N / (K - 1);
    if (N % (K - 1)) ans++;

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

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr ll MOD = 1000000007;

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

ll dp[100010];

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> a(N + 1);
  for (int i = 0; i < M; i++) {
    ll floor;
    cin >> floor;
    a[floor] = true;
  }

  dp[0] = 1;
  if (!a[1]) dp[1] = 1;

  rep(i, 2, N + 1) {
    if (a[i]) continue;
    dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
  }

  put(dp[N]);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 1792
n,m = map(int,input().split())

h = list(map(int,input().split()))

a = [list(map(int,input().split())) for i in range(m)]

good = [1] * (n+1)


for i in a:
    if h[i[0]-1] < h[i[1]-1]:
        good[i[0]] = 0
    elif h[i[0]-1] > h[i[1]-1]:
        good[i[1]] = 0
    else:
        good[i[0]] = 0
        good[i[1]] = 0

print(good.count(1)-1)


Measured memory_bytes: 32024
import java.io.*;
import java.util.*;

public class Main{
	static Scanner s=new Scanner(System.in);
	public static void main(String[] args) throws IOException{
		int n=s.nextInt(),m=s.nextInt();
		int[] in=new int[n];
		int[] r=new int[n];
		ArrayList<ArrayList<Integer>> g=new ArrayList<>(n);
		for(int i=0;i<n;i++)
			g.add(new ArrayList<>());
		for(int i=0;i<n-1+m;i++){
			int f=s.nextInt()-1;
			int t=s.nextInt()-1;
			in[t]++;
			g.get(f).add(t);
		}
		
		int root=0;
		
		for(int i=0;i<n;i++){
			if(in[i]==0) root=i;
		}
		
		ArrayDeque<Integer> q=new ArrayDeque<>();
		q.add(root);
		while(!q.isEmpty()){
			int p=q.poll();
			for(int h:g.get(p)){
				if(--in[h]==0){
					r[h]=p+1;
					q.add(h);
				}
			}
		}
		
		Arrays.stream(r).forEach(System.out::println);
	}
}

Measured memory_bytes: 102328