akhauriyash/Code-Regression huggingface dataset:
n, k = gets.chomp!.split(" ").map(&:to_i)
a_n = gets.chomp!.split(" ").map(&:to_i).sort!
f_n = gets.chomp!.split(" ").map(&:to_i).sort!.reverse!

sum = Array.new(n, 0)
min = 0
max = 0
n.times do |i|
    sum[i] = a_n[i] * f_n[i]
    if max < sum[i]
        max = sum[i]
    end
end

ans = (0..max).bsearch {|mid|
    count = k
    n.times do |i|
        next if sum[i] < mid

        y = mid / f_n[i]
        count -= (a_n[i] - y)
    end
    if count >= 0
        true
    else
        false
    end
}

puts ans


Measured memory_bytes: 31352
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();
    let v = read_vec::<u32>();

    let v2 = v.into_iter().rev().collect::<Vec<u32>>();
    for i in 0..n {
        if i == n - 1 {
            println!("{}", v2[i]);
        } else {
            print!("{} ", v2[i]);
        }
    }
}



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

string letter(int a){
  switch(a){
  case 0:
    return "a";
  case 1:
    return "b";
  case 2:
    return "c";
  case 3:
    return "d";
  case 4:
    return "e";
  case 5:
    return "f";
  case 6:
    return "g";
  case 7:
    return "h";
  case 8:
    return "i";
  case 9:
    return "j";
  case 10:
    return "k";
  case 11:
    return "l";
  case 12:
    return "m";
  case 13:
    return "n";
  case 14:
    return "o";
  case 15:
    return "p";
  case 16:
    return "q";
  case 17:
    return "r";
  case 18:
    return "s";
  case 19:
    return "t";
  case 20:
    return "u";
  case 21:
    return "v";
  case 22:
    return "w";
  case 23:
    return "x";
  case 24:
    return "y";
  case 25:
    return "z";
  }
}

string name(ll n){
  string name="";
  
  while(n>0){
    n--;
    string first=letter(n%26);
    name=first+name;
    n/=26;
 }
  return name;
}

int main(){
  ll n;
  cin >> n;
  cout << name(n) << endl;
}


Measured memory_bytes: 3596
#include <algorithm>
#include <cassert>
#include <iostream>
#include <memory>
#include <numeric>

#include <array>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cstring>
#include <ostream>
#include <type_traits>
#include <utility>
#include <chrono>
#include <random>

#ifdef ONLINE_JUDGE
#pragma GCC optimize ("O3")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

using namespace std;

using uint64 = uint64_t;
using int64 = int64_t;
using uint32 = uint32_t;
using vi = vector<int>;

#define seq(i,a,b) for (int i = (a); i < (b); ++i)
#define rev(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define dbg(x) {cerr << #x << ": " << x << endl;}

int main(int argc, char *argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string s; cin >> s;
  string t; cin >> t;

  int res = 1000000000;
  seq(i,0,sz(s)-sz(t)+1) {
    int cnt = 0;
    seq(j,0,sz(t)) {
      cnt += s[i+j] != t[j];
    }
    res = min(cnt, res);
  }
  cout << res << endl;
}


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

instructions = []
for _ in range(M):
    a = list(map(int, input().split()))
    instructions.append(a)
instructions.sort(key=lambda x:x[1])

ans = 0
current = 0
for a, b in instructions:
    if current < a: #過去の条件ではまだ満たしてない
        current = b-1
        ans += 1
print(ans)


Measured memory_bytes: 28700
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  uint64 n;
  cin >> n;
  if (n & 1) {
    cout << "0\n";
    return;
  }
  uint64 ans = 0;
  for (uint64 i = 5; i <= n; i *= 5) {
    ans += n / (2 * i);
  }
  cout << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

typedef long long LL;
typedef vector<int> VI;

vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

int main() {
  int X;
  cin >> X;
  vector<int> primes = sieve_of_eratosthenes(1000000);
  for (int i = 0; i < primes.size(); i++) {
    if (primes[i] >= X) {
      cout << primes[i] << endl;
      return 0;
    }
  }
  return 0;
}


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

#define endl '\n'
#define ff first
#define ss second
#define mp make_pair

typedef long long llong;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector< vi > vvi;

void solve(){

	int n, m;
	cin >> n >> m;

	vector<int> cnt(n, 1);
	vector<bool> red(n);
	red[0] = true;

	int ans = 1;

	for(int i = 0; i < m; i++){

		int a, b;
		cin >> a >> b;
		a--; b--;

		cnt[a]--;
		cnt[b]++;
		
		if(red[a]){
			if(!red[b]) ans++;
			red[b] = true;
		}

		if(cnt[a] == 0){
			if(red[a]) ans--;
			red[a] = false;
		}

	}

	cout << ans;


}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif

	solve();

	return 0;
}

Measured memory_bytes: 640
s = gets.chomp.split('').map(&:to_i)
8.times do |i|
    ope = []
    3.times do |j|
        if (i & (1 << j)) > 0
            ope.push('-')
        else
            ope.push('+')
        end
    end
    hoge = ''
    3.times do |j|
        hoge += s[j].to_s + ope[j]
    end
    hoge += s[3].to_s
    if eval(hoge) == 7
        hoge += "=7"
        puts hoge
        exit
    end
end

Measured memory_bytes: 2044
N=int(input())

import math

# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

# 素数判定
def callIsPrime(input_num=1000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

# 関数の呼び出し
L=callIsPrime(55555)
count=0
ans=[]
for l in L:
    if l%5==1:
        ans.append(l)
    if len(ans)==N:
        break
print(*ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<(int)c;i++)
#define print(var) cout<<var<<endl;
#define DEBUG(var) cerr<<var<<endl;
// puts("str");

const int inf = 1000000000;//10^9

int main (){
  string T;
  cin >>T;
  rep(i,T.size()){
    if(T[i]=='?'){
      if(i>0){
        if(T[i-1]=='P'){
          T[i]='D';
        }else if(i!=T.size()-1&&(T[i+1]=='D'||T[i+1]=='?')){
          T[i]='P';
        }else{
          T[i]='D';
        }
      }else{
        if(T[i+1]=='D'){
          T[i]='P';
        }else{
          T[i]='D';
        }
      }
    }
  }
  print(T);



  return 0;

}


Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{

    string s;
    cin >> s;
    if (s[0] >= 'A' && s[0] <= 'Z')
    {
        cout << 'A' << endl;
    }
    else
    {
        cout << 'a' << endl;
    }
}


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

typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 

//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k;
ll t=1;

void solve()
{
    cin>>n;
    cout<<((n>=30)?"Yes":"No");
   
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>

using namespace std;

int main(){
    string a;
    string flag = "No";
    cin >> a;
    if (a[0] == a[1] && a[1] == a[2] || a[1] == a[2] && a[2] == a[3]) flag = "Yes";

    cout << flag << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ cin >> p.first >> p.second; return s;}
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    ll N, D, A; cin >>N>>D>>A;
    vector<pll> XH(N); cin >> XH;
    sort(all(XH));

    ll ans = 0;

    queue<pll> q;
    ll cumulative = 0;
    rep(i, N) {
        ll x = XH[i].first;
        ll h = XH[i].second;

        while (!q.empty()) {
            pll p = q.front();
            if (p.first > x) {
                break;
            } else {
                cumulative += p.second;
                q.pop();
            }
        }
        ll h_rest = h + cumulative;
        if (h_rest > 0) {
            ll c = (h_rest + A-1) / A;
            cumulative -= A * c;
            q.push(make_pair(x+2*D+1, A*c));
            ans += c;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
long long a,b,ans;
int main() {
	cin>>a>>b;
	if(a==0||b==0) {
		if(a>b) {
			cout<<abs(a-b)+1<<endl;
			exit(0);
		}
		cout<<abs(a-b)<<endl;
		exit(0);
	}
	if(a>0&&b>0) {
		if(a<b)
			cout<<abs(a-b)<<endl;
		else
			cout<<abs(a-b)+2<<endl;
	}
	if(a>0&&b<0||a<0&&b>0)cout<<abs(abs(a)-abs(b))+1<<endl;
	if(a<0&&b<0) {
		if(a==b)cout<<0<<endl;
		if(a>b)cout<<abs(abs(a)-abs(b))+2<<endl;
		if(a<b)cout<<abs(abs(a)-abs(b))<<endl;
	}
}

Measured memory_bytes: 256
s=input()
t=input()
n=len(s);k=len(t)
an=k
for i in range(n-k+1):
  a=s[i:i+k]
  ct=0
  for j in range(k):
    if a[j]!=t[j]:
      ct+=1
  an=min(an,ct)
print(an)

Measured memory_bytes: 9052
#include<iostream>
#include<queue>
using namespace std;
int D[1002][1002];
char c[1002][1002];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct Point {
    int x;
    int y;
};
queue<Point> q;
void put(int x, int y, int d){
    if(x<1 || x>1000 || y<1 || y>1000) return;
    if(D[x][y] <= d) return;
    D[x][y] = d;
    q.push({x,y});
}
int main(){
    int h, w;
    cin >> h >> w;
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
	    D[i][j] = 1e9;
            cin >> c[i][j];
	    if(c[i][j] == '#') put(i, j, 0);
        }
    }
    while(!q.empty()){
	Point p = q.front();
	q.pop();
	for (int i = 0; i < 4; ++i) {
	    put(p.x + dx[i], p.y + dy[i], D[p.x][p.y] + 1);
	}
    }
    int result=0;
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            if(D[i][j] > result) result = D[i][j];
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 13328
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A, B = sr().split()
A = int(A)
B = int(float(B) * 1000)
answer = int(A*B)//1000
print(answer)


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

int main()
{
    int n, m, x;
    scanf("%d%d", &n, &m);
    x = (n - m) * 100 + m * 1900;
    for (int i = 0; i < m; i++)
        x *= 2;
    printf("%d\n", x);

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = in.next();
        int sum = 0;
        for (int i = 0; i < 3; i++){
            if (s.charAt(i) == '1')sum++;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23760
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

ll check(ll u, ll v, ll x, ll y) {
    if (u * v > x * y) return 0;
    ll res = u;
    if (u == x || v == y || u * v == x * y) res--;

    //cout << res << endl;
    if (u == v) {
        res += max(0LL, min(x - u - 1, v - y - 1));
    }
    else if (v == u + 1) {
        if (u * v == x * y) res += max(0LL, min(x - u - 2, v - y - 2));
        else res += max(0LL, min(x - u - 1, v - y - 1));
    }
    else {
        res += max(0LL, min(x - u - 2, v - y - 2));
    }

    // cout << res << endl;

    return res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int q;
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);
        ll res = u - 1;
        ll p = (ll) u * v;
        ll g = (ll) sqrt(p);
        res = res + max(check(g, g, v, u), max(check(g, g+1, v, u), check(g, g+2, v, u)));
        cout << res << "\n";
    }
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    int k;
    cin >> k;
    vector<int> dist(k, INT_MAX);
    deque<int> dq;
    dist[1] = 1;
    dq.push_back(1);
    while (!dq.empty()) {
        int x = dq.front();
        dq.pop_front();
        if (dist[(x + 1) % k] > dist[x]) {
            dist[(x + 1) % k] = dist[x] + 1;
            dq.push_back((x + 1) % k);
        }
        if (dist[x * 10 % k] > dist[x]) {
            dist[x * 10 % k] = dist[x];
            dq.push_front(x * 10 % k);
        }
    }
    cout << dist[0] << endl;
    return 0;
}

Measured memory_bytes: 896
x = int(input())

p = 1
while p * p <= x:
    if x % p != 0:
        p += 1
        continue

    q = x // p
    a = 0
    while a < 1000:
        b = a - p
        f = a**4 + a**3 * b + a**2 * b**2 + a * b**3 + b**4
        if f == q:
            print(a, b)
            exit(0)
        a += 1
    p += 1


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

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a%b);
}

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int g = gcd(a,b);
    int cnt = 0;
    for(int i = g;; i--){
        if(g%i == 0){
            cnt++;
            if(cnt == k){
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int p[n];
	for (int i = 0; i < n; i++) cin >> p[i];
	
	sort(p, p + n);
	reverse(p, p + n);
	
	int sum = 0;
	
	for (int i = 0; i < n; i++) {
		if (i == 0) sum += (p[i] / 2);
		else sum += p[i];
	}
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
a = [int(x) for x in input().split()]
s = 0
c = Counter(a)
# print(c)
for i in c.values():
    s += i*(i-1)// 2
    
# print(s)
for j in range(n):
    t = c[a[j]]
    print(s-t+1)

Measured memory_bytes: 87756
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
	Node *cur = nil->next;
	while( cur != nil && cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList(){
	Node *cur = nil->next;
	int isf = 0;
	while(1){
		if(cur  == nil) break;
		if(isf++ > 0) printf(" ");
		printf("%d",cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t){
	if(t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main(){
	int key,n,i;
	int size = 0;
	char com[20];
	int np = 0,nd = 0;
	scanf("%d",&n);
	init();
	for(i = 0;i < n; i++){
		scanf("%s%d",com,&key);
		if(com[0] == 'i') {insert(key);np++;size++;}
		else if(com[0] == 'd') {
			if(strlen(com) > 6){
				if(com[6] == 'F') deleteFirst();
				else if(com[6] == 'L') deleteLast();
			}else{
				deleteKey(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}	

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

int main() {
  int N;
  cin >> N;
  vector<int> twoPower(0);
  for(int i=0;i<10;i++) {
    twoPower.push_back(pow(2, i));
  }
  for(int i=0;i<twoPower.size();i++) {
    if(N < twoPower[i]) {
      cout << twoPower[i-1] << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
import math
from functools import reduce
import itertools


def gcd_list(numbers):
  return reduce(math.gcd, numbers)


k = int(input())
items = list(range(1, k+1))
ans = sum(items)
ans += sum([6 * gcd_list(item) for item in itertools.combinations(items, 2)])
ans += sum([6 * gcd_list(item) for item in itertools.combinations(items, 3)])

print(ans)



Measured memory_bytes: 19612
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[3100][3100] = {};

int main(){
    long long int N, K;
    cin >> N >> K;
    DP[1][1] = 1;
    for(int i = 2; i <= N; i++){
        for(int j = 1; j <= N; j++){
            DP[i][j] = DP[i - 1][j] * j + DP[i - 1][j - 1];
            DP[i][j] %= MOD;
        }
    }
    cout << DP[N][K] << endl;
    return 0;
}


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

int main() {
  int x1, y1, x2, y2;

  cin >> x1 >> y1 >> x2 >> y2;
  int a = x2 - x1;
  int b = y2 - y1;

  cout << x2 - b << " " <<  y2 + a << " " << x1 - b << " " << y1 + a << endl;
  return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
    int a,b,C;
    cin >>a>>b>>C;
    double PI = acos(-1);
    double S,L,h;
    double c;
    c=sqrt(a*a+b*b-2*a*b*cos(C*PI/180));
    S=(a*b*sin(C*PI/180))/2;
    L=a+b+c;
    h=2*S/a;
    printf("%lf\n", S);
    printf("%lf\n", L);
    printf("%lf\n", h);
    return 0;
}


Measured memory_bytes: 3356
k = int(input())

def test_case(k):
    ans,cnt = 7,1
    
    if k % 2 == 0 or k % 5 == 0:
        return -1
    
    if k == 1 or k == 7:
        return 1
    
    while (1):
        ans = (ans * 10 + 7) % k
        cnt += 1
        
        if ans == 0:
            return cnt
        
print(test_case(k))



Measured memory_bytes: 9172
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<double, double> pdd;

map<pii, int> dp;

void solve() {
  int n, ma, mb;
  cin >> n >> ma >> mb;
  while(n--) {
    int a, b, c;
    cin >> a >> b >> c;
    map<pii, int> ndp;
    ndp[{a, b}] = c;
    for(auto out2: dp) {
      pii out = out2.first;
      if(ndp.count(out)) ndp[out] = min(ndp[out], dp[out]);
      else ndp[out] = dp[out];
      if(ndp.count({out.first + a, out.second + b})) ndp[{out.first + a, out.second + b}] = min(ndp[{out.first + a, out.second + b}], dp[out] + c);
      else ndp[{out.first + a, out.second + b}] = dp[out] + c;
    }
    dp = ndp;
  }
  int ret = 1e9;
  for(auto out: dp) {
    pii key = out.first;
    if(key.first * mb == key.second * ma) {
      ret = min(ret, out.second);
    }
  }
  if(ret == 1e9) ret = -1;
  cout << ret << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << " ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define PRINT(a)   cout << (a) << endl
#define RALL(v) rbegin(v), rend(v)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  double n, m, d;
  cin >> n >> m >> d;

  double ans;
  if(d==0){
    ans = (m-1)/n;
  }else{
    ans = 2*(n-d)/(n*n) * (m-1);
  } 
  printf("%0.10f\n",ans);
}



Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int N;
  while(cin >> N){
    vector<pair<LLI,LLI>> task;
    REP(i,N){
      LLI a,b; cin >> a >> b;
      task.push_back({b,a});
    }

    sort(ALL(task));

    bool ans = true;

    LLI sum = 0;
    
    REP(i,N){
      sum += task[i].snd;

      if(sum > task[i].fst){
	ans = false;
	break;
      }
    }

    cout << (ans ? "Yes" : "No") << endl;
  }
  
  return 0;
}


Measured memory_bytes: 6384
#include <iostream>
#include <vector>
using namespace std;
int N;
vector <int> G[3005];
int DP[3005], V[3005];
void Read()
{
    cin >> N;
    for(int i = 1; i <= N; i++)
        cin >> V[i];
    for(int i = 1; i < N; i++)
    {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
}

void DFS(int node, int father)
{
    int ans = 0;
    for(int i = 0; i < G[node].size(); i++)
    {
        int neighb = G[node][i];
        if(neighb == father)
            continue;
        if(V[neighb] >= V[node])
            continue;
        DFS(neighb, node);
        if(DP[neighb] == 0)
            ans = 1;
    }
    DP[node] = ans;
}

void Solve()
{
    int ans = 0;
    for(int i = 1; i <= N; i++)
    {
        DFS(i, 0);
        if(DP[i] == 1)
            cout << i << " ";
    }
    cout << "\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Problem A: Citation Format
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = Integer.parseInt(line);
			if (n == 0) break;

			words = br.readLine().split(" ");
			Deque<Integer> queue = new ArrayDeque<>();

			for (int i = 0; i < n; i++) {
				int next = parseInt(words[i]);
				if (i == 0) {
					queue.add(next);
				} else if (i == 1) {
					if (queue.peekLast() + 1 == next) {
						queue.add(-1);
						queue.add(next);
					} else {
						queue.add(0);
						queue.add(next);
					}
				} else {
					if (queue.peekLast() + 1 == next) {
						int prev = queue.removeLast();
						if (queue.peekLast() == -1) {
							queue.add(next);
						} else {
							queue.add(prev);
							queue.add(-1);
							queue.add(next);
						}
					} else {
						queue.add(0);
						queue.add(next);
					}
				}
			}

			StringBuilder sb = new StringBuilder();
			for (int i : queue) {
				if (i == 0) {
					sb.append(" ");
				} else if (i == -1) {
					sb.append("-");
				} else {
					sb.append(i);
				}
			}
			System.out.println(sb.toString());

		}//end while
	}//end main
}

Measured memory_bytes: 25192
//https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_a
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    ll N,K; cin>>N>>K;
    ll num=(N-1)/2+1;
    cout<<(K<=num?"YES":"NO")<<endl;
    return 0;
}

Measured memory_bytes: 256
n, m = gets.split(" ").map(&:to_i)
matrix = []
n.times do
  matrix << gets.split(" ").map(&:to_i)
end
vector = []
m.times do
  vector << gets.to_i
end
result = []
n.times do |i|
  item = matrix[i]
  temp = 0
  m.times do |j|
    temp += item[j] * vector[j]
  end
  result << temp
end
puts result

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

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

    int cnt[N] = {0};

    int d;
    for (int i = 0; i < K; ++i) {
        std::cin >> d;
        int A;
        for (int i = 0; i < d; ++i) {
            std::cin >> A;
            cnt[A-1] += 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (cnt[i] == 0) {
            ++ans;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3636
let () =
  let rec read l = function
      0 -> l
    | i -> read (read_int ()::l) (i-1)
  in
  let l = read [] 4
          |> List.sort compare
          |> List.rev
          |> Array.of_list and
      h = read_int () and
      g = read_int () in
  let score1 = l.(0)+l.(1)+l.(2) and
      score2 = if h > g then h else g in
  Printf.printf "%d\n" (score1+score2)
;;

Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e12)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int c[10][1005];
int main()
{
    int h, w, k; cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    vector<int> v;
    int wchoco, ans=INF, num;
    bool flag;

    for(int div=0; div < (1<<(h-1)); div++){
        int g=0; //グループ数
        vector<int> id(h);
        rep(i, h){
            id[i] = g;
            if(div>>i&1) g++;
        }
        g++;
        rep(i, g) rep(j, w) c[i][j] = 0;
        rep(i, h) rep(j, w) c[id[i]][j] += (s[i][j] - '0');

        num = g-1;
        vector<int> now(g);
        auto add = [&](int j){
            rep(i, g) now[i] += c[i][j];
            rep(i, g) if(now[i] > k) return false;
            return true; 
        };
        rep(j, w){
            if(!add(j)){
                num++;
                now.assign(g, 0);
                if(!add(j)){
                    num = INF;
                    break;
                }
            }
        }
        chmin(ans, num);
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val ( n, m) = readLine()!!.split(" ").map{it.toInt()}
    var cnt = 0
    var sum = 0.0
    var a = readLine()!!.split(" ").map{it.toInt()}
    for (i in 1..n) {
        sum += a[i-1]
    }
    for (i in 1..n) {
        if(a[i-1] >= sum/4/m) cnt++
    }
    if(cnt >= m) println("Yes")
    else println("No")
}

Measured memory_bytes: 37852
#include "stdio.h"

#define SQ(X) ((X)*(X))

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int A, B, O;
  int rectNum = 0,
      diamNum = 0;

  while ( scanf ( "%d,%d,%d", &A, &B, &O ) == 3 )
  {
    rectNum += !! ( SQ(A) + SQ(B) == SQ(O) );
    diamNum += !! ( SQ(A)         == SQ(B) );
  }

  printf ( "%d\n%d\n", rectNum, diamNum );

  return ( 0 );
}

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <set>
#include <string>
#include<string.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=55;
char mp[maxn][maxn];
int f[maxn][maxn];
int main(){
    int h,w;
    scanf("%d%d",&h,&w);
    memset(f,0,sizeof(f));
    for(int i=0;i<h;i++){
        scanf("%s",mp[i]);
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(mp[i][j]=='#'){
                if(i-1>=0){
                    f[i-1][j]++;
                }
                if(j-1>=0){
                    f[i][j-1]++;
                }
                if(i+1<h){
                    f[i+1][j]++;
                }
                if(j+1<w){
                    f[i][j+1]++;
                }
                if(i-1>=0&&j-1>=0){
                    f[i-1][j-1]++;
                }
                if(i+1<h&&j-1>=0){
                    f[i+1][j-1]++;
                }
                if(i-1>=0&&j+1<w){
                    f[i-1][j+1]++;
                }
                if(i+1<h&&j+1<w){
                    f[i+1][j+1]++;
                }
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(mp[i][j]=='#') printf("#");
            else printf("%d",f[i][j]);
        }printf("\n");
    }
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int main(){
  int N;
  while(~scanf("%d",&N)){
    priority_queue<int> carpets;
    int count = 0;
    for(int i=0;i<N;i++){
      int height;
      scanf("%d",&height);
      count++;

      while(!carpets.empty()){
	if(carpets.top() > height){
	  carpets.pop();
	}
	else if(carpets.top() == height){
	  count--;
	  break;
	}
	else{
	  break;
	}
      }
      carpets.push(height);
    }
    printf("%d\n",count);
  }
}

Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define int long long int
#define ll long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define rep(i, init, n) for (int i = init; i < (int)n; i++)
#define rev(i, n, init) for (int i = (int)n; i >= init; i--)
#define MOD1 1e9 + 7
#define MOD2 998244353
#define f first
#define s second
#define endl '\n'
#define pii pair<int, int>
#define piii pair<pii, int>
#define precise(i) cout << fixed << setprecision(i)
#define codejam cout << "Case #" << ii + 1 << ": ";
#define impossible cout << "IMPOSSIBLE" << endl;
#define error(s) throw runtime_error(s)
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int myRand(int R){int val=rng()%R;assert(val >= 0);return val;}

const long double PI = atan(1.0) * 4;
const int64_t INF64 = 3e18;
const int32_t INF32 = 2e9 + 7;
const int32_t LOG = 21;
const int32_t MOD = MOD1;

using namespace std;


//-------------------DEBUGGING-------------------------
void my_debugger(string s,int LINE_NUM){cerr<<endl;}
template<typename start,typename... end>
void my_debugger(string s,int LINE_NUM,start x,end... y) 
{
    if(s.back()!=',') {s+=',';cerr<<"LINE("<<LINE_NUM<<"): ";}
    int i=s.find(',');
    cerr<<s.substr(0,i)<<" = "<<x;
    s=s.substr(i+1);
    if(!s.empty()) cerr<<", ";
    my_debugger(s,LINE_NUM,y...);
}

#ifdef AJIT
#define debug(...) my_debugger(#__VA_ARGS__,__LINE__,__VA_ARGS__);
#else
#define debug(...) ;
#endif

//-----------------------------------------------------


int32_t main()
{
      getFaster;
      //files_init();
      int tests = 1;
      //cin >> tests;
      rep(ii, 0, tests)
      {
            int x;
            cin>>x;
            cout<<1-x<<endl;
      }
      return 0;
}


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

using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_E

int LevenshteinDistance(string s1,string s2) {
  int n = (int)s1.size(), m = (int)s2.size();
  vector<vector<int> > dp(n+1,vector<int>(m+1));
  for(int i=0;i<=n;++i) dp[i][0] = i;
  for(int i=0;i<=m;++i) dp[0][i] = i;
  for(int i=1;i<=n;++i) {
    for(int j=1;j<=m;++j) {
      dp[i][j] = min(dp[i-1][j]+1,
                     min(dp[i][j-1]+1,dp[i-1][j-1]+(s1[i-1]!=s2[j-1])));
    }
  }
  return dp[n][m];
}

int main() {
  string s1,s2;
  getline(cin,s1);
  getline(cin,s2);
  cout << LevenshteinDistance(s1,s2) << endl;
  return 0;
}

Measured memory_bytes: 4964
#include <iostream>
#include <string>
using namespace std;
long isMul(string t) {
    int sum = 0;
    while (t != "") {
        int rem = t.back() - '0';
        t.erase(t.size() - 1);
        sum += rem;
    }
    return sum;
}
int main()
{
    string a;
    cin >> a;
    if (isMul(a) % 9 == 0) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3324
N, M = map(int, input().split())
A = [0]*N
for _ in range(M):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    A[x]+=1
    A[y]+=1
for a in A:
    if a%2:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 75248
l = list(input())
n = l.count('N')
w = l.count('W')
s = l.count('S')
e = l.count('E')
if n == s or (n != 0 and s != 0):
    if w == e or (w != 0 and e != 0):
        print('Yes')
        exit(0)
print('No')

Measured memory_bytes: 9052
#include <cstdio>
#include <vector>
#include <stack>
using namespace std;
const long long MOD=1000000007;

int n;
long long k;

vector<vector<long long> > mul(vector<vector<long long> > i,vector<vector<long long> > j,int m){
    vector<vector<long long> > res;
    for (int x=0;x<i.size();x++){
        res.push_back(vector<long long>());
        for (int y=0;y<i.size();y++){
            res[x].push_back(0);
            for (int z=0;z<i.size();z++){
                res[x][y]=(res[x][y]+i[x][z]*j[z][y])%m;
            }
        }
    }
    return res;
}

vector<vector<long long> > mexp(vector<vector<long long> > mat,long long p,int m){
    if (p==1) return mat;
    vector<vector<long long> > res=mexp(mat,p>>1,m);
    res=mul(res,res,m);
    if (p&1) res=mul(res,mat,m);
    return res;
}

int main(){
    scanf("%d%lld",&n,&k);
    vector<vector<long long> > v;
    int t;
    for (int x=0;x<n;x++){
        v.push_back(*new vector<long long>());
        for (int y=0;y<n;y++){
            scanf("%d",&t);
            v[x].push_back(t);
        }
    }
    v=mexp(v,k,MOD);
    long long ans=0;
    for (int x=0;x<n;x++){
        for (int y=0;y<n;y++){
            ans=(ans+v[x][y])%MOD;
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
 
const int MAX_N = 20000;
typedef pair<int, pair<int, int > > P;
 
vector<P> v;
bool vis[MAX_N];
 
int main() {
  int N, M;
  while(cin >> N >> M && (N || M)) {
    P p;
    v.clear();
    for(int i = 0; i < M; ++i) {
      cin >> p.first >> p.second.first >> p.second.second;
      --p.second.first; --p.second.second;
      v.push_back(p);
    }
    sort(v.begin(), v.end());
    fill(vis, vis+N, false);
    vis[0] = true;
    int ans = 1;
    for(int i = 0; i < v.size(); ++i) {
      if(vis[v[i].second.first] && !vis[v[i].second.second]) {
        vis[v[i].second.second] = true;
        ++ans;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1684
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	LL N;
	cin >> N;
	LL ans = LINF;
	for (LL i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			LL res = (i - 1) + (N / i - 1);
			if (ans > res) {
				ans = res;
			}
		}
	}
	if (ans == LINF) {
		cout << N - 1 << endl;
	}
	else {
		cout << ans << endl;
	}
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            int t = sc.nextInt();
            long[] a = new long[n];

            for (int i = 0; i < n; i++) {
                a[i] = sc.nextLong();
            }

            long maxDiff = 0;
            long min = Long.MAX_VALUE;

            for (int i = 0; i < n; i++) {
                if ( i != 0 ) {
                    maxDiff = Math.max(maxDiff, a[i] - min);
                }
                min = Math.min(min, a[i]);
            }

            int ans = 0;
            Map<Long, Long> cnt = new HashMap<>();
            for (int i = 0; i < n; i++) {
                long target = a[i] - maxDiff;

                if ( cnt.containsKey(target) ) {
                    ans += cnt.get(target);
                }

                Long tmpCnt = cnt.get(a[i]);
                if ( tmpCnt == null ) {
                    tmpCnt = 0L;
                }
                tmpCnt++;
                cnt.put(a[i], tmpCnt);
            }

            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 66388
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;


int main() {
	int n, k;
	cin >> n >> k;
	int index = -1;
	rep(i, n) {
		int a;
		cin >> a;
		if (a == 1) {
			index = i;
		}
	}

	int count = 0;
	n = n - k;
	count++;
	if (n <= 0) {
		cout << count << endl;
		return 0;
	}

	while(true) {
		n = n - (k - 1);
		count++;
		if (n <= 0) {
			cout << count << endl;
			return 0;
		}

	}




	return 0;
}


Measured memory_bytes: 888
#include<iostream>
using namespace std;
int main()
{
	double n,p;
	double count=1;
	cin >> n;
	for(int i=2;i<=n;i++)
	{
		if(i%2!=0)	
			count++;
	}
	p=count/n;
	printf("%.10lf",p);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	vector<int> A(n);
	ll amt = 1000;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
		if (i && A[i] > A[i - 1]) {
			ll buy = amt / A[i - 1];
			amt -= buy * A[i - 1];
			amt += buy * A[i];
		}
	}
	printf("%lld\n", amt);
}


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

#define ll long long
#define int long long
#define loop(i,s,e) for(int i=s;i<e;i++)
#define rloop(i,s,e) for(int i=e;i>=s;i--)
#define fr first
#define sc second
#define pb push_back
#define  vii vector<int>
#define vll vector<ll>
#define vpii vector<pair<int ,int >>
#define vpll vector<pair<ll, ll> >
#define  pii pair<int,int>
#define lb(v,x) lower_bound(v.begin(),v.end(),x);
#define ub(v,x) upper_bound(v.begin(),v.end(),x);
const long mod =1e8;
const int N = 5e6+5;
const long long inf= 1e18;

ll gcd(ll a ,ll b){if(b==0) return a;return gcd(b,a%b);}
ll mul(ll a ,ll b){return (a%mod * b%mod )%mod;}
ll mpower(ll a, ll b){if(b==0) return 1;ll temp=mpower(a,b/2);if(b%2==0){return mul(temp,temp);}else{	return mul(mul(temp,temp) , a);}}
ll inv(ll a){return mpower(a,mod-2);}
ll ncr(ll n, ll r){if(r==0)return 1;ll ans=n%mod;ans=mul(ans,ncr(n-1,r-1));ans=mul(ans,inv(r));	return ans;}
ll power(ll a, ll b){if(b==0) return 1;ll temp=power(a,b/2);if(b%2==0)return temp*temp;else return temp*temp*a;}
ll add(ll a, ll b){return (a%mod + b%mod)%mod;}



void solve()
{
    ll a;cin>>a;
    
    int x=100;
    int cnt=0;
    while(x<a)
    {
        x+=x/100;
        cnt++;
    }
    cout<<cnt;
}

int32_t main()
{
	ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;//cin>>t;
	while(t--){
        solve();
	}
}

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

using namespace std;

int main(){
    long long n, tmp, garbo;
    cin >> n >> tmp;
    for(long long i = 0; i < n - 1; ++i){
        cin >> garbo;
        tmp = (garbo / __gcd(garbo, tmp) * tmp);
    }
    cout << tmp << endl;
    return 0;

}


Measured memory_bytes: 256