akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> b(n+1,0);
	vector<int> w(n+1,0);
	w[n]=0;
	b[0]=0;
	for(int i=1;i<=n;i++)
	{
		b[i]=b[i-1]+(s[i-1]=='#' ? 1:0);
	}
	for(int i=n-1;i>=0;i--)
		w[i]=w[i+1]+(s[i]=='.' ? 1:0);
	int ans=n;
	for(int i=0;i<=n;i++)
	{
//		cout << b[i] << " " << w[i] << " " <<b[i]+w[i] << endl;
		if(ans>b[i]+w[i])
			ans=b[i]+w[i];
	}
	cout << ans << endl;
}

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

int main(){
	
	int n;
	cin >> n;
	int arrX[n+1],arrY[n+1];
	for(int i=0;i<n;i++){
		cin >> arrX[i];
	}
	for(int i=0;i<n;i++){
		cin >> arrY[i];
	}
	int best = INT_MIN;
	for (int t = 0; t < (1 << n); t++) {
		int tempX=0,tempY=0;
		for (int i = 0; i < n; i++) {
			if (t & (1 << i)){
				tempX += arrX[i];
				tempY += arrY[i]; 
			}
		}
		best = max(tempX-tempY,best);
	}
	cout << best << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
   
int main(){
 ll n,k,s;
 cin >> n >> k >> s;
 if(s==mm){
     rep(i,n){
         if(i<k)cout << mm << " ";
         else cout << mm-1 << " ";
     }
     cout << endl;
 }
 else if(s!=mm){
     rep(i,n){
         if(i<k)cout << s <<" ";
         else cout << mm <<" ";
     }
     cout << endl;
 }
} 
    

Measured memory_bytes: 3488
#include<bits/stdc++.h>
using namespace std;
#define maxn (int)1e5+1000
typedef long long ll;

int main()
{
    ll n,k;
    cin >> n >> k;
    if(n > k)
        n %= k;
    ll minn = n;
    int t = 100000;
    while(t--)
    {
        n = abs(n - k);
        minn = min(minn,n);
    }
    cout << minn << endl;
}


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

void swap(double *x, double *y){
    double c;
    c=*x;
    *x=*y;
    *y=c;
}
void SortData(double data[] ,int N){
    int i,j;
    for(i=0;i<N-1;i++){
        for(j=0;j<N-1;j++){
            if(data[j]>data[j+1]){
                swap(&data[j],&data[j+1]);
            }
        }
    }
}

int main(){
    double a, b, c;
    scanf("%lf %lf %lf", &a, &b, &c);
    double A[3];
    A[0] = fabs(a - b);
    A[1] = fabs(a - c);
    A[2] = fabs(b - c);
    SortData(A, 3);
    printf("%.0f",(A[0]+A[1]));
    return 0;
}

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

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

# define int(x) int x; scanf("%d",&x);
# define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
# define string(x) string x; cin >> x;

using namespace std;

namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    REP (i, mat.size()) {
      REP (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    REP (i, v.size())
      if (i >= v.size()-1)
	cout << v[i];
      else
	cout << v[i] << ' ';
    
    cout << endl;
  }

  template <typename T> pair<T, T> shape(vector<vector<T>> mat) {
    int d1, d2;

    d1 = mat.size();
    if (d1 > 0) d2 = mat[0].size();
    else int d2 = 0;
    cout << "(" << d1 << ", " << d2 << ")" << endl;
    return make_pair(0, 0);
  }

  template <typename T> vector<vector<T>> empty(int n, int m) {
    vector<vector<T>> mat(n, vector<T>(m));
    return mat;
  }
}


int main() {
  vint(A,3);
  if(A[1] >= A[2]){
    cout << "delicious" << endl;
  }
  else if (A[1] + A[0] >= A[2]){
    cout << "safe" << endl;
  }else{
    cout << "dangerous" << endl;
  }
}


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

int main()
{
int n;cin>>n;//scanf("%d",&n);
int fib[n+1];//vector<int> fib(n+1,1);
for(int i=0;i<n+2;i++)fib[i]=1;
if(n>1){for(int i=2;i<n+2;i++){fib[i]=fib[i-2]+fib[i-1];}}
cout<<fib[n]<<endl;//printf("%d\n",fib[n]);
}



Measured memory_bytes: 3092
package main

import (
    "fmt"
    "math"
)

func main(){
    m := make([]int, 5)
    for i := 0; i < 5; i++ {
        fmt.Scan(&m[i])
    }
    var mink, minv, res int
    minv = 10
    for mk, mv := range m {
        if mv % 10 < minv  && mv % 10 != 0 {
            minv = mv % 10
            mink = mk
        }
    }
    m[mink], m[4] = m[4], m[mink]
    for k, v := range m {
        if k != 4 {
            if v % 10 != 0 {
                up := roundUp(v)
                res += int(up)
            } else {
                res += v
            }
        } else {
            res += v
        }
    }
    fmt.Println(res)
}

func roundUp(i int) float64 {
    fi := float64(i) / 10
    ceil := math.Ceil(fi)
    return ceil * 10
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    if(a+b>=10){
        cout<<"error"<<endl;
    }else{
        cout<<a+b<<endl;
    }
}   




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


#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

ll mod = 1000000007ll;
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 ll inf = 1ll << 60;

int n, m, L, R;
int ans = 0;

int gcc(int n, int m) {
    int a = max({n, m});
    int b = min({n, m});
    if(b == 0) return a;
    int c;
    while(a % b != 0){
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}

int main() {
    scanf("%d%d", &n, &m);
    int up = n;
    int down = 1;
    rp(i, 0, m){
        scanf("%d%d", &L, &R);
        chmax(down, L);
        chmin(up, R);
    }
    ans = up - down + 1;
    if(ans < 0) printf("%d", 0);
    else printf("%d", ans);
    return 0;
    
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        String s = bf.readLine();
        int[] a = new int[s.length()];
        int n = s.length();
        for(int i=0; i<s.length(); i++) a[i] = s.charAt(i)-'a';
        Set<Integer> avail = new HashSet<Integer>();
        for(int i=0; i<n; i++) avail.add(a[i]);
        boolean done = false;
        if(n < 26) {
          StringBuilder sb = new StringBuilder();
          for(int i=0; i<n; i++) sb.append((char)('a'+a[i]));
          for(int j=0; j<26; j++) {
            if(!avail.contains(j)) {
              sb.append((char)('a'+j));
              break;
            }
          }
          out.println(sb.toString());
        }
        else {
        hi: for(int i=n-1; i>=0; i--) {
          int cur = a[i];
          avail.remove(a[i]);
          cur++;
          while((cur < 26) && (avail.contains(cur)))
            cur++;
          if(cur != 26) {
            a[i] = cur;
            avail.add(cur);
            done = true;
            break;
          }
        }

        if(!done) out.println("-1");
        else {
          StringBuilder sb = new StringBuilder();
          for(int i=0; i<avail.size(); i++) sb.append((char)('a'+a[i]));
          out.println(sb.toString());
        }
        }
        // Scanner scan = new Scanner(System.in);
        // PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        // int n = Integer.parseInt(bf.readLine());
        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n];
        // for(int i=0; i<n; i++) a[i] =  Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }


}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t;
  cin >>a>>b;
  if(a<6)b=0;
  if(a>=6&&a<13)b/=2;
  cout <<b;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;



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

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    using P = pair<int, int>;
    vector<vector<P>> G(n);
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        a--; b--;
        if(c <= l){
            G[a].emplace_back(b, c);
            G[b].emplace_back(a, c);
        }
    }
    vector<vector<P>> ans(n, vector<P>(n, {INF<int>, INF<int>}));
    for (int i = 0; i < n; ++i) {
        ans[i][i] = {0, 0};
        using tup = pair<pair<int, int>, int>;
        GPQ<tup> Q;
        Q.emplace(P{0, 0}, i);
        while(!Q.empty()){
            P cost; int x;
            tie(cost, x) = Q.top(); Q.pop();
            if(ans[i][x] < cost) continue;
            for (auto &&e : G[x]) {
                auto cost2 = cost;
                cost2.second += e.second;
                if(cost2.second > l){
                    cost2.second = e.second;
                    cost2.first++;
                }
                if(ans[i][e.first] <= cost2) continue;
                ans[i][e.first] = cost2;
                Q.emplace(ans[i][e.first], e.first);
            }
        }
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        cout << (ans[s][t].first == INF<int> ? -1 : ans[s][t].first) << "\n";
    }
    return 0;
}

Measured memory_bytes: 2980
#include<queue>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7ffffff
using namespace std;
int main()
{
    long long n,k,v,t,ans;
    n=0;k=0;v=0;t=0;ans=0;
    scanf("%lld%lld",&n,&k);
    v=n/k;ans=v*v*v;
    if(k%2==0)
    {
    	t=(n/(k/2)+1)/2;
    	ans+=t*t*t; 
	}printf("%lld",ans); 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

istream& operator>> (istream& a, pii& b) {
    cin >> b.first >> b.second;
    return a;
}

ostream& operator<< (ostream& a, const pii& b) {
    cout << "{" << b.first << ", " << b.second << "}";
    return a;
}

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    if (s[0] != s[1] || s[1] != s[2] || s[0] != s[2]) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}
/*

*/  

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

using namespace std;

int n;
string s;

bool check(int L, int R)
{
    while (L < R)
    {
        if (s[L] != s[R])
        {
            return false;
        }
        L++;
        R--;
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    n = s.length();
    s = " " + s;
    cout << (check(1, n) && check(1, (n - 1) / 2) && check((n + 3) / 2, n) ? "Yes" : "No");
    return 0;
}


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

typedef long long ll;

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;

ll dp[MAXV];
int N,W,V,wi[MAXN],vi[MAXN];

int main(){

	cin >> N >> W;
	for(int i = 1;i<=N;i++){
		cin >> wi[i] >> vi[i];
		V += vi[i];
	}

	for(int i = 1;i<=V;i++) dp[i] = INF;
	dp[0] = 0;
	
	for(int item = 1;item<=N;item++){
		int w = wi[item], v = vi[item];
		for(int i = V;i>=v;i--){
			dp[i] = min(dp[i],dp[i - v] + w);
		}
	}

	for(int i = V;i>=0;i--){
		if(dp[i] <= W){
			cout << i << endl;
			break;
		}
	}

	return 0;

}

Measured memory_bytes: 4416
use std::collections::VecDeque;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
    }

    let mut cycle_size = 1e9 as i64;
    let mut result = vec![];
    for start in 0..n {
        let mut q = VecDeque::new();
        let mut dist = vec![-1; n];
        let mut prev = vec![n; n];
        dist[start] = 0;
        q.push_back(start);
        while let Some(v) = q.pop_front() {
            for &next in graph[v].iter() {
                if dist[next] == -1 {
                    dist[next] = dist[v] + 1;
                    q.push_back(next);
                    prev[next] = v;
                } else if next == start && dist[v] + 1 < cycle_size {
                    cycle_size = dist[v] + 1;
                    result.clear();
                    let mut cur = v;
                    while cur != start {
                        result.push(cur);
                        cur = prev[cur];
                    }
                    result.push(cur);
                }
            }
        }
    }

    if result.is_empty() {
        println!("-1");
    } else {
        println!("{}", result.len());
        for ans in result.into_iter() {
            println!("{}", ans + 1);
        }
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using ll = long long;
using pll = pair<long, long>;
#define all(x) (x).begin(), (x).end()

int main() {

    ll n;
    cin >> n;
    ll count_b_b = 0;
    ll count_e_a = 0;
    ll count_both = 0;
    ll ans = 0;

    for (auto i = 0; i < n; i++) {
        string tmp;
        cin >> tmp;

        bool flag = false;
        for (auto j = 0; j < tmp.size() - 1; j++) {
            if (tmp[j] == 'A' && tmp[j + 1] == 'B')
                ans++;
        }

        if (tmp[0] == 'B') {
            if (tmp.back() == 'A')
                count_both++;
            else
                count_b_b++;
        } else {
            if (tmp.back() == 'A')
                count_e_a++;
        }
    }

    if (count_both != 0)
    {
        ans += count_both - 1;
        if (count_b_b != 0)
        {
            ans += 1;
            count_b_b -= 1;
        }

        if (count_e_a != 0)
        {
            ans += 1;
            count_e_a -= 1;
        }

        ans += min(count_b_b, count_e_a);
    } else {
        ans += min(count_b_b, count_e_a);
    }





    cout << ans;

    return 0;
}

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

def fib(n):
  a, b = 1, 1
  for i in range(n):
    a, b = b, a+b
  return a

ans  = 1
last = 0
for _ in range(M):
  a = int(input())
  if a == last:
    ans = 0
  ans *= (fib(a-1-last) % MOD)
  last = a + 1

  
ans *= (fib(N - last) % MOD)
print(ans%MOD)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
    int n, m, sum = 0, cnt = 0;
    cin >> n >> m;
    int l[100010], r[100010];
    for(int i = 0; i < m; i++){
        cin >> l[i] >> r[i];
    }
    int down = l[0];
    int up = r[0];

    for(int i = 1; i < m; i++){
        if(l[i] > down)down = l[i];
        if(r[i] < up)up = r[i];
    }


    if(up >= down)cout << up - down + 1;
    else cout << 0;
    return 0;
}


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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class T> ostream& operator<<(ostream &os, set<T> S){os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}";}
#ifdef np
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "<<arg1<<endl;}
template<typename Arg1, typename ... Args>void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,','); cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif


int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
	
	int N ; string s;
	cin >> N >> s;
    s.erase(unique(all(s)),s.end());
    cout << s.size() << endl;

#ifdef np
    cerr <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
 return 0; 
 }


Measured memory_bytes: 512
from heapq import *
import bisect

k,t=map(int,input().split())
a=sorted([-int(i) for i in input().split()],reverse=True)

heapify(a)
while len(a)>=2:
 max=heappop(a)
 min=a.pop(-1)
 if max+1<=-1:
  bisect.insort(a,max+1)
 if min+1<=-1:
  heappush(a,min+1)
if a:
 print(abs(a[0]+1))
else:
 print(0)

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

int main(){
  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x = x2 - x1;
  int y = y2 - y1;
  cout << x2-y <<' '<< y2+x <<' '<< x1-y <<' '<< y1+x << endl;  
  return 0;
}

Measured memory_bytes: 256
use std::io::{Read, StdoutLock};
use std::io::{stdout, BufWriter, Write};
use std::collections::{HashMap, VecDeque};
use std::str::{SplitWhitespace, FromStr};
use std::fmt::Display;

struct IO<'a> {
    sw: SplitWhitespace<'a>,
    bw: BufWriter<StdoutLock<'a>>
}

impl IO<'_> {
    pub fn read<T: FromStr>(&mut self) -> T where <T as std::str::FromStr>::Err: std::fmt::Debug {
        self.sw.next().unwrap().parse().unwrap()
    }
    pub fn writeln<T: Display>(&mut self, s: T) {
        let bytes = format!("{}\n", s);
        self.bw.write(bytes.as_bytes()).unwrap();
    }
}

// AtCoder Beginner Contest 146 D - Coloring Edges on Tree
fn main() {
    /* BEGIN TEMPLATE */
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let sw = buf.split_whitespace();
    let _stdout = stdout();
    let bw = BufWriter::new(_stdout.lock());
    let mut io = IO{sw, bw};
    /* END TEMPLATE */

    let n: usize = io.read();
    let mut tree: Vec<Vec<usize>> = vec![Vec::new(); n+1];
    let mut edges: Vec<(usize, usize)> = Vec::with_capacity(n-1);
    let mut edge_colors: HashMap<(usize, usize), usize> = HashMap::new();
    (0..n-1).for_each(|_| {
        let (a, b): (usize, usize) = (io.read(), io.read());
        tree[a].push(b);
        tree[b].push(a);
        if a < b {
            edges.push((a, b));
        } else {
            edges.push((b, a));
        }
    });
    let mut colors: Vec<usize> = vec![0; n+1];
    let mut done = vec![false; n+1];
    done[1] = true;
    colors[1] = 0;
    let mut count = colors[1];
    let mut queue: VecDeque<usize> = VecDeque::new();
    queue.push_back(1);
    while !queue.is_empty() {
        let length = queue.len();
        (0..length).for_each(|_|{
            let mut color: usize = 0;
            let front = queue.pop_front().unwrap();
            tree[front].iter().for_each(|&t|{
                if !done[t] {
                    color += 1;
                    if color == colors[front] {
                        color += 1;
                    }
                    colors[t] = color;
                    if color > count {
                        count = color;
                    }
                    done[t] = true;
                    queue.push_back(t);
                    if front < t {
                        *edge_colors.entry((front, t)).or_default() = color;
                    } else {
                        *edge_colors.entry((t, front)).or_default() = color;
                    }
                }
            });
        })
    }
    io.writeln(count);
    edges.iter().for_each(|&edge| {
        io.writeln(edge_colors.entry(edge).or_default());
    })
}

Measured memory_bytes: 16752
import fractions as math

a,b,c,d = map(int,input().split())

#cの培数の数を調べる
num_c = (b//c) - ((a-1)//c)

#dの培数の数を調べる
num_d = (b//d) - ((a-1)//d)

#dの培数の数を調べる
lcm = c*d//(math.gcd(c,d))
num_cd = (b//lcm) - ((a-1)//lcm)

print(b - a + 1 - num_c - num_d + num_cd)

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


int main()
{
    int N,X;
    int L[100];
    std::cin >> N >> X;
    for(int i=0; i<N; i++){
        std::cin >> L[i];
    }
    int D[200]={};
    int count=1;
    D[0]=0;
    for(int i=0; i<N; i++){
        D[i+1] = D[i]+L[i];
        if(D[i+1]<=X){
            count++;
        }
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF LLONG_MAX/100000

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;


static const int MAX = 2500;

int d[MAX];
WeightGraph WG(MAX);


// true if negative loop, false if no negative loop
// O (|E| * |V|)
bool bellman_ford(const WeightGraph& WG, int (&d)[MAX], const int &n, const int& s) {
  // initialize to INF except the starting node
  for (int i = 0; i < n; i++) {
    d[i] = INF;
  }
  d[s] = 0;

  int flag;
  for (int i = 0; i < 2 * n; i++) {
    if (i == n - 1) {
      flag = d[0];
    }
    for (int v = 0; v < n; v++) {
      for (auto adjacent : WG[v]) {
        int nv = adjacent.first;
        int nd = adjacent.second;
        if (d[v] != INF && d[nv] > d[v] + nd) {
          d[nv] = d[v] + nd;
          if (i == n - 1) {
            // cout << "negative loop" << endl;
            d[nv] -= INF;
          }
        }
      }
    }
  }

  // for (int i = 0; i < n; i++) {
  //   cout << d[i] << endl;
  // }
  return d[0] == flag;
}


signed main() {
  int N, M, P; cin >> N >> M >> P;

  Graph G(N);
  
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--; c -= P; c = -1*c;
    G[b].push_back(a);
    WG[b].push_back(Pi(a, c));
  }

  // DAG dg(G);
  // dg.tsort();
  // if (dg.is_acyclic == false) {
  //   cout << -1 << endl;
  //   return 0;
  // }

  // Pi A =  bellman_ford(WG, d, N, N-1);

  // if (!A.first) {
  //   cout << -1 << endl;
  //   return 0;
  // } else {
  //   if (A.second <= -1*INF/100) {
  //     cout << -1 << endl;
  //   } else if ( A.second > 0) {
  //     cout << 0 << endl;
  //   } else {
  //     cout << -1 * A.second << endl;
  //   }
  // }

  if (!bellman_ford(WG, d, N, N-1)) {
    cout << -1 << endl;
  } else {
    if (d[0] > 0) {
      cout << 0 << endl;
    } else {
      cout << -1 * d[0] << endl;
    }
  }
  
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

struct edge { int to,cost; };
struct ftedge { int from,to,cost; };

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  int H,W;cin>>H>>W;
  vector<string> grid(H);
  REP(i,H) cin>>grid[i];

  // ひとつひとつ探していって最大個数 = O(H*W*H*W)
  // 点を決めて、上下左右にloopをかける必要がある
  // まず縦にloopしていって、それぞれ
  // wcnt[h][w]を用意して、その点が横向きに連続で持っている数を保存していく
  // hcntも同様
  // 最後にH*Wでループして、合計の最大値

  int wcnt[H][W],hcnt[H][W];
  REP(h,H)REP(w,W) {
    wcnt[h][w] = 0;
    hcnt[h][w] = 0;
  }
  REP(h,H) {
    wcnt[h][0] = grid[h][0]=='#' ? 0 : 1;
    FOR(w,1,W) {
      if (grid[h][w]=='#') {
        wcnt[h][w] = 0;
      } else {
        wcnt[h][w] = wcnt[h][w-1]+1;
      }
    }
    for (int w=W-2;w>=0;w--) {
      if (wcnt[h][w]==0) continue;
      wcnt[h][w] = max(wcnt[h][w],wcnt[h][w+1]);
    }
  }
  REP(w,W) {
    hcnt[0][w] = grid[0][w]=='#' ? 0 : 1;
    FOR(h,1,H) {
      if (grid[h][w]=='#') {
        hcnt[h][w] = 0;
      } else {
        hcnt[h][w] = hcnt[h-1][w]+1;
      }
    }
    for (int h=H-2;h>=0;h--) {
      if (hcnt[h][w]==0) continue;
      hcnt[h][w] = max(hcnt[h][w],hcnt[h+1][w]);
    }
  }

  int ans = 0;
  REP(h,H)REP(w,W) {
    ans = max(ans, wcnt[h][w]+hcnt[h][w]-1);
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  if(A%2==1||B%2==1||C%2==1){
    cout << 0 << endl;
    return 0;
  }
  if(A==B&&B==C){
    cout << -1 << endl;
    return 0;
  }
  ll ans = 0;
  while(A%2==0&&B%2==0&&C%2==0){
    ll a = A / 2, b = B / 2, c = C / 2;
    A =  b  + c ;
    B =  a  + c ;
    C =  a  + b ;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    ll N,A,B,C,D,E;
    cin>>N>>A>>B>>C>>D>>E;
    ll R=min(A,min(B,min(C,min(D,E))));
    ll k=(N-1)/R+1;
    cout<<k+4<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;

typedef long long int int64;

int main(int argc, char **argv)
{
    int H, W;
    cin >> H >> W;
    int64 count;
    if (H == 1 || W == 1) {
        count = 1;
    }
    else {
        count = (int64)(W) * (int64)(H / 2);
        if (H % 2 == 1) {
            count += (int64)((W + 1) / 2);
        }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int n,m,r;
vi route;
vvi L,S;

int solve(){
    vvi dp(r,vi(n,INF));
    dp[0][route[0]]=0;
        //i番目の集配が終了した時点で、頂点jに船を乗り捨てているときの累計コスト
    rep(p,r-1){
        int s=route[p],t=route[p+1];
        rep(i,n)rep(j,n){
            //cout<<s<<"->"<<i<<"->"<<j<<"->"<<t<<endl;
            //cout<<vi{dp[p][i],L[s][i],S[i][j],L[j][t]}<<endl;
            if(dp[p][i]!=INF and L[s][i]!=INF and S[i][j]!=INF and L[j][t]!=INF){
				if(i==j)
					dp[p+1][j]=min(dp[p+1][j],dp[p][i]+L[s][t]);
				else
					dp[p+1][j]=min(dp[p+1][j],dp[p][i]+L[s][i]+S[i][j]+L[j][t]);
            }
        }
        //cout<<p+1<<":"<<dp[p+1]<<endl;
    }
    return *min_element(all(dp[r-1]));
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	while(cin>>n>>m,n){
	    L=vvi(n,vi(n,INF));
	    S=vvi(n,vi(n,INF));
	    rep(_,m){
	        int x,y,t; char c;
	        cin>>x>>y>>t>>c;
	        x--;y--;
			t=min((c=='L'?L:S)[x][y],t);
	        (c=='L'?L:S)[x][y]=(c=='L'?L:S)[y][x]=t;
	    }
	    rep(k,n)rep(i,n)rep(j,n)if(i!=j){
	        if(L[i][k]!=INF&&L[k][j]!=INF)
	            L[i][j]=min(L[i][j],L[i][k]+L[k][j]);
	        if(S[i][k]!=INF&&S[k][j]!=INF)
	            S[i][j]=min(S[i][j],S[i][k]+S[k][j]);
	    }else L[i][j]=S[i][j]=0;
	    cin>>r;
	    route.resize(r);
	    rep(i,r){
	        cin>>route[i];
	        route[i]--;
	    }
	    cout<<solve()<<endl;
	}
	return 0;
}



Measured memory_bytes: 4112
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int mod=1e9+7;
const int N=2010,M=4000100;
const int maxn=4000000;
int dp[N*2][N];
int cj[M],inv[M];
int ans;

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

int power(int x,int y){
	int ret=1;
	for(;y;y>>=1,x=1ll*x*x%mod){
		if(y&1)	ret=1ll*ret*x%mod;
	}
	return ret;
}

int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n,K,i,j,k;
	scanf("%d%d",&n,&K);
	if(K==1){printf("1\n");return 0;}
	for(cj[0]=1,i=1;i<=maxn;i++)	cj[i]=1ll*cj[i-1]*i%mod;
	inv[maxn]=power(cj[maxn],mod-2);inv[0]=1;
	for(i=maxn-1;i;i--)	inv[i]=1ll*inv[i+1]*(i+1)%mod;
	dp[0][0]=1;
	rep(i,0,2*n-1)	rep(j,0,n)	if(dp[i][j]){
		k=(i-j)/2;
		dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod;		
		if(j)	dp[i+1][j-1]=(dp[i+1][j-1]+1ll*dp[i][j]*C(n*K-i-1-(K-2)*k,K-2))%mod;
	}
	ans=1ll*dp[2*n][0]*cj[n]%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 62848
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

string S;
ll ans;
 
int main(void) {
    
    cin >> S;
    int n = S.size();
    for (int i = 0; i < 1 << n-1; i++) {
      int s = 0;
      while(s < n) {
        int t = s+1;
        while (!((i>>(t-1)) & 1) && t < n) t++;
        ans += stoll(S.substr(s, t-s));
        s = t;
      }
    }
    
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const int MX = 1000005, mod = 998244353;
int n, a[MX], cn[MX], val[MX], sq[MX], mx;
ll res = 0;

ll pot (ll b, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= b) %= mod;
		(b *= b) %= mod;
		p /= 2;
	}
	return res;
}

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

	cin >> n;
	forn (i, n) {
		cin >> a[i];
		cn[a[i]]++;
		mx = max(mx, a[i]);
	}

	for (int i = 1; i <= mx; i++) {
		val[i] = pot(i, mod - 2);
		sq[i] = 1ll * cn[i] * (cn[i] - 1) / 2 % mod * i % mod * i % mod;
	}

	for (int i = 1; i <= mx; i++) {
		ll s = 0, rs = 0;

		for (int j = i; j <= mx; j += i) {
			if (j != i) val[j] -= val[i];
			if (val[j] < 0) val[j] += mod;
			(rs += s * j % mod * cn[j] + sq[j]) %= mod;
			(s += 1ll * j * cn[j]) %= mod;
		}

		(res += rs * val[i]) %= mod;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N); for (auto &a : A) cin >> a;
    int ng = 0, ok = *max_element(begin(A), end(A));
    while (ok - ng > 1) {
        int mid = (ok + ng) / 2;
        int cnt = 0;
        for (auto a : A) {
            cnt += (a + mid - 1) / mid - 1;
        }
        if (cnt > K) {
            ng = mid;
        } else {
            ok = mid;
        }
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 3912
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
// namespace mp = boost::multiprecision;
// using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
// using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

struct s_t{
  ll b,c;
};

bool asc(s_t left,s_t right) {
  return left.c == right.c ? left.b < right.b : left.c < right.c;
}

int main(){
  ll n,m;
  cin>>n>>m;
  multiset<ll> a;
  vector<ll>v;
  vector<s_t>vv;
  ll z;
  s_t zz;
  for(ll i=0;i<n;i++){
    cin>>z;
    a.insert(z);
  }
  for(ll i=0;i<m;i++){
    cin>>zz.b>>zz.c;
    vv.push_back(zz);
  }
  sort(vv.begin(),vv.end(),asc);
  auto itt=vv.end();
  itt--;
  ll tmp=itt->c;


  while(a.size()){
    auto itr=a.end();
    itr--;
    if(*(itr)>=tmp){
      v.push_back(*(itr));
      a.erase((itr));
    }
    else{
      auto it=vv.end();
      it--;
      a.erase(a.begin());
      v.push_back(tmp);
      it->b--;
      if(it->b==0){
        vv.pop_back();
        it=vv.end();
        it--;
        if(vv.size()){
          tmp=it->c;
        }
        else{
          tmp=-1;
        }
      }
    }
  }
  ll ans=0;
  for(ll i=0;i<n;i++){
    ans+=v[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 8308
program ABC073C
    implicit none
    integer(8)::N,same_count,i
    integer(8)::result=0
    integer(8),allocatable,dimension(:)::A
    read(5,*)N
    allocate(A(N))
    read(5,*)(A(i),i=1,N)
    A=iqsort(A)

    do i=1,N
        if(i==1)then
            same_count=1
        else if(A(i)==A(i-1))then
            same_count=same_count+1
        else
            if(mod(same_count,2)==1)then
                result=result+1
            end if
            same_count=1
        end if
    end do

    if(mod(same_count,2)==1)then
        result=result+1
    end if
    
    print'(i0)',result
contains
    recursive function iqsort(ix) result(ires)
      integer(8), allocatable :: ires(:)
      integer(8), intent(in)  :: ix(:)
      integer :: k
      if (size(ix) <= 1) then 
        ires = ix
      else  
        k = ix(size(ix) / 2)
        ires = [iqsort(pack(ix, ix < k)), pack(ix, ix == k), iqsort(pack(ix, ix > k))] 
      end if
    end function iqsort
end program ABC073C

Measured memory_bytes: 5468
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int a[4], b[4];
    int i, j;
    int hit, blow;
 
    while (scanf("%d%d%d%d", &a[0], &a[1], &a[2], &a[3]) == 4) {
        scanf("%d%d%d%d", &b[0], &b[1], &b[2], &b[3]);
        hit = blow = 0;
        for (i = 0; i < 4; i++) {
            if (a[i] == b[i]) hit++, a[i] = -1, b[i] = -2;
        }
        if (hit < 4) {
            for (i = 0; i < 4; i++) {
                if (a[i] < 0) continue;
                for (j = 0; j < 4; j++) {
                    if (a[i] == b[j]) blow++;
                }
            }
        }
        printf("%d %d\n", hit, blow);
    }
    return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int i, N, K, X, Y, cost = 0;

	cin >> N >> K >> X >> Y;
	for (i = 0; i < N; i++)
	{
		if (i < K)
		{
			cost += X;
		}
		else
		{
			cost += Y;
		}
	}
	cout << cost;
}

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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

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

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }






int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    REP(i, N) cin >> L[i];
    sort(all(L));
    ll cnt = 0;
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            for(int k = j + 1; k < N; k++){
            if(L[i] + L[j] <= L[k]) break;
                if(L[i] < L[j] + L[k] && L[j] < L[k] + L[i] && L[k] < L[i] + L[j]) cnt++;
            }
        }
    }

print(cnt);
}



Measured memory_bytes: 256
#include <stdio.h>

int SizeGet(int i, int N, int *d);
int Sort(int N,int *d);

int main(void){
	int N;
	int d[100] = {0};
	scanf("%d",&N);
	SizeGet(0, N,&d[0]);

	printf("%d",Sort(N, &d[0]));

	return 0;
}


int SizeGet(int i, int N, int *d){
	scanf("%d",&d[i]);
	if(i < (N -1))	SizeGet(i+1,N,d);
	
	return 0;
}

int Sort(int N,int *d){
	int j = 0;
	for(int k = 0; k < 100; k++){
		for(int i = 0; i < N; i++){
			if((100 - k) == d[i]){
				j++;
				break;
			}
		}
	}
	return j;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MaxN = 100003;
int n,a[MaxN];
LL sum[MaxN],asum[MaxN],dp[MaxN];
int main() {
    scanf("%d%d",&n,a+1);
    for (int i=2;i<=n;++i) {
        char ch;
        scanf(" %c %d",&ch,a+i);
        if (ch=='-') a[i]*=-1;
    }
    for (int i=n,j=0;i>=1;--i) {
        sum[i]=sum[i+1]+a[i];
        asum[i]=asum[i+1]+abs(a[i]);
        dp[i]=0x8000'0000'0000'0000LL;
        if (a[i]<0) {
            if (j) dp[i]=-sum[i+1]+sum[j]+asum[j]+a[i];
            j=i;
        }
        dp[i]=max(dp[i],dp[i+1]+a[i]);
    }
    printf("%lld\n",dp[1]);
    return 0;
}

Measured memory_bytes: 2944
s_num = gets.to_i
s_arr = gets.split.map(&:to_i)
t_num = gets.to_i
t_arr = gets.split.map(&:to_i)

cnt = 0

for t in t_arr do
  s_idx = 0
  e_idx = s_num - 1
  
  while s_idx <= e_idx do
    mid_idx = ((e_idx - s_idx) / 2).to_i + s_idx
    s_mid = s_arr[mid_idx]
    
    if s_mid == t then
      cnt += 1
      break
    end
    if s_idx === e_idx then
      break
    end
    if t < s_mid then
      e_idx = mid_idx - 1
    else
      s_idx = mid_idx + 1
    end
  end
end

puts cnt

Measured memory_bytes: 17232
from itertools import permutations
from math import hypot
N = int(input())
XY = [tuple(map(int,input().split())) for i in range(N)]

tmp = n = 0
for ptn in permutations(XY):
    n += 1
    for (x1,y1),(x2,y2) in zip(ptn,ptn[1:]):
        tmp += hypot(x1-x2, y1-y2)
print(tmp / n)

Measured memory_bytes: 3064
L = int(input())
N = min(L.bit_length()-1, 19) + 1
base = (1 << N - 1) - 1

edges = []
for i in range(1, N):
  edges.append([i, i+1, 0])
  edges.append([i, i+1, 1<<(i-1)])

for t in range(N-1, 0, -1):
  l = 1 << (t-1)
  if L - l > base:
    edges.append([t, N, L - l])
    L -= l

M = len(edges)
print(N, M)
for edge in edges:
  print(*edge)

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<int> a(n), c(n);
  rep(i, n)cin>>a[i];
  ll result=1;
  rep(i, n){
    if(a[i]==0){
      result *= (3-c[0]);
    }else{
      result *= (c[a[i]-1] - c[a[i]]);
    }
    result %= MOD;

    c[a[i]]++;
  }

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;

int n;
int a[3][110];
int main(){
  cin>>n;
  rep(i,2){
    rep(j,n){
      cin>>a[i][j];
    }
  }

  int ans=-1;
  for(int k=0;k<n;k++){
    int temp_ans=0;
    for(int j=0;j<n;j++){
      if(j>k){
        temp_ans+=a[1][j];
      }else if(j==k){
        temp_ans+=a[1][j];
        temp_ans+=a[0][j];
      }else{
        temp_ans+=a[0][j];
      }
    }
    dump(ans);
    ans=max(ans,temp_ans);
  }

  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
double Emat(double a,double b,double c,double d);

int main(){
	double a,b,c,d,e,f;
	while(cin>>a>>b>>c>>d>>e>>f){
		
		int x=Emat(c,b,f,e)/Emat(a,b,d,e)*1000;
		int y=Emat(a,c,d,f)/Emat(a,b,d,e)*1000;
		double xd=x/1000.0;
		double yd=y/1000.0;

		printf("%.3f %.3f\n",xd,yd);
		
	}
	return 0;
}

double Emat(double a,double b,double c,double d){
	return a*d-b*c;
}

Measured memory_bytes: 1236
g=[[0]*5 for _ in[0]*5]
for i in range(9):
 e=input()
 for j in range(4+i%2):
  if int(e[j]):
   if i%2:g[i//2][j]+=4;g[i//2+1][j]+=1
   else:r=g[i//2];r[j]+=2;r[j+1]+=8
y,x=0,1
k=1
a='1'
while 1:
 k+=2
 for _ in[0]*4:
  k+=1
  if g[y][x]&int(2**(k%4)):a+=str(k%4);break
 if k%2:x+=[1,-1][(k%4)>1]
 else:y+=[-1,1][(k%4)>0]
 if x+y==0:break
print(''.join('URDL'[int(c)]for c in a))


Measured memory_bytes: 5608
#include <iostream>

#include <string>

using namespace std;

int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};

int main(){

	int d;

	cin >> d;

	for(int t = 0;t < d;t++){

		if(t) cout << endl;

		char s[102][102];

		int n;

		cin >> n;
		
		if(n == 1){
			cout << "#" << endl;
			continue;
			}

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

			for(int j = 0;j < n;j++) s[i][j] = ' ';

		}

		int x = n - 1,y = 0,dir = 0;

		for(int k = 0;k < n;k++){

			bool flag = false;

			while(1){

				int nx = x + dx[dir],ny = y + dy[dir];

			 if(nx < 0 || nx >= n + 1 || ny < 0 || ny >= n + 1 || s[nx][ny] == '#') break;

s[x][y] = '#';

flag = true;

				x = nx;

				y = ny;

			}

if(x)x -= dx[dir];

if(y)y -= dy[dir];

			if(!flag) break;

			dir = (dir + 1) % 4;

		}

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

for(int j = 0;j < n;j++){

cout << s[i][j];

}

cout << endl;}

	}

}

Measured memory_bytes: 3052
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n,k;cin>>n>>k;
    vll a(200001,0);
    rep(i,n){
        ll b;
        cin>>b;
        a[b]++;
    }

    ll cnt=0;
    priority_queue<ll, vector<ll>,greater<ll>> q;
    rep(i,200001){
        if(a[i]!=0){
            q.push(a[i]);
            cnt++;
        }
    }

    if(k==n) cout<<0<<endl;
    else{
        ll ans=0;
        rep(i,cnt-k){
            int num=q.top();
            q.pop();
            ans+=num;
        }

        cout<<ans<<endl;
    }
}

Measured memory_bytes: 6816