akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

struct Edge {
    int to, d;
    Edge() {}
    Edge(int to, int d) : to(to), d(d) {}
};

int N, M;
vector<vector<Edge>> G;
vector<bool> seen;
vector<int> dist;

bool dfs(int v) {
    seen[v] = true;
    for (auto g : G[v]) {
        if (!seen[g.to]) {
            dist[g.to] = dist[v] + g.d;
            if (!dfs(g.to)) return false;
        } else {
            if (dist[g.to] != dist[v] + g.d) return false;
        }
    }
    return true;
}

int main() {
    int N, M; cin >> N >> M;
    G.resize(N);
    REP(i, 0, M) {
        int l, r, d; cin >> l >> r >> d; l--; r--;
        G[l].push_back({r, d});
        G[r].push_back({l, -d});
    }

    seen.resize(N, false);
    dist.resize(N, false);
    REP(i, 0, N) {
        if (seen[i]) continue;
        if (!dfs(i)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 14960
#include <stdio.h>

int main(void){
  int n , m , x;
  scanf("%d %d %d",&n,&m,&x);
  
  int a[m];
  for(int i = 0;i < m;i ++){
    scanf("%d",&a[i]);
  }
 int hidari = 0 , migi = 0;
  
  for(int i = 0;i < m;i ++){
    if(a[i] < x){
      hidari++;
    }
    else if(x < a[i]){
      migi++;
    }
  }
  printf("%d",(hidari<migi?hidari:migi));
  
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007

int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int a_sum = 0;
    rep(i, n){
        cin >> a.at(i);
        a_sum += a.at(i);
    }
    int cnt = 0;
    rep(i,n){
        if((double)a.at(i)>=a_sum/(4.0*m))
            cnt++;
    }
    if(cnt>=m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
    }


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

/**
 * Union-Find tree.
 * Verified by yukicoder No.94 (http://yukicoder.me/submissions/82111)
 */
struct UnionFind { disj: Vec<usize> }

impl UnionFind {
    fn new(n: usize) -> Self {
        let mut disj = vec![0; n];
        for i in 0 .. n {
            disj[i] = i;
        }
        UnionFind { disj: disj }
    }
    fn root(self: &mut Self, x: usize) -> usize {
        if x != self.disj[x] {
            let par = self.disj[x];
            let r = self.root(par);
            self.disj[x] = r;
        }
        return self.disj[x];
    }
    fn unite(self: &mut Self, x: usize, y: usize) {
        let xr = self.root(x);
        let yr = self.root(y);
        self.disj[xr] = yr;
    }
    fn is_same_set(self: &mut Self, x: usize, y: usize) -> bool {
        return self.root(x) == self.root(y);
    }
}


fn ask(q: &[bool]) -> i32 {
    let mut s = String::new();
    for &c in q.iter() {
        s.push(if c { '1' } else { '0' });
    }
    println!("? {}", s);
    get()
}

fn solve() {
    let n: usize = get();
    // n == 200
    // n * (n - 1) / 2 queries
    let mut pool = Vec::new();
    let mut uf = UnionFind::new(n);
    for i in 0 .. n {
        for j in 0 .. i {
            if pool.len() >= n - 1 {
                break;
            }
            if uf.is_same_set(i, j) { continue; }
            let mut v = vec![false; n];
            v[i] = true;
            v[j] = true;
            if ask(&v) == 1 {
                pool.push((i, j));
                uf.unite(i, j);
            }
        }
    }
    print!("!");
    for (u, v) in pool {
        print!(" ({},{})", u, v);
    }
    println!("");
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 9040
use proconio::input;
use proconio::marker::Chars;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
macro_rules! maxs {
    ($x:expr, $($y:expr), *) => {{
        let mut ret = $x;
        $(
            ret = max(ret, $y);
        )*
        ret
    }};
}
fn main() {
    input!(mut S: Chars);
    let N = S.len();
    let last = S[N - 1];
    if last == 's' {
        S.push('e');
        S.push('s');
    } else {
        S.push('s');
    }

    for c in S {
        print!("{}", c);
    }
    println!();
}


Measured memory_bytes: 2164
#include <iostream>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    string S;
    cin >> S;
    ll count = 0;
    ll start = 0;
    ll N = S.size();
    ll As = 0;
    for (int i = 0;i<N;i++){
        if(i != 0 && (
                (S[i-1] == 'B' && S[i] == 'B' )
                || (S[i-1] == 'C' && S[i] == 'C' )
                || (S[i-1] == 'B' && S[i] == 'A' )
                || (S[i-1] == 'A' && S[i] == 'C' )
            )
        ){
            As = 0;
        }

        if(S[i] == 'A'){
            As++;
        }else if (S[i-1] == 'B' && S[i] == 'C'){
            count += As;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

int main() {
  string s;
  cin >> s;
  int c = 1000;
  for(int i = 0; i < s.size()-2; i++) {
    int a = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + s[i+2] - '0';
    if(abs(753 - a) < c) {
      c = abs(753-a);
    }
  }
  cout << c;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

unordered_map<ll, int> factors(ll n){
    unordered_map<ll, int> d;
    for(ll i = 2; i*i <= n; i ++) while(n % i == 0) d[i] ++, n /= i;
    if(n > 1) d[n] ++;
    return d;
}

int main(void){
    Cin(ll, a, b);
    ll n = gcd(a, b);
    auto p = factors(n);
    int ans = 0;
    for(auto e : p) ans ++;
    Cout(ans+1);
}




Measured memory_bytes: 256
#include <set>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

const int mod = 1000000007;
int a[10000 + 10];
int dp[200][10000 + 10];
int w, n;

int memo;
int solve(int pos, int rest){
  if(pos == n)
    return rest < a[memo] ? 1 : 0;

  if(dp[pos][rest] != -1)
    return dp[pos][rest];

  int ret = 0;
  ret = (ret + solve(pos + 1, rest)) % mod;
  if(rest >= a[pos])
    ret = (ret + solve(pos + 1, rest - a[pos])) % mod;

  return dp[pos][rest] = ret;
}

int main(){
  int ans = 0;
  n   = getInt();
  w   = getInt();

  REP(i,n) a[i] = getInt();

  sort(a, a + n);


  int sum = 0;
  REP(i,n){
    memset(dp, -1, sizeof(dp));
    memo = i;
    ans = (ans + solve(i + 1, w - sum)) % mod;
    sum += a[i];
    if(sum > w) break;
  }
  if(sum <= w) ans++;
  if(ans == 0) ans = 1;

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 8548
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
 
int main() {

int a;cin>>a;
  ll huge=1;
  REP(i,1,a+1){huge=(huge*i)%1000000007;}
  
  cout<<huge<<endl;

  
  
}

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

int main(){
  int n,r;
  while(cin >> n >> r, n){
    int npos[100];
    for(int i=n-1,j=0;i>=0;i--,j++){
      npos[j] = i+1;
    }
    for(int i=0;i<r;i++){
      int a,b;
      cin >> a >> b;
      int tmp[b];
      for(int j=0;j<b;j++){
	tmp[j] = npos[j+a-1];
      }
      for(int j=a+b-2;j>=b;j--){
	npos[j] = npos[j-b];
      }
      for(int j=0;j<b;j++){
	npos[j] = tmp[j];
      }
    }
    cout << npos[0] << endl;
  }
}

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

using i64 = long long int;

struct Edge{
    i64 from, to, yen, snuuk;
};

struct Node{
    i64 n, cost;
    bool operator<(const Node& obj)const{
        return cost > obj.cost;
    }
};

vector<Edge> graph[100005];

i64 min_yen[100005], min_snuuk[100005];

int main(){
    i64 n, m, s, t;
    cin >> n >> m >> s >> t;
    for(int i=0;i<m;++i){
        i64 u, v, a, b;
        cin >> u >> v >> a >> b;
        graph[u].push_back((Edge){u, v, a, b});
        graph[v].push_back((Edge){v, u, a, b});
    }
    for(int i=0;i<=n;++i){
        min_yen[i] = LLONG_MAX;
        min_snuuk[i] = LLONG_MAX;
    }
    min_yen[s] = 0;
    min_snuuk[t] = 0;
    priority_queue<Node> que_yen, que_snuuk;
    que_yen.push((Node){s, 0});
    while(!que_yen.empty()){
        Node curr = que_yen.top(); que_yen.pop();
        for(auto e : graph[curr.n]){
            if(min_yen[e.to] > curr.cost + e.yen){
                min_yen[e.to] = curr.cost + e.yen;
                que_yen.push((Node){e.to, curr.cost + e.yen});
            }
        }
    }
    que_snuuk.push((Node){t, 0});
    while(!que_snuuk.empty()){
        Node curr = que_snuuk.top(); que_snuuk.pop();
        for(auto e : graph[curr.n]){
            if(min_snuuk[e.to] > curr.cost + e.snuuk){
                min_snuuk[e.to] = curr.cost + e.snuuk;
                que_snuuk.push((Node){e.to, curr.cost + e.snuuk});
            }
        }
    }

    vector<pair<i64, i64>> v;
    for(i64 i=1;i<=n;++i)v.emplace_back(min_yen[i] + min_snuuk[i], i);
    sort(v.begin(), v.end());
    int idx = 0;
    for(int i=0;i<n;++i){
        while(v[idx].second <= i)idx++;
        cout << 1000000000000000 - v[idx].first << endl;
    }

    return 0;
}


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

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut a = vec![0u64; n];
    let mut b = vec![0u64; n];
    let mut e = vec![];
    for i in 0..n {
        a[i] = it.next().unwrap().parse().unwrap();
        b[i] = it.next().unwrap().parse().unwrap();
        e.push((a[i], 1, i));
        e.push((b[i], 2, i));
    }
    e.sort_by_key(|e| e.0);
    let mut set = vec![std::collections::BTreeSet::new(); 4];
    for i in 0..n {
        set[0].insert(i);
    }
    let mut sum = 0;
    for i in 0..n {
        let (c, b, k) = e[i];
        sum += c;
        for j in (0..3).rev() {
            if set[j].contains(&k) {
                set[j].remove(&k);
                set[j | b].insert(k);
            }
        }
    }
    if !set[0].is_empty() || set[1].len() == n || set[2].len() == n {
        println!("{}", sum);
        return;
    }
    let mut ans = std::u64::MAX;
    for &(c, _, k) in &e[n..(n + 2)] {
        for &u in &set[1] {
            if u != k || set[1].len() == 1 {
                ans = std::cmp::min(ans, sum - a[u] + c);
            }
        }
        for &u in &set[2] {
            if u != k || set[2].len() == 1 {
                ans = std::cmp::min(ans, sum - b[u] + c);
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 17520
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    bool flag=true;
    while(k){
        if(flag){
            a/=2;
            b+=a;
            flag=false;
        }else{
            b/=2;
            a+=b;
            flag=true;
        }   
        k--;
    }
    cout<<a<<" "<<b<<endl;

}

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

int main(void){
    int n;
    cin >> n;

    n %= 10;

    if(n==2 || n==4||n==5||n==7||n==9){
        cout << "hon" << endl;
    }
    if(n==0 || n==1||n==6||n==8){
        cout << "pon" << endl;
    }
    if(n==3){
        cout << "bon" << endl;
    }
}

Measured memory_bytes: 3636
#include <cstdio>

int area(const int x, const int y) {
  return x * y;
}

int perimeter(const int x, const int y) {
  return (x * 2) + (y * 2);
}

int main() {
  int a,b;
  scanf("%d %d", &a, &b);
  printf("%d %d\n", area(a, b), perimeter(a, b));
  return 0;
}


Measured memory_bytes: 2596
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;

int N, M;
Graph G;
vector<int> res;
const long long INF = 1LL << 60;

int main() {
    cin >> N >> M;
    G.assign(N, vector<int>());
    rep(i, 0, M) {

        int a, b;
        cin >> a >> b;
        ;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while(!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for(int nv : G[v]) {
            if(dist[nv] != -1)
                continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
    vector<int> res(N);
    cout << "Yes" << endl;
    rep(i, 1, N) {
        for(int t : G[i]) {
            if(dist[t] == dist[i] - 1) {
                res[i] = t + 1;
                break;
            }
        }
    }
    rep(i, 1, N) { cout << res[i] << endl; }
}


Measured memory_bytes: 10568
#include<stdio.h>
#include<math.h>
int array[100];
int counter(long long int a,long long int b);
int main()
{
    long long int a,b;
    int count;
    while(scanf("%lld %lld",&a,&b)==2)
    {
        count=counter(a,b);
        printf("%d\n",count);
    }
    return(0);
}
int counter(long long int a,long long int b)
{
    long long int number;
    int x,count=0;
    number=a+b;
    if(number==0)
    {
        count=1;
        return(count);
    }
    else
    {

        while(number!=0)
        {
            count++;
            number=number/10;
        }
        return(count);
    }
}

Measured memory_bytes: 1028
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		sc.close();
		System.out.println(func(A - 1) ^ func(B));
	}
	static long func(long n) {
		if(n < 0) return 0;
		if(n % 4 == 0) {
			return n;
		}else if(n % 4 == 1) {
			return 1;
		}else if(n % 4 == 2) {
			return 1 ^ n;
		}else {
			return 0;
		}
	}
}

Measured memory_bytes: 22864
using System;

namespace AtCoderABC133C
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = int.MaxValue;

            string[] s = Console.ReadLine().Split(' ');

            int L = int.Parse(s[0]);
            int R = int.Parse(s[1]);

            if (R - L > 674)
                ans = 0;
            else
            {
                for(int i=L;i<R;i++)
                {
                    for(int j=i+1;j<=R;j++)
                    {
                        int buffer = ((i % 2019) * (j % 2019)) % 2019;

                        if (ans > buffer)
                            ans = buffer;
                    }

                }
            }

            Console.WriteLine(ans.ToString());
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<set<string>> ret(11);
    ret[0].insert("a");
    for (int i = 1; i < n; ++i) {
        vector<set<string>> temp(11);
        for (int j = 0; j < 10; ++j) {
            for (auto &s : ret[j]) {
                for (int k = 0; k <= j; ++k) {
                    temp[j].insert(s + string(1, 'a' + k));
                }
                temp[j + 1].insert(s + string(1, 'a' + j + 1));
            }
        }
        swap(ret, temp);
        for (auto &r : temp) {
            r.clear();
        }
    }
    vector<string> ans;
    for (int i = 0; i < 10; ++i) {
        for (auto &r : ret[i]) {
            ans.push_back(r);
        }
    }
    sort(ans.begin(), ans.end());
    for (auto &a : ans) {
        cout << a << "\n";
    }
    return 0;
}

Measured memory_bytes: 15232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<typename T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }
int sum(VI a) { int ret = 0; for (int i : a)ret += i; return ret; }
struct p { int from, to, num; };

int main() {
    init();

    int n;
    cin >> n;
    vector<p> edge(n - 1);
    int a, b;
    FOR(i, 0, n - 1) {
        cin >> a >> b;
        edge[i] = { --a,--b,i };
    }
    VI c(n);
    cin >> c;

    rSORT(c, greater<int>());
    int point = 0;
    vector<bool> ever(n, false);
    VI ans(n, 0);
    ans[0] = c[0]; ever[0] = true;
    FOR(i, 1, n)FOR(j, 0, n - 1) {
        if (ever[edge[j].from] != ever[edge[j].to]) {
            ever[edge[j].from] = true;
            ever[edge[j].to] = true;
            chmax(ans[edge[j].from], c[i]);
            chmax(ans[edge[j].to], c[i]);
            point += c[i];
            break;
        }
    }
    cout << point << "\n";
    FOR(i, 0, n)cout << ans[i] << (i == n - 1 ? "\n" : " ");
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
using namespace std;
typedef long long int ll;
#define pb push_back

int main(void){
  ll n,i,t,t1,t2;
  vector<ll> res;
  priority_queue<ll,vector<ll> ,greater<ll> > a;
  priority_queue<ll> c;
  deque<ll> b1,b2;
  t1=t2=0;
  cin>>n;
  res.resize(n+1);
  for(i=0;i<n;i++){
    cin>>t;
    a.push(t);
    t1+=t;
    res[i]=0;
  }
  for(i=0;i<n;i++){
    cin>>t;
    b1.pb(t);
    b2.pb(t);
  }
  for(i=0;i<n;i++){
    cin>>t;
    c.push(t);
    t2+=t;
  }
  res[n]=0;
  res[0]+=t1;
  res[n]-=t2;
  for(i=1;i<=n;i++){
    t1+=b1.front();
    a.push(b1.front());
    b1.pop_front();
    t1-=a.top();
    a.pop();
    res[i]+=t1;
    
    t2+=b2.back();
    c.push(b2.back());
    b2.pop_back();
    t2-=c.top();
    c.pop();
    res[n-i]-=t2;
  }
  t=res[0];
  for(i=1;i<=n;i++){
    if(res[i]>t) t=res[i];
  }
  cout<<t<<endl;
  /*
  for(i=0;i<n;i++) {cout<<a.top()<<endl;a.pop();}
  cout<<endl;
  for(i=0;i<n;i++) cout<<b[i]<<endl;
  cout<<endl;
  for(i=0;i<n;i++) {cout<<c.top()<<endl;c.pop();}
  cout<<endl;
  */
  return 0;
}


Measured memory_bytes: 4984
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
edge = []
edge_inv = [[] for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    edge.append((a, b, -c))
    edge_inv[b].append(a)

visited = [False] * n
def dfs(v):
    for u in edge_inv[v]:
        if not visited[u]:
            visited[u] = True
            dfs(u)

visited[n-1] = True
dfs(n-1)
target_nodes = [i for i in range(n) if visited[i]]
# print(target_nodes)

def bellman_ford(n, edge):
    INF = float('inf')
    d = [INF] * n
    d[0] = 0
    for i in range(n):
        update = False
        for v_from, v_to, cost in edge:
            if v_from not in target_nodes or v_to not in target_nodes:
                continue
            if d[v_from] != INF and d[v_to] > d[v_from] + cost:
                d[v_to] = d[v_from] + cost # 緩和
                update = True
    return d, update

d, update = bellman_ford(n, edge)
if update:
    print("inf")
else:
    print(-d[n-1])


Measured memory_bytes: 42480
N = int(input())
A = [""] * N
B = [0] * N
for i in range(N):
    s, t = input().split()
    A[i] = s
    B[i] = int(t)
X = input()
c = 0
for i in range(N):
    c += B[i]
    if A[i] == X:
        print(sum(B) - c)
        exit()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll = long long;
template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
#define F first
#define S second

signed solve(){
  ll t;
  cin>>t;
  ll ans=t;
  for(ll i=1;;i++){
    ll res=1,cnt=i+i;
    for(ll j=0,k=1;j<i;j++){
      k*=3;
      //res+=k*2;
      res+=k;
      if(j+1<i) res+=k;
      if(k>t) break;
    }
    if(res>t) break;
    ll tmp=t-res;
    ll num=i;
    while(tmp&&num){
      cnt+=tmp%3;
      tmp/=3;
      num--;
    }
    cnt+=tmp;
    //cout<<i<<":"<<t-res<<" "<<cnt<<endl;
    chmin(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  solve();
  return 0;
}



Measured memory_bytes: 3172
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
using namespace std;

using int64 = long long;
using int128 = __int128;

#define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++)

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

  int N;
  int64 K;
  cin >> N >> K;

  vector<int64> A(N);
  repeat (i, N) {
    cin >> A[i];
  }

  int64 ans = 0;
  repeat (i, N) ans += A[i] ^ K;

  int64 mask = (1LL << 41) - 1,
        sum = 0;
  for (int i = 0; i <= 40; i++) {
    if ((K >> i) & 1) {
      int64 value = sum;
      repeat (j, N) {
        value += (K & (mask ^ (1LL << i))) ^ (A[j] & mask);
      }
      ans = max(ans, value);
    }

    int cnt = 0;
    repeat (j, N) if ((A[j] >> i) & 1) cnt++;

    sum += (1LL << i) * max(cnt, N - cnt);
    mask -= (1LL << i);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1024
main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine :: IO [Int]
  ds <- map ('R' ==) . takeWhile (`elem` "LR") <$> getContents :: IO [Bool]
  let
    s = length . filter id . (zipWith (==) <$> id <*> tail) $ ds :: Int
  print $ (s + 2 * k) `min` (n - 1)


Measured memory_bytes: 4928
#include <bits/stdc++.h>
#define fr first
#define pb push_back
#define skip continue
#define se second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define vi vector<ll>
#define MAX 1e9 + 1234

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

int const INF = 1e5 + 9 ;
const int N = 100100;

void faster(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int simple( int n ) {
    int i, sq;
    if ( n%2 == 0 ) { return 0; }
    sq= (int)sqrt( n );
    for ( i= 3; i<=sq; i++ ) {
    if ( (n%i) == 0 ) { return 0; }
    }
    return 1;
}
ll gcd(ll a, ll b){
    if(a > b)	swap(a, b);
    if(!a)	return b;
    return gcd(b % a, a);
}



void solve() {
    ll a , b;
    cin >> a >> b;

    if(a < b) {
    for(int i = 0; i < b; i++) {
        cout << a;
    }
  }
  else{
    for(int i = 0; i < a; i++) {
      cout << b;
    }
  }
}

int main(){
    faster();
    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
}


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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

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

    int ans = 1;
    FORE(i, 1, sqrt(m)) {
        if (m % i == 0) {
            if (m / i >= n) {
                ans = max(i, ans);
            }
            if (i >= n) {
                ans = max(m / i, ans);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define neko 100010
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~(i)))
#define rf(i,a,b) for(register int i=(a);i>=(b);i=~(-(i)))
int a[neko],ans,n;
bool cmp(int a,int b){return a>b;}
int main()
{
	scanf("%d",&n);
	f(i,1,n)scanf("%d",&a[i]);
	std::sort(a+1,a+n+1,cmp);
	f(i,0,n)
	{
		if(i+1>a[i+1])
		{
			f(j,i+1,n)if(a[j]==i)++ans;
			if(ans&1)return printf("First\n"),0;
			return printf("%s",(a[i]-i)&1?"First":"Second"),0;
		}
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> l(n);
  for(Int i=0;i<n;i++) cin>>l[i];
  sort(l.begin(),l.end());
  Int s=0;
  for(Int i=0;i+1<n;i++) s+=l[i];
  cout<<(s>l.back()?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

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

		String str = sc.next();

		if(str.equals("ABC")) {
			System.out.println("ARC");
		}
		else {
			System.out.println("ABC");
		}


	}

}

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

typedef struct{
    double x;
    double y;
}dot;

void kock(int, dot, dot);

void kock(int n, dot p1, dot p2){

    dot s, t, u;

    if(n==0) return;

    s.x=(2*p1.x+1*p2.x)/3;
    s.y=(2*p1.y+1*p2.y)/3;
    t.x=(1*p1.x+2*p2.x)/3;
    t.y=(1*p1.y+2*p2.y)/3;
    u.x=(t.x-s.x)*cos(M_PI/3)-(t.y-s.y)*sin(M_PI/3)+s.x;
    u.y=(t.x-s.x)*sin(M_PI/3)+(t.y-s.y)*cos(M_PI/3)+s.y;

    kock(n-1, p1, s);
    printf("%.8f %.8f\n", s.x, s.y);
    kock(n-1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    kock(n-1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    kock(n-1, t, p2);
    return;
}

int main(void){

    int n;
    dot start={0,0}, end={100, 0};

    scanf("%d", &n);

    printf("%.8f %.8f\n", start.x, start.y);
    kock(n, start, end);
    printf("%.8f %.8f\n", end.x, end.y);


    return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin>>n;
	long long res = n;
	for(int i = 1; i <= sqrt(n); ++i){
		long long x = n / i;
		if(n % i == 0){
			if((i - 1) + (x - 1) < res)res = (i - 1) + (x - 1);
		}
	}
	cout<<res<<endl;	
	return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input!{
        source = src,
        d: u32,
        n: usize,
    }

    let x: usize = 100;
    if n < 100 {
        return format!("{}", n * x.pow(d));
    } else {
        return format!("{}", (n + 1)* x.pow(d));
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

const ll mod = 1e9+7;
const int NMAX = 1e5+1;

int main(){

    ll n, m; cin >> n >> m;

    if(n < m){
        swap(n, m);
    }

    ll fact[NMAX];
    fact[1] = 1;
    for(int i=2; i<NMAX; i++){
        fact[i] = (fact[i-1]*i)%mod;
    }

    if(n >= m + 2){
        cout << 0;
    }
    else{
        ll ans = (fact[n] * fact[m]) % mod;

        cout << ( n != m ? ans : (2*ans)%mod);
    }

    return 0;
}

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

using namespace std;
int main() {
    long long N, M, K;
    cin >> N >> M >> K;
    vector<long long> A(N + 1);
    vector<long long> B(M + 1);
    A[0] = 0;
    B[0] = 0;
    long long prev = 0;
    for (long long i = 1; i <= N; ++i) {
        long long t;
        cin >> t;
        A[i] = t + A[i - 1];
    }
    for (long long i = 1; i <= M; ++i) {
        long long t;
        cin >> t;
        B[i] = t + B[i - 1];
    }
    long long cnt = 0;
    long long j = M;
    for (long long i = 0; i <= N; ++i) {
        if (A[i] > K) { break; }
        while (j >= 0 && A[i] + B[j] > K) {
            j--;
        }
        cnt = max(cnt, i + j);

    }
    cout << cnt << endl;

    return 0;
}


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

const int MAX_D = 14;
int p[MAX_D];
int c[MAX_D];
int D, G;

int accept_number(int state) {
    int res = 0, score = 0;
    for(int i = 0; i < D; ++i) {
        if(state&(1<<i)) res += p[i], score += 100*(i+1)*p[i] + c[i];
    }
    for(int i = D-1; i >= 0; --i) {
        if(score >= G) break;
        if(state&(1<<i)) continue;
        int cur = 100*(i+1);
        int num = min((G - score + cur - 1)/cur, p[i]-1);
        res += num, score += 100*(i+1)*num;
    }
    // もしスコアがGに達しなかったら、INFを返す
    return (score < G) ? 1000000000 : res;
}

int main()
{
    scanf("%d %d", &D, &G);
    for(int i = 0; i < D; ++i) scanf("%d %d", &p[i], &c[i]);
    
    int res = 10000000;
    for(int i = 0; i < (1<<D); ++i) {
        res = min(res, accept_number(i));
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int R;
    cin>>R;
    if(R<1200){
        cout<<"ABC"<<endl;
    }
    else  if(R<2800){
        cout<<"ARC"<<endl;
    }
    else{
        cout<<"AGC"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
MOD = 998244353

f_list = [1] * 300000
f_r_list = [1] * 300000

for i in range(299999):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

def power(n, x):
	if x == 1:
		return n
	elif x % 2 == 0:
		return power(int((n * n) % MOD), int(x / 2))
	else:
		return int((n * power(n, x - 1)) % MOD)

f_r_list[-1] = power(f_list[-1], MOD - 2)

for i in range(2, 300001):
	f_r_list[-i] = int((f_r_list[-i + 1] * (300002 - i)) % MOD)

def comb(n, r):
	if n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 


n, a, b, k = map(int, input().split())
a, b = min(a, b), max(a, b)

cmb = []

for i in range(n+1):
	if (k - b * i) % a == 0 and k >= b * i and (k - b * i) // a <= n:
		cmb.append(((k - b * i) // a, i))

if cmb == []:
	print(0)
else:

	ans = 0

	for c in cmb:
		ans = int((ans + (comb(n, c[0]) * comb(n, c[1])) % MOD) % MOD)

	print(ans)

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

int main(void) {
    int N;
    int t,x,y;
    int lt,lx,ly;
    int need;
    bool check = true;
    
    cin >> N;
    lt = lx = ly = 0;
    for(int i=0;i<N;i++) {
        cin >> t >> x >> y;
        need = abs(x-lx) + abs(y-ly);
        if((t-lt) < need) check = false;
        if((t-lt-need)%2) check = false;
        lt = t;
        lx = x;
        ly = y;
    }

    if(check) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    int l; cin >> l;
    vector<vector<int>> next(n, vector<int>(20, -1));
    for (int i = 0; i < n-1; i++) {
        int left = i; int right = n;
        while (right - left > 1) {
            int mid = (left + right) / 2;
            if (x[mid] - x[i] > l) right = mid;
            else left = mid;
        }
        next[i][0] = left;
    }
    for (int c = 0; c < 19; c++) {
        for (int i = 0; i < n; i++) {
            if (next[i][c] == -1) continue;
            next[i][c+1] = next[next[i][c]][c];
        }
    }
    int q; cin >> q;
    while (q--) {
        int a, b; cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);
        int left = 0; int right = n;
        while (right - left > 1) {
            int mid = (left + right) / 2;
            int curr = a;
            for (int i = 0; i < 20; i++) {
                if (mid & (1 << i)) {
                    curr = next[curr][i];
                }
                if (curr == -1) break;
            }
            if (curr == -1 || curr >= b) right = mid;
            else left = mid;
        }
        cout << right << endl;
    }
    return 0;
}

Measured memory_bytes: 14464
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

int a[500][500] , sl[500] , cnt[500];
bool vis[500];

int main()
{
	int n , m;
	scanf("%d %d",&n , &m);
	for(int i = 1 ; i <= n ; i++){
		for(int j = 1 ; j <= m ; j++) scanf("%d",&a[i][j]);
	}
	int Max = 1000;
	memset(vis , 0 , sizeof(vis));
	for(int i = 1 ; i <= n ; i++) sl[i] = 1;
	for(int j = 1 ; j <= m ; j++){
		for(int i = 1 ; i <= n ; i++){
			int tl = sl[i];
			while(vis[a[i][sl[i]]]){
				sl[i]++;//当前指针		
			}
			if(j == 1) {cnt[a[i][sl[i]]]++;continue;}
			else if(vis[a[i][tl]] == 0) {continue;}
			else cnt[a[i][sl[i]]]++;
		}
		int ml = 0 , mcnt = 0;
		for(int i = 1 ; i <= m ; i++){
			if(ml < cnt[i] && !vis[i]){
				ml = cnt[i];
				mcnt = i;
			}
		}
		if(ml < Max) Max = ml;
		vis[mcnt] = 1;
	}
	printf("%d\n", Max);
	return 0;
}

Measured memory_bytes: 768
P = Struct.new(:x,:y) do; 
  def d(o)
    (o.x - x).abs + (o.y - y).abs
  end
end
n,m = gets.split.map(&:to_i)
S = n.times.map{P.new(*gets.split.map(&:to_i)) }
M = m.times.map{P.new(*gets.split.map(&:to_i)) }
puts S.map{|s| (1..m).min_by{|i| M[i - 1].d(s) }}



Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 5002;
int a[N], b[N], n, r[N], l[N], c[N], s[N];
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s1, s2;
    cin >> s1;
    cin >> s2;
    n = s1.length();
    int f1 = 0, f2 = 0;
    for (int i = 0; i < n; i++){
        a[i] = s1[i] - '0';
        b[i] = s2[i] - '0';
        f1 += a[i];
        f2 += b[i];
    }
    if (f2 == 0){
        if (f1 == 0) cout << 0; else cout << -1;
        return 0;
    }
    for (int i = 0; i < n; i++){
        int p = i;
        int x = 0;
        while(b[p] == 0 && x <= n){
            p = (p + 1) % n;
            x++;
        }
        r[i] = x;
        p = i;
        x = 0;
        while(b[p] == 0 && x <= n){
            p = (p - 1 + n) % n;
            x++;
        }
        l[i] = x;
    }
    int ans = 100000;
    for (int i = 0; i < n; i++){
        int x = 0;
        vector < pair < int, int > > t;
        for (int j = 0; j < n; j++){
            if (a[(j + i) % n] != b[j]){
                x++;
                t.pb({l[j], r[j]});
            }
        }
        sort(t.begin(), t.end());
        memset(s, 0, sizeof(s));
        for (int j = (int)t.size() - 1; j >= 0; j--){
            s[j] = max(s[j + 1], t[j].S);
        }
        t.pb({0, s[0]});
        for (int j = 0; j < t.size(); j++){
            int L = t[j].F;
            int R = s[j + 1];
            if (j == t.size() - 1){
                L = 0;
                R = s[0];
            }
            int d = (R + L) * 2;
            int k = (n - i) % n;
            if (k <= L){
                ans = min(ans, d - k + x);
            } else
                ans = min(ans, k + R + R + x);
            if (i <= R){
                ans = min(ans, d - i + x);
            } else
                ans = min(ans, L + L + i + x);
        }
    }
    cout << ans;
}


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


int main() {
   int a;
  cin >> a;
  if(a % 2 == 0){
    cout << 0.5;
  }
  else{
    double b, c;
    b = (a + 1) / 2;
    c = b / a;
    cout << fixed << setprecision(7);
    cout << c;
  }
  
  return 0;
}

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

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> L(n);
	for (auto& a : L) cin >> a;
	sort(L.begin(), L.end());
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			int l = L[j] - L[i], r = L[j] + L[i];
			auto lit = upper_bound(L.begin(), L.end(), l);
			auto rit = lower_bound(L.begin(), L.end(), r);
			ans += distance(lit, rit);
			if (l < L[i] && L[i] < r) ans--;
			if (l < L[j] && L[j] < r) ans--;
		}
	}
	cout << ans / 3 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = (l); i <= (r); i++)
#define LOG(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;

double sqr (double x) {
	return x * x; 
}
int nd[15], n;
double x[15], y[15];
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> x[i] >> y[i], nd[i] = i;
	
	int r = 1;
	for (int i = 2; i <= n; i++) r *= i;
	double cr = r; 
	double ans = 0;
	while (r--) {
		next_permutation(nd + 1, nd + n + 1);
		double dis = 0; 
		for (int i = 2; i <= n; i++) dis += sqrt(sqr(x[nd[i]] - x[nd[i - 1]]) + sqr(y[nd[i]] - y[nd[i - 1]]));
		
		ans += dis;
	}
	cout << fixed << setprecision(10) << ans / cr << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
    int N;
    std::cin >> N;
    for (int b = 0; b < (1 << N); ++b) {
        std::cout << b << ":";
        for (int i = 0; i < N; ++i) {
            if ((b >> i) & 1) std::cout << " " << i;
        }
        std::cout << std::endl;
    }
}


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


const int MAX_V = 10000;
const int MAX_E = 100000;
int finde[MAX_V];

struct Edge {
	int first;
	int second;
	int weight;
};
vector<Edge> e;

bool operator < (const Edge& a, const Edge& b) {
	return a.weight < b.weight;
}

bool Judge(int m, int n) {
	while (finde[m] != m) m = finde[m];
	while (finde[n] != n) n = finde[n];
	if (m == n) {
		return false;
	}
	 finde[n]= m;
	return true;
}

int min_span_tree(int n, int m) {

	for (int i = 0; i < m; i++) finde[i] = i;
	int count = 0;
	int ret = 0;
	int f, s;
	for (int i = 0;count<m-1; i++) {
		f = e[i].first;
		s = e[i].second;
		if (Judge(f,s)) {		
			ret += e[i].weight;
			count++;
		}
	}
	return ret;
}
int main() {
	int n, m;
	cin >> m >> n;
	for (int i = 0; i < n; i++) {
		int s, t, w;
		cin>>s>>t>>w;
		e.push_back(Edge{ s, t, w });
	}
	sort(e.begin(), e.end());
	int ret = min_span_tree(n, m);
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 4584
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

// conversion
inline int
toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

//change
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//math
template <class T>
inline T sqr(T x) { return x * x; }

template <class T>
inline T nCr(T n, T r)
{
    T num = 1;
    for (int i = 1; i <= r; ++i)
    {
        num *= (n - i + 1) / i;
    }
    return num;
}
template <class T>
inline T nPr(T n, T r)
{
    r = n - r;
    T sum = 1;
    int i;
    for (i = n; i >= r + 1; --i)
        sum *= i;
    return sum;
}

template <class T>
inline T facctorial(T k)
{
    T sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

//numeric
template <class T>
inline T gcd(T a, T b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

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

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

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

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

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main()
{
    int a;
    cin >> a;
    string s;
    cin >> s;
    if (a < 3200)
    {
        s = "red";
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n<4)
    {
        cout<<"No\n";
        return 0;
    }

    rep(i,26)
    {
        rep(j,15)
        {
            if((4*i+7*j)==n)
            {
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";

    return 0;
}

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

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

moved = {}
now_city = 1
next_city = A[0]
i=0

while i < N:
    moved[now_city] = i
    if next_city in moved:
        break
    now_city = next_city
    next_city = A[now_city-1]
    i += 1

# i 回目の試行で、now_city から next_city に移ろうとしている

mod = i - moved[next_city]

moved_list = [x for x in moved.keys()]

loop_list = moved_list[moved[next_city]:i+1]
loop = len(loop_list)

if K < moved[next_city]:
    print(moved_list[K])
else:
    print(loop_list[(K-moved[next_city])%loop])


# print(f"{next_city=} {i=}")
# print(f"{loop_list=}")
# print(f"{moved_list=}")
# print(f"{K-moved[next_city]=}")
# print(f"{loop=}")

# ans = 5
# 6 10
# 2 3 4 5 4 6


Measured memory_bytes: 38696