akhauriyash/Code-Regression huggingface dataset:
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()
}

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

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let nk: Vec<usize> = read_vec();
    let n = nk[0];
    let k = nk[1];
    let mut hv: Vec<u32> = read_col(n);

    hv.sort();

    let mut min: u32 = 1000000000;

    for i in 0..(n - k + 1) {
        if hv[i + k - 1] - hv[i] < min {
            min = hv[i + k - 1] - hv[i];
        }
    }

    println!("{}", min);
}


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = LLONG_MAX;
    for (ll i = 0; i <= max(x, y); ++i) {
        ans = min(ans, i * c * 2 + max(0LL, x - i) * a + max(0LL, y - i) * b);
    }
    cout << ans;
    return 0;
}

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

int main() {
    int th, ta, ah, aa;
    cin >> th >> ta >> ah >> aa;

    //ah-ta takahashi
    int takahashi = ah - ta;
    int aoki = th - aa;
    while(true) {
        if(takahashi <= 0) {
            cout << "Yes" << endl;
          break;
        }
        else if(aoki <= 0) {
            cout << "No" << endl;
          break;
        }
        takahashi -= ta;
        aoki -= aa;
    }
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String S = sc.next();
		sc.close();

		int max = 0;
		int tmp = 0;
		for(int i = 0; i < S.length(); i++) {
			if(S.charAt(i) == 'I') {
				tmp++;
			}else if(S.charAt(i) == 'D') {
				tmp--;
			}
			max = Math.max(max, tmp);
		}
		System.out.println(max);
	}

}

Measured memory_bytes: 21588
#include <stdio.h>
#include <string.h>
int main(void){


    long int desk1, desk2, limit;
    scanf("%ld%ld%ld", &desk1, &desk2, &limit);
    
    
    long int now1 = 0, now2 = desk2;
    long int sum1 = 0, sum2 = 0, max = 0;
    long int read1[desk1 + 1], read2[desk2 + 1];
    
    for(long int i = 0; i < desk1; i++){
        scanf("%ld", &read1[i]);
        //sum1 += read1[i];
    }
   
    for(long int i = 0; i < desk2; i++){
        scanf("%ld", &read2[i]);
        sum2 += read2[i];    
    }
   
    //printf
   
    for(long int i = 0; i <= desk1; i++){
        if(sum1 > limit){
            break;
        } else {
            for(int j = 0; j < desk2; j++){
                
                if(sum1 + sum2 > limit && now2 > 0){
                    now2--;
                    //printf("%ld\n", now2);
                    //printf("%ld\n", read2[now2]);
                    sum2 -= read2[now2];
                } else {
                    if(max < now1 + now2){
                        max = now1 + now2;
                    }
                    break;
                }
            }
            
            sum1 += read1[now1];
            now1++;

        }
    }

  
   printf("%ld\n", max);
   
    return 0;
}


Measured memory_bytes: 4856
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
 
int main() {
   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
 
   int n, m;
   cin >> n >> m;
   vector <vector <int>> adj(n + 1);
   for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      adj[x].push_back(y);
   }
 
   vector <int> dist(n + 1);
   vector <bool> vis(n + 1);
 
   function <void (int)> dfs = [&](int v) {
      vis[v] = true;
      for (auto u : adj[v]) {
         if (!vis[u]) {
            dfs(u);
         }
         dist[v] = max(dist[v], dist[u] + 1);
      }
   };
 
   for (int i = 1; i <= n; i++) {
      if (!vis[i])
         dfs(i);
   }
 
   int ans = *max_element(dist.begin(), dist.end());
 
   cout << ans << '\n';
 
   return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <map>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;


const int INF = 1000000000 + 7;


int main() {
    int n; string s;
    cin >> n >> s;

    map<char, int> counter;
    rep (i, n) {
        if (counter.find(s[i]) == counter.end()) counter[s[i]] = 1;
        else counter[s[i]]++;
    }

    long long ans = 1;
    for (auto elem : counter) {
        ans *= elem.second+1;
        ans %= INF;
    }

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



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<string>moji(N);
  for(int i=0;i<N;i++){
  cin>>moji.at(i);
  }
  int count=N;
  sort(moji.begin(),moji.end());
  for(int i=1;i<N;i++){
  	if(moji.at(i) == moji.at(i-1)){
    	count--;
      
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 9568
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1e9+7;

int main() {
  bool ifprime[55556];
  rep(i,55556) ifprime[i]=true;
  ifprime[0]=false;
  ifprime[1]=false;
  vector<int> primes;
  rep(i,55556) if(ifprime[i]){
    primes.push_back(i);
    int k=2*i;
    while(k<=55555){
      ifprime[k]=false;
      k+=i;
    }
  }
  
  int n;
  cin>>n;
  vector<int> ans;
  for(int num:primes){
    if(num%5==2) ans.push_back(num);
    if(ans.size()==n) break;
  }
  for(auto num:ans) cout<<num<<" ";
  cout<<endl;
  return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    string s;
    cin >> s;

    string ans = s.substr(0, 4) + ' ' + s.substr(4);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    REP(i, m){
        cin >> a[i];
    }

    int accum = accumulate(a.begin(), a.end(), 0);
    if(n < accum)
        cout << -1 << endl;
    else
        cout << n - accum << endl;
    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int main()
{
  double n;
  int k;
  cin>>n>>k;
  double ans=0;
  for(int i=1;i<=n;i++)
  {
    double t=1.0/n;
    int  p=i;
    while(p<k)
    {
      p*=2;
      t/=2;
    }
    ans+=t;
  }
  printf("%.10f",ans);
  return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using Pa = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    vec<double> E(N),S(N+1);
    for(int i=0;i<N;i++){
        int p;
        cin >> p;
        E[i] = 1.0*(p+1)/2;
    }
    for(int i=0;i<N;i++) S[i+1] = S[i]+E[i];
    double ans = 0;
    for(int i=0;i<N;i++){
        if(i+K>N) break;
        ans = max(ans,S[i+K]-S[i]);
    }
    cout << fixed << setprecision(10) << ans << "\n";
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const LL inf=1e18;
const double pi=acos(-1.0);
const int mod=21092013;
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int main()
{
//    freopen("out.txt","r",stdin);
//    freopen("outt.txt","w",stdout);
    int n,a;
    cin>>n;
    int c1=0,c4=0,c2=0;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a&1) c1++;
        else if(a%4==0) c4++;
        else c2++;
    }
    if(c1==1) puts(c4?"Yes":"No");
    else if(c2==0) puts(c1<=c4+1?"Yes":"No");
    else puts(c1<=c4?"Yes":"No");
    return 0;
}


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

using namespace std;

int main (){
  int p, q, r;
  cin >> p >> q >> r;
  cin.ignore();

  // 最大のものを抽出
  int max_ = p;
  if(max_ < q) max_ = q;
  if(max_ < r) max_ = r;

  if(max_ == q){
    cout << p + r << endl;
    return 0;
  }

  if(max_ == p){
    cout << q + r << endl;
    return 0;
  }

  if(max_ == r){
    cout << p + q << endl;
    return 0;
  }
  return 0;
}


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

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

  int T, A;
  cin >> T >> A;

  int cand_idx = 1;
  double cand_diff = 1e9;
  for(int i = 1; i <= N; i++){
    int h;
    cin >> h;
    double temp = T - h * 0.006;
    if(abs(temp - A) < cand_diff){
      cand_idx = i;
      cand_diff = abs(temp - A);
    }
  }
  cout << cand_idx << endl;
}


Measured memory_bytes: 888
// aabc172_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int a;
  cin>>a;
  cout<<a+a*a+a*a*a<<endl;
  return 0;
}


Measured memory_bytes: 3620
H, W = map(int, input().split())
grid = ['.'*(W+2)]
for _ in range(H):
    grid.append('.'+input()+'.')
grid.append('.'*(W+2))
for i in range(1,H):
    for k in range(1,W):
        if grid[i][k] == '.':
            continue
        if grid[i-1][k] == '.' and grid[i+1][k] == '.' and grid[i][k-1] == '.' and grid[i][k+1] == '.':
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>

using namespace std;
static const int MAXV=1000;

int main() {
  while(!feof(stdin)) {
    char data[MAXV];
    if(fgets(data, sizeof(data), stdin) == NULL) break;
    for(int i=0; data[i] != '\n'; i++) {
      if('a' <= data[i] && data[i] <='z')
	printf("%c", data[i]-32);
      else printf("%c", data[i]);
    }
    printf("\n");
  }
}

Measured memory_bytes: 1084
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
 
using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define replb(i, a, b) for (ll i = a; i >= b; i--)
#define repl(i, a, b) for (ll i = a; i < b; i++)
#define repit(arr) for (auto it = arr.begin(); it != arr.end(); 
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int> >
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<int>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define castl static_cast<ll>
#define BRAHAMASTRA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ull unsigned long long int

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	BRAHAMASTRA

	string s;
	cin>>s;
	int n=s.length();
	if(s[n-1]=='s')
	{
		s+='e';
		s+='s';
	}
	else
		s+='s';
	cout<<s<<"\n";
}

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

int main() {
    int n, l[15], sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(l, l + n);

    for (int i = 0; i < n - 1; i++) sum += l[i];

    if (sum > l[n - 1]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,l = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    pa = a[0]
    mi = -1
    for i,ai in enumerate(a[1::]):
        if pa+ai >= l:
            print("Possible")
            mi = i
            break
        pa = ai
    if mi == -1:
        print("Impossible")
        exit()
    for i in range(mi):
        print(i+1)
    for i in range(n-mi-1):
        print(n-i-1)

    return

if __name__ == '__main__':
    main()


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

keta1 = -1
keta10 = -1
keta100 = -1
for i in range(M):
  checkKeta, num = map(int,input().split())
  if N == 1:
    if keta1 != -1 and keta1 != num:
      print(-1)
      exit()
    else:
      keta1 = num
  else:
    if checkKeta == 1 and num == 0:
      print(-1)
      exit()
    
    if N == 2:
      if checkKeta == 1:
        if keta10 != -1 and keta10 != num:
          print(-1)
          exit()
        else:
          keta10 = num
      else:
        if keta1 != -1 and keta1 != num:
          print(-1)
          exit()
        else:
          keta1 = num
    elif N == 3:
      if checkKeta == 1:
        if keta100 != -1 and keta100 != num:
          print(-1)
          exit()
        else:
          keta100 = num
      elif checkKeta == 2:
        if keta10 != -1 and keta10 != num:
          print(-1)
          exit()
        else:
          keta10 = num
      else:
        if keta1 != -1 and keta1 != num:
          print(-1)
          exit()
        else:
          keta1 = num
if N == 1:
  if keta1 == -1:
    print(0)
  else:
    print(keta1)
elif N == 2:
  if keta10 == -1:
    keta10 = 1
  if keta1 == -1:
    keta1 = 0
  print(str(keta10) + str(keta1))
else:
  if keta100 == -1:
    keta100 = 1
  if keta10 == -1:
    keta10 = 0
  if keta1 == -1:
    keta1 = 0
  print(str(keta100) + str(keta10) + str(keta1))



Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t 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(int64_t 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) {return mint(*this) /= a;}
};

struct combination {
    vector<mint> frac, ifrac;
    combination(int n):frac(n+1), ifrac(n+1) {
        assert(n < mod);
        frac[0] = 1;
        for (int i = 1; i <= n; ++i) frac[i] = frac[i-1]*i;
        ifrac[n] = frac[n].inv();
        for (int i = n; i >= 1; --i) ifrac[i-1] = ifrac[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return frac[n]*ifrac[k]*ifrac[n-k];
    }
} c(1000000);

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

int main() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    mint ans;
    rep(i, n) {
        mint now = a[i];
        ans -= now*c(n-1-i, k-1);
        ans += now*c(i, k-1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 16256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>

#ifdef GONGKUNPENG
#include <cassert>

#define _GG 1
#else
#define _GG 0
#endif

#define uint unsigned
#define vector std::vector
#define max(a, b) std::max(a, b)
#define min(a, b) std::min(a, b)
#define swap(a, b) std::swap(a, b)
#define sort(...) std::sort(__VA_ARGS__)
#define ms(a, v) memset(a, v, sizeof(a))
#define ufor(i, n) for (int i = 1; i < n; ++i)
#define sfor(i, n) for (int i = 1; i <= n; ++i)
#define tfor(i, n) for (int i = 0; i < n; ++i)

#if __cplusplus >= 201103L
using ll = long long;
using ull = unsigned long long;
#else
typedef long long ll;
typedef unsigned long long ull;
#endif

#define _GIO 1

#if _GIO
struct _gio {
#define BFSZ 1 << 18
#define blank(x) (x == ' ' || x == '\t' || x == '\n' || x == '\r')

  char rcha;
  bool rneg;
#if _GG
#else
  char ruf[BFSZ], wuf[BFSZ], *r1, *r2, *w1;
#endif

  _gio() {
    rcha = ' ';
#if _GG
#else
    r1 = r2 = ruf, w1 = wuf;
#endif
  }

  ~_gio() {
#if _GG
#else
    fwrite(wuf, 1, w1 - wuf, stdout);
#endif
  }

  inline void flush() {
#ifdef _GG
#else
    fwrite(wuf, 1, w1 - wuf, stdout), w1 = wuf;
#endif
  }

  inline int readc() {
#if _GG
    return getchar();
#else
    return (r1 == r2 && (r2 = (r1 = ruf) + fread(ruf, 1, BFSZ, stdin), r1 == r2)
                ? -1
                : *r1++);
#endif
  }

  template <typename T, typename... Args>
  void read(T &x, Args &... args) {
    read(x), read(args...);
  }

  inline void read() {}

  inline void read(char *s) {
    while (blank(rcha)) rcha = readc();
    while (!blank(rcha) && rcha > 0) *s++ = rcha, rcha = readc();
    *s = '\0';
  }

  inline void readl(char *s) {
    while (blank(rcha)) rcha = readc();
    while (rcha != '\n' && rcha > 0) *s++ = rcha, rcha = readc();
    *s = '\0';
  }

  template <typename T>
  inline void read(T &x) {
    x = rcha = rneg = 0;
    while (!isdigit(rcha) && rcha != '-') rcha = readc();
    rcha == '-' && (rneg = true, rcha = readc());
    while (isdigit(rcha)) x = (x << 3) + (x << 1) - 48 + rcha, rcha = readc();
    rneg && (x = -x);
  }

  inline void writec(char c) {
#if _GG
    putchar(c);
#else
    (w1 - wuf == BFSZ) && (fwrite(wuf, 1, BFSZ, stdout), w1 = wuf);
    *w1++ = c;
#endif
  }

  template <typename T, typename... Args>
  void write(const T &x, const Args &... args) {
    write(x), write(args...);
  }

  template <typename T, typename... Args>
  void writel(const T &x, const Args &... args) {
    write(x), write(args...);
    writec('\n');
  }

  inline void write() {}

  inline void write(const char &c) { writec(c); }

  template <typename T>
  void write(T x) {
    if (x < 0) {
      writec('-');
      write(-ll(x));
      return;
    }
    if (x > 9) write(x / 10);
    writec(x % 10 ^ 48);
  }

  inline void write(const char *s) {
    while (*s) writec(*s++);
  }
#undef BFSZ
} io;
#endif

const int INF = 0x3f3f3f3f;
const int MAXN =
#ifdef GONGKUNPENG
    15
#else
    1000005
#endif
    ;

int main() {
  ll res = 0;
  int n;
  io.read(n);
  sfor(i, n) if (i % 3 > 0 && i % 5 > 0) res += i;
  io.writel(res);

  return 0;
}

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

//-----BEGIN union find tree-----
//complexity: -

// [0, n) をノードとする union find tree
class UnionFindTree {
	public:
		UnionFindTree(int n) : N_(n) {
			rank_ = std::vector<int>(n, 0);
			card_ = std::vector<int>(n, 1);
			for(int i = 0; i < n; ++i) {
				parent_.push_back(i);
			}
		}
		bool same(int x, int y) {
			assert(0 <= x && x < N_ && 0 <= y && y < N_);
			return findRoot(x) == findRoot(y);
		}
		void unite(int x, int y) {
			assert(0 <= x && x < N_ && 0 <= y && y < N_);
			x = findRoot(x);
			y = findRoot(y);
			if(x == y) return;
			if(rank_[x] < rank_[y]) {
				parent_[x] = y;
				card_[y] += card_[x];
			} else {
				parent_[y] = x;
				card_[x] += card_[y];
				if(rank_[x] == rank_[y]) ++rank_[x];
			}
		}
		int card(int x) {
			assert(0 <= x && x < N_);
			return card_[findRoot(x)];
		}
	private:
		const int N_;
		std::vector<int> parent_;
		std::vector<int> rank_;
		std::vector<int> card_;
		int findRoot(int x) {
			if(parent_[x] == x) {
				return x;
			} else {
				//rank_[x] = 1; // rank_[x] < N_ なので不要
				return parent_[x] = findRoot(parent_[x]);
			}
		}
};
//-----END union find tree-----

using namespace std;

int main(void) {
	long long N, M, K;
	cin >> N >> M >> K;
	UnionFindTree tree(N);
	vector<long long> blockNum(N, 0);
	for(int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		tree.unite(a, b);
		++blockNum[a];
		++blockNum[b];
	}
	for(int i = 0; i < K; ++i) {
		int c, d;
		cin >> c >> d;
		--c;
		--d;
		if(tree.same(c, d)) {
			++blockNum[c];
			++blockNum[d];
		}
	}
	for(int i = 0; i < N; ++i) {
		cout << (tree.card(i) - blockNum[i] - 1) << '\n';
	}
	return 0;
}



Measured memory_bytes: 2936
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = int(input())
a_list = list(map(int, input().split()))
a_list = np.array(a_list)

a = a_list.sum() % MOD
b = ( (a_list**2)%MOD ).sum() % MOD
c = ( a**2 - b) % MOD

if c&1:
    c += MOD

print(c//2)

Measured memory_bytes: 50164
// https://atcoder.jp/contests/abc072/tasks/arc082_b

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 1e5;

int N;
int p[N_MAX];

void solve() {
  int bl = 0;
  int ans = 0;
  REP(i, N) {
    if (p[i] == i + 1) {
      bl++;
    } else {
      ans += bl / 2 + bl % 2;
      bl = 0;
    }
  }
  ans += bl / 2 + bl % 2;
  printf("%d\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", p + i);
}

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


Measured memory_bytes: 640
#include <stdio.h>
#define N 105
#define INFTY 2000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1
int prim();
int A[N][N],a;  //A[u][v]にu~vへの辺の重みを記録する隣接行列
int main(){
  int i,j;

  scanf("%d",&a);
  for(i=0;i<a;i++){
    for(j=0;j<a;j++){
      scanf("%d",&A[i][j]);
      
    }
  }
  printf("%d\n",prim());
  
  return 0;
}


int prim(){
  int i,minv,v,u;
  int d[N],p[N],color[N];  //d[N]重みが最小の辺の重みを記録
                           //p[N]はMSTにおける頂点vの親を記録
                           //color[v]にWHITE,GRAY,BLACKを記録

  for(i=0;i<a;i++){
    d[i]=INFTY;
    p[i]=NIL;
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){
    minv=INFTY;
    u=NIL;
    for(i=0;i<a;i++){
      if(color[i]!=BLACK && d[i]<minv){
	u=i;
	minv=d[i];
      }
    }
    if(u==NIL) break;
    color[u]=BLACK;
    for(v=0;v<a;v++){
      if(color[v]!=BLACK && A[u][v]!=NIL){
	if(d[v]>A[u][v]){
	  d[v]=A[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  int sum=0;
  for(i=0;i<a;i++){
    if(p[i]!=NIL) sum+=A[i][p[i]];
    //printf("%d\n",sum);
  }
  //printf("%d\n",sum);

  return sum;
}

  

  



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

int main() {
  int W,H,x,y;
  cin >> W >> H >> x >> y;
  double area=(double)W*H/2.0;
  cout << fixed << setprecision(2);
  cout << area << ' ';
  if (W%2==0&&W/2==x&&H%2==0&&H/2==y){
    cout << 1 << endl;
  }
  else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 getrandmax() {
	static uint32_t y = time(NULL);
	y ^= (y << 13); y ^= (y >> 17);
	y ^= (y << 5);
	return abs((int)y);
}
int getrand(int l, int r) { // [l, r]
	return getrandmax() % (r - l + 1) + l;
}
vector<int> makePermutation(int n) {
	vector<int> v(n);
	rep(i, 0, n) v[i] = i + 1;
	rep(i, 0, n) {
		int j = getrand(0, n - 1);
		swap(v[i], v[j]);
	}
	return v;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
char ans[201];
//---------------------------------------------------------------------------------------------------
string ask(vector<int> d) {
	printf("?");
	fore(i, d) printf(" %d", i+1);
	printf("\n");
	fflush(stdout);

	string res; cin >> res;
	return res;
}
string ask2(int st) {
	vector<int> v;
	rep(i, 0, N) v.push_back((st + i) % (2 * N));
	return ask(v);
}
void answer() {
	printf("! ");
	rep(i, 0, N * 2) printf("%c", ans[i]);
	printf("\n");
}
//---------------------------------------------------------------------------------------------------
#define blue 'B'
#define red 'R'
void _main() {
	cin >> N;
	rep(i, 0, 2 * N) ans[i] = '#';

	int a = 0, b = N;
	string as = ask2(a), bs = ask2(b);
	while (a + 1 != b) {
		int md = (a + b) / 2;
		if (ask2(md) == as) a = md;
		else b = md;
	}

	if (as == "Red") {
		ans[a] = 'R';
		ans[(a + N) % (2 * N)] = 'B';
	}
	else {
		ans[a] = 'B';
		ans[(a + N) % (2 * N)] = 'R';
	}

	rep(st, 0, N - 1) {
		vector<int> v;
		rep(i, 0, N - 1) v.push_back((a + 1 + i) % (2 * N));
		v.push_back((a + N + 1 + st) % (2 * N));
		auto res = ask(v);
		if (res == "Red") ans[(a + N + 1 + st) % (2 * N)] = 'R';
		else ans[(a + N + 1 + st) % (2 * N)] = 'B';
	}

	rep(st, 0, N - 1) {
		vector<int> v;
		rep(i, 0, N - 1) v.push_back((a + 1 + N + i) % (2 * N));
		v.push_back((a + 1 + st) % (2 * N));
		auto res = ask(v);
		if (res == "Red") ans[(a + 1 + st) % (2 * N)] = 'R';
		else ans[(a + 1 + st) % (2 * N)] = 'B';
	}

	answer();
}







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

using namespace std;

const int MAXN = 2e5 + 10;
int a[MAXN], b[MAXN];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &a[i], &b[i]);// don't forget &
    }
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + n);
    if (n & 1) {
        printf("%d", b[(n + 1) / 2] - a[(n + 1) / 2] + 1);
    } else {
        printf("%d", (b[n / 2] + b[n / 2 + 1]) - (a[n / 2] + a[n / 2 + 1]) + 1);
    }
    return 0;
}


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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
#define F first
#define S second
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int x; cin >> x;
  if(x >= 30)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

import numpy as np

def main():
  n, W = map(int, input().split())
  dp = np.zeros(W+1, dtype=np.int64)
  for _ in range(n):
    w, v = map(int, input().split())
    np.maximum(dp[:W-w+1]+v, dp[w:W+1], out=dp[w:W+1])
  print(dp[W])
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 14596
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
#define mod 1000000007
using LL = long long;
using namespace std;

int main(){
	int n;cin>>n;
    int ben=0;
    vector<int> v(n),c(n);
    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=0;i<n;i++)cin>>c[i];

    for(int i=0;i<n;i++){
        if(v[i]>=c[i])ben+=v[i]-c[i];
    }

    cout<<ben<<endl;
}

Measured memory_bytes: 256
s = input()

ans = [-1 for i in range(len(s))]

pointer = 0
while pointer < len(s):
    start = pointer
    while pointer < len(s) and s[pointer] == 'R':
        pointer += 1
    change = pointer
    while pointer < len(s) and s[pointer] == 'L':
        pointer += 1
    end = pointer
    
    if (end - start) % 2 == 0:
        for i in range(start, end):
            if (i == (change - 1)) or (i == change):
                ans[i] = (end - start) // 2
            else:
                ans[i] = 0
    else:
        if (change - start) < (end - change):
            if (end - change) % 2 == 0:
                for i in range(start, end):
                    if i == (change - 1):
                        ans[i] = (end - start) // 2 + 1
                    elif i == change:
                        ans[i] = (end - start) // 2
                    else:
                        ans[i] = 0
            else:
                for i in range(start, end):
                    if i == (change - 1):
                        ans[i] = (end - start) // 2
                    elif i == change:
                        ans[i] = (end - start) // 2 + 1
                    else:
                        ans[i] = 0
        else:
            if (change - start) % 2 == 0:
                for i in range(start, end):
                    if i == (change - 1):
                        ans[i] = (end - start) // 2
                    elif i == change:
                        ans[i] = (end - start) // 2 + 1
                    else:
                        ans[i] = 0
            else:
                for i in range(start, end):
                    if i == (change - 1):
                        ans[i] = (end - start) // 2 + 1
                    elif i == change:
                        ans[i] = (end - start) // 2
                    else:
                        ans[i] = 0

print(' '.join(map(str, ans)))


Measured memory_bytes: 10612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define inf LLONG_MAX
#define mod 1000000007
#define vll vector <ll>
#define pll pair <ll,ll>
#define dbg(n) cout<<n<<' '
#define cu continue
#define br break

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

	ll n;
	cin>>n;
	cout<<ceil(1.0*n/2)<<'\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    ll mi=INF,cnt=0,sum=0;
    rep(i,n){
        mi=min(mi,(ll)abs(a[i]));
        if(a[i]<0)cnt++;
        sum+=abs(a[i]);
    }
    if(cnt%2==0)cout<<sum<<endl;
    else cout<<sum-2*mi<<endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.*;

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

        // 出力
      
      int ans = a - (b -1);
      
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include <stdio.h>

int main(void)
{
	int a, b, c, x, y, z;
	int n = 0;
	scanf("%d %d %d", &a, &b, &c);
	
	while(1){
		if(a%2==1 || b%2==1 || c%2==1){
			printf("%d\n", n);
			break;
		}
		n++;
		x = b/2 + c/2;
		y = a/2 + c/2;
		z = a/2 + b/2;
		a = x;
		b = y;
		c = z;
		if(a == b && b == c){
			printf("-1\n");
			break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	int n;
	cin >> n;
	if (!cin) return false;

	vi v(n); 
	ll sol = 0;
	map<int, ll> reps;

	for (int i = 0; i < n; ++i) {
		cin >> v[i];

		if (reps.find(v[i]) == reps.end()) reps.insert(mp(v[i], 1));
		else ++reps[v[i]];
	}

	for (auto it = reps.begin(); it != reps.end(); ++it) {
		ll num = it->second;
		sol += num * (num - 1);
	}

	for (int i = 0; i < n; ++i) {
		ll num = reps[v[i]];
		sol -= num * (num - 1);
		sol += (num - 1) * (num - 2);

		cout << sol / 2 << '\n';

		sol += num * (num - 1);
		sol -= (num - 1) * (num - 2);
	}



	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 10240
#include<iostream>
using namespace std;
long long N, A, B, C, D, E;


int main(){
  cin >> N >> A >> B >> C >> D >> E;
  long long m = min(A, min(B, min(C, min(D, E))));

  cout << 4 + (N + m - 1) / m << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define  maxn 200005
#define pb push_back
#define forup(i,a,b) for(int i=(a);i<=(b);i++)  
#define fordown(i,a,b) for(int i=(a);i>=(b);i--)
string s;
int n;
int main()
{cin>>s;
  cin>>n;
  int l=s.length();	
 forup(i,0,l-1)
  {if(i%n==0) cout<<s[i];
  }
}

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

struct edge {
	int to;
	edge *nxt;
}E[4010], *head[2010], *et=E;

void adde(int u, int v) {
	*(++et)=(edge){v,head[u]}; head[u]=et;
	*(++et)=(edge){u,head[v]}; head[v]=et;
}

int dep[2010], sum[2010], ha, n, k;

void dfs(int x, int fa) {
	sum[x]=dep[x]==ha+1;
	for (edge *i=head[x]; i; i=i->nxt)
		if (i->to!=fa) {
			dep[i->to]=dep[x]+1;
			dfs(i->to,x);
			sum[x]+=sum[i->to];
		}
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		adde(u,v);
	}
	ha=k>>1;
	int ans=0, t, h;
	for (int i=1; i<=n; i++) {
		dep[i]=0;
		dfs(i,0);
		t=h=0;
		for (int j=1; j<=n; j++) if (dep[j]<=ha) t++;
		if (k&1) {
			for (edge *j=head[i]; j; j=j->nxt)
				h=std::max(h,sum[j->to]);
		}
		t+=h;
		ans=std::max(ans,t);
	}
	printf("%d", n-ans);
	return 0;
}

Measured memory_bytes: 384
n,m = map(int,input().split())
lmax = 1
rmin = n
for _ in range(m):
  l,r = map(int,input().split())
  if l > lmax:
    lmax = l
  if r < rmin:
    rmin = r
if rmin >= lmax:
  print(rmin-lmax+1)
else:
  print(0)
  

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int i,c,d,f,g,j=0;
  char e[51]={0};
  char k[51][180]={0};
  int l[180]={0};
  scanf("%d:%d %s",&c,&d,e);
  for(i=0;i<a-1;i++){
    scanf("%d:%d %s %d:%d %s",&c,&d,e,&f,&g,e);
    c*=60;
    f*=60;
    if(f+g-c-d>=b){
      j++;
      strcpy(k[j],e);
      l[j]=f+g-c-d;
    }
  }
  scanf("%d:%d %s",&c,&d,e);
  printf("%d\n",j);
  if(j!=0){
    for(i=1;i<=j;i++){
      printf("%s %d\n",k[i],l[i]);
    }
  }
}

Measured memory_bytes: 2820
class UnionFind:
    def __init__(self, size):
        self.parent = [-1 for i in range(size)]#非負なら親ノード，負ならグループの要素数

    def root(self, x): #root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x]) #xをxの根に直接つなぐ
            return self.parent[x]

    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]


n,m=[int(i) for i in input().split()]

A = []
for i in range(m):
    a, b = map(int, input().split())
    A.append((a-1, b-1))

ans = [0]*(m+1)
a = n*(n-1)//2
ans[0] = a

uf = UnionFind(n)
for i in range(m):
    j = m-i-1
    v1 = A[j][0]
    v2 = A[j][1]
#    print(v1,v2)
    if not uf.issame(v1,v2):
#        print(uf.parent)
        a -= uf.size(v1) * uf.size(v2)
        uf.merge(v1,v2)

    ans[i+1]=a

for i in range(m):
    print(ans[m-i-1])
    
    
    
    
    
    





Measured memory_bytes: 22516
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
  int main(){
 lint N,M;
 cin>>N>>M;
 if(N*2<M){
   cout<< N+(lint)(M-2*N)/4;
 }else cout <<(lint)M/2;
  }

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a) for(int i=(a);;++i)
#define REP(i,n)  FOR(i,0,n)
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define INPUT \
FILE *fp; \
fp=fopen("input.text","r");



int main(int argc, char *argv[]) {
    int N;
    int buld,flo,room,hum;
    int bill[4][3][10]={};
    
    cin >> N;
    
    for (int num_cy = 0; num_cy < N; num_cy++) {
        cin >> buld >> flo >> room >> hum;
        bill[buld-1][flo-1][room-1]+=hum;
    }
    for (int buldings=0; buldings<4; buldings++){
        for(int f=0; f<3; f++){
            for(int l=0; l<10; l++){
                cout << " " << bill[buldings][f][l] ;
            }
            cout << endl;
        }
        switch (buldings) {
            case 3:
                break;
                
            default:
                cout << "####################" << endl;
                break;
        }
        
    }
    return 0;

}





Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int dp[10009];
struct item
{
    int w,c;
};
vector<item>v;int n;
int solve(int h)
{
    if(h<=0)return 0;
    int &rt = dp[h];
    if(rt)return rt;
    int k = INT_MAX;
    for(int i=0;i<n;i++)
         k = min(k,solve(h-v[i].w)+v[i].c);
    return rt = k;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int h;cin>>h>>n;
    v.resize(n);
    for(auto& z:v)cin>>z.w>>z.c;
    cout<<solve(h);
    return 0;
}


Measured memory_bytes: 768
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
typedef long long LL;
LL ans;
LL n, m;
int main(){
	while(~scanf("%lld %lld", &n, &m)){
		ans = 0;
		if(m >= n * 2){
			ans += n;
			m = m - (n * 2);
			ans += m / 4;
		}
		else ans = (m / 2);
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
import math


def isPrime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    for i in range(3, int(x ** 0.5) + 1, 2):
        if x % i == 0:
            return False
    return True


def enum_div(n):
    ldv, udv = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            ldv.append(i)
            if i != n // i:
                udv.append(n // i)
        i += 1
    return ldv + udv[::-1]


n = int(input())
cnt = math.inf

if isPrime(n):
    cnt = n - 1
else:
    arr = enum_div(n)
    for i, v in enumerate(range(len(arr) - 1, -1, -1)):
        cnt = min(cnt, arr[i] + arr[v] - 2)

print(cnt)


Measured memory_bytes: 9484
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        string s;
        cin>>s;
        int l=0,r=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='(')
                r++;
            else
            {
                if(r!=0)
                    r--;
                else
                    l++;
            }
        }
        for(int i=0;i<l;i++)
            cout<<"(";
        cout<<s;
        for(int i=0;i<r;i++)
            cout<<')';
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=2e5+3;
ll a[M],ans=0;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) 
	{
		cin>>a[i];
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	for(int i=n/2+1+n%2;i<=n;i++) ans+=a[i];
	for(int i=1;i<=n/2;i++) ans-=a[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

long long N, a[500009], bit[500009], mod = 1000000007; bool used[500009]; vector<long long>A, B;

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (long long i = 0; i < 63; i++) {
		if ((b&(1LL << i)) != 0) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}
long long Div(long long a, long long b, long long m) {
	a %= m;
	return (a*modpow(b, m - 2, m)) % m;
}
void Add(long long p, long long x) {
	p++;
	while (p <= 500008) { bit[p] += x; p += (p&-p); }
}
long long Sum(long long p) {
	p++; long long s = 0;
	while (p >= 1) { s += bit[p]; p -= (p&-p); }
	return s;
}

int main() {
	cin >> N;
	for (long long i = 1; i <= N; i++) {
		scanf("%lld", &a[i]); if (a[i] >= 1)used[a[i]] = true;
	}
	for (long long i = 1; i <= N; i++) {
		if (used[i] == true)A.push_back(i);
		if (used[i] == false)B.push_back(i);
	}
	long long fact2 = 1;
	for (long long i = 0; i < B.size(); i++) { fact2 *= (i + 1); fact2 %= mod; }
	long long cnt = 0, fact = 1, ret = 0, sum = 0, cnt2 = 0;
	for (long long i = N; i >= 1; i--) {
		if (a[i] == 0) {
			long long V = sum; V = Div(V, B.size(), mod);
			long long W = cnt2; W = Div(W, 2, mod);
			long long X = V + W; X *= fact2; X %= mod;
			ret += X * fact; ret %= mod; cnt2++;
		}
		else {
			long long pos1 = lower_bound(B.begin(), B.end(), a[i]) - B.begin();
			sum += (B.size() - pos1);
			long long V = Sum(a[i]); Add(a[i], 1);
			long long W = pos1; W = Div(W, B.size(), mod); W *= cnt2; W %= mod;
			long long X = V + W; X *= fact2; X %= mod;
			ret += X*fact; ret %= mod;
		}
		cnt++; fact *= cnt; fact %= mod;
	}
	ret += fact2; ret %= mod;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 14828