akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>

using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using intpv=vector<intpair>;
using llpair=pair<ll,ll>;
using llpv=vector<llpair>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;
using pairmat=vector<llpv>;

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())
#define matin(mat,H,W) for(int i__=0; i__<H; i__++)for(int j__=0; j__<W; j__++) cin>>mat[i__][j__]
#define out(n) cout<<n<<endl

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

template<class T>
inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

template<class T>
inline void init(T& v) {
	for(auto &a__: v) cin>>a__;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a__: v) cin>>a__.first>>a__.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a__: v) cin>>a__;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a__: v) cin>>a__.first>>a__.second;
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll GCD(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}

ll Fact(ll x, ll p) { //階乗
	ll f=1;
	for(ll i=2; i<=x; i++) {
		f*=i;
		f%=p;
	}
	return f;
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll div=1LL;
	while(n/div) {
		digit++;
		div*=10;
	}
	return digit;
}


int N,K;
intvec A;
int res;

void input() {
	cin>>N>>K;
	init(A,N);
}

void solve() {
	sort(all(A));
	for(int i=0; i<K; i++) res+=A[i];
	cout<<res<<endl;
}

int main() {
	while(1) {
		input();
		solve();
		break;
	}
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  int n;cin>>n;
  string str;
  int cnt=0;
  REP(i,n){
    cin>>str;
    if(str=="A"){
      cnt++;
    }else{
      cnt--;
      if(cnt<0){
	cout<<"NO"<<endl;
	return 0;
      }
    }
  }
  if(cnt==0)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}

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

using namespace std;
using ll = long long;

vector<vector<pair<int,int>>> tree;
vector<int> col;

void dfs(int u, int p){
    int pcol = -1;
    if(p!=-1) pcol = col[p];
    //cout<<u<<" "<<col[p]<<endl;
    int cnt = 1;
    for(auto &x: tree[u]){
        if(cnt == pcol) cnt++;
        if(x.second == p) continue;
        col[x.second] = cnt;
        dfs(x.first, x.second);
        cnt++;
    }
}

int main(){
    int n;
    cin>>n;
    tree = vector<vector<pair<int,int>>>(n, vector<pair<int,int>>(0));
    col.resize(n-1);
    for(int i=0; i<-1+n; i++){
        int a,b;
        cin>>a>>b;
        a--, b--;
        tree[a].push_back({b,i});
        tree[b].push_back({a,i});
    }
    dfs(0,-1);
    set<int> s;
    for(auto x:col) s.insert(x);
    cout<<s.size()<<endl;
    for(auto x:col) cout<<x<<endl;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if(A > 12) {
    cout << B << endl;
  }
  else if (A >= 6) {
    cout << B / 2 << endl;
  }
  else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 3568
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var S = Read();
            var center = S.Length / 2;
            var ans = 0;
            for (int i = 0; i < center; i++)
            {
                if (S[i] != S[S.Length - 1 - i])
                    ans++;
            }

            Println(ans);
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



Measured memory_bytes: 13140
main = do
  ln <- getLine
  let n = read ln :: Int
  putStrLn . concat $
    [" " ++ show x | x <- [1..n], check x]
check :: Int -> Bool
check x
  | x `mod` 3 == 0 = True
  | check2 x = True
  | otherwise = False
check2 :: Int -> Bool
check2 x = do
  if x == 0
    then False
    else
      if x `mod` 10 == 3
        then True
        else check2 (x `div` 10)

Measured memory_bytes: 4088
#include <stdio.h>
int k, n, ans;
int a[200000];
int main() {
	scanf("%d%d", &k, &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	ans = a[n - 1] - a[0];
	for (int i = 1; i < n; i++) {
		if (ans > k - (a[i] - a[i - 1]))ans = k - (a[i] - a[i - 1]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 896
from collections import Counter


LEN = 10 ** 6
is_avl = [0] * (LEN + 1)
N = int(input())
A = Counter(map(int, input().split()))
for a in A:
    is_avl[a] = 1
for a in A:
    for i in range(2 * a, LEN + 1, a):
        is_avl[i] = 0
ans = 0
for a in A:
    if is_avl[a] == 1 and A[a] == 1:
        ans += 1
print(ans)


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;


int main(){
  int k,x;
  cin >> k >> x;
  if((500*k)>=x)cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main() {
 int N, K = 0;
 int num = 0;

 cin >> N >> K;

 int hight[N] = {};
 for (int i = 0; i < N; i++) {
	cin >> hight[i];
	if(hight[i] >= K) {
		num++;
	}
 }

 cout << num << endl;
 
}

Measured memory_bytes: 640
mod = 10**9+7

# コンビネーション
def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NN = 10**6 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

X, Y = map(int, input().split())
if (X+Y)%3 != 0:
    print(0)
else:
    a = (X+Y)//3
    ans = cmb(a, X-a)
    print(ans) 

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n;
    cin>> n;

    int sum=0 , l[n];

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

    
    cout << (sum > (2* *max_element(l, l+n)) ? "Yes\n" : "No\n");

    return 0;
}




Measured memory_bytes: 3580
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<unistd.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;
using namespace __gnu_pbds;
 
// replace ll  with pair if multiset needed
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set secik;
 
const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

ll pot(ll a, ll wyk){
	if(wyk == 0) return 1;
	if(wyk % 2) return (a * pot(a,wyk-1)) % MOD;
	ll xd = pot(a,wyk/2);
	return (xd * xd) % MOD;
}

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

	ll n; cin >> n;
	ll wyn = pot(10,n);
	wyn = (wyn - 2 * pot(9,n)) % MOD;	
	wyn = (wyn + pot(8,n)) % MOD;
	
	if(wyn < 0) wyn += MOD;
	
	cout << wyn << "\n";















	
	return 0;
 
}

Measured memory_bytes: 3652
//Author : Prakhar Asaiya
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define REPN(i,a,b) for(ll i = a; i <= b; ++i)
#define REPV(i,a,b) for(ll i = a; i >= b; --i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define with_tests int t; cin>>t; while(t--){ solve(); }
#define without_tests solve();
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 100000000
#define ff first
#define ss second
const int M=1e9+7;
const int N = 200005;
vector<int> adj[N]; 
bool vis[N];

int dfs(int s)
{
	int ans = 1;
	vis[s] = true;
	for(auto i : adj[s])
	{
		if(!vis[i])
		{
			ans += dfs(i);
		}
	}
	return ans;
}

void solve()
{
	int n, m, a, b;
	cin>>n>>m;
	REP(i,0,m)
	{
		cin>>a>>b;
		--a, --b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int cnt = 0;
	vector<int> v;
	REP(i,0,n)
	{
		if(!vis[i])
		{
			int res = dfs(i);
			v.push_back(res);
			++cnt;
		}
	}
	int ans = 0;
	//int mN = *min_element(all(v));
	sort(all(v));
	int mN = v[0];
	ans += mN;
	REP(i,1,cnt)
	{
		ans += (v[i] - mN);
		mN = v[i];
	}
	cout<<ans<<"\n";
}
 
int main()
{/*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#*/
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  //with_tests;
  without_tests;
  return 0;
}

Measured memory_bytes: 24012
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

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

test! {
r#"2 2
.*
*."# => r#".*
.*
*.
*."#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        h: usize, _w: i64,
        c: [String; h],
    }
    let mut ans = "".to_string();

    for i in 0..h {
        for j in 0..2 {
            ans.push_str(&c[i]);
            if i == h - 1 && j == 1 {
                continue;
            }
            ans.push_str("\n");
        }
    }

    ans.to_string()
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>
#include <set>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
int main() {
	int n, s1[1145], s2[1145], l1[1145] = {}, l2[1145] = {},ans = 0;
	cin >> n;
	REPO(i, n)cin >> s1[i];
	REPO(i, n)l1[i] = l1[i - 1] + s1[i];
	REPO(i, n)cin >> s2[i];
	REPO(i, n)l2[i] = l2[i - 1] + s2[i];
	REPO(i, n) ans = max(ans, l1[i] + l2[n] - l2[i - 1]);
	cout << ans << endl;

}



Measured memory_bytes: 256
#frog
H=10**10
n=int(input())
h=list(map(int,input().split()))+[H]*10
dp=[0]*(n+10)
for i in range(1,n+1):
    dp[i]=min([dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])])
print(dp[n-1])

Measured memory_bytes: 13924
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        h: usize,
        w: usize,
        n: usize,
        a: [usize; n],
    }

    let v: Vec<_> = a
        .iter()
        .zip(1..)
        .flat_map(|(&c, i)| std::iter::repeat(i).take(c))
        .collect();

    let v: Vec<Vec<_>> = v
        .chunks(w)
        .zip([0, 1].iter().cycle())
        .map(|(x, &i)| {
            if i == 0 {
                x.iter().collect::<Vec<_>>()
            } else {
                x.iter().rev().collect::<Vec<_>>()
            }
        }).collect();

    v.iter()
        .map(|l| {
            println!(
                "{}",
                l.iter()
                    .map(|&x| x.to_string())
                    .collect::<Vec<_>>()
                    .join(" ")
            )
        }).count();
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define ull 		unsigned long long
#define ll 			long long
#define M 			1000000007
#define pb 			emplace_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)		__builtin_popcountll(a)
#define hell 		(ull)1e9
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
int d,n,dp[10001][2][2][101];
vi l,r;
int solve(int pos,int f1,int f2,int rem)
{
	if(pos==n)
	{
		if(rem==0)
			return 1;
		return 0;
	}
	int &ans=dp[pos][f1][f2][rem];
	if(ans!=-1)
		return ans;
	ans=0;
	int ulmt=9,llmt=0;
	if(f1==0)
		ulmt=r[pos];
	if(f2==0)
		llmt=l[pos];
	rep(dgt,llmt,ulmt+1)
	{
		int nf1=f1,nf2=f2;
		if(dgt>llmt)
			nf2=1;
		if(dgt<ulmt)
			nf1=1;
		int nrem=(rem+dgt)%d;
		ans=(ans+solve(pos+1,nf1,nf2,nrem))%M;
	}
	return ans;
}
signed main(void)
{ios
	string k; 
	cin>>k>>d;
	for(char i:k)
		r.pb(i-'0');
	l.pb(1);
	rep(i,0,sz(r)-1)
	{
		l.pb(0);
	}
	reverse(all(l));
	n=sz(r);
	memset(dp,-1,sizeof(dp));
	cout<<solve(0,0,0,0)<<endl;
}

Measured memory_bytes: 33152
#include<stdio.h>
#define N 200000
int main(){
  int i,j,a,min,max,R[N];
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&R[i]);
  } 
  max=R[1]-R[0];
  min=R[0];
 
  for(j=1;j<a;j++){
   max=(max>R[j]-min)?max:R[j]-min; 
   min=(min<R[j])?min:R[j];
  }
  printf("%d\n",max);
  return 0;
}

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

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

const long long MAX = 100100;  // 最大を決めておく
long long fac[MAX], finv[MAX], inv[MAX];
 
void nPr_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
 
 // nPrを計算する (前処理は忘れないように)
long long nPr(int n, int r) {
    if (n < 0 || r < 0 || n < r) return 0;
    return fac[n] * finv[n - r] % mod;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];
    
    ll ans = 0;
    nPr_init();
    ll cnt = nPr(n-1,n-2);
    rep(i,n-1) {
        if (i > 0) {
            cnt += (nPr(i,i) * (nPr(n-1,n-i-2)));
            cnt %= mod;
        }
        ans += (cnt * (x[i+1]-x[i]));
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <map> 
#include <iostream>
#include <cctype>
#include <utility> // 包含pair 
using namespace std;
typedef long long LL;
#define rep(i, j, k) for (int i = (int) (j); i <= (int)(k); i++)
map<string, int> solve;
const int mov[] = {1, -1, 4, -4}; // 在一行中模拟两行的上下移动效果 
// 但要注意这种一维的越界判断还要注意在换行的时候，如0123 4567这里的3和4并非adjacent，需要特判 

void bfs() {
	queue<string> que;
	que.push("01234567");
	solve["01234567"] = 0;
	while (!que.empty()) {
		string u = que.front(); que.pop();
		int p = 0; // 之后查找'0'在字符串中的位置
		for (int i = 0; i < 8; i++) {
			if (u[i] == '0') {
				p = i;
				break;
			}
		} 
		// 开始递推 
		for (int i = 0; i < 4; i++) {
			int loc = p + mov[i];
			if (loc >= 0 && loc < 8 && !(p == 3 && i == 0) && !(p == 4 && i == 1)) {
				string Next = u;
				swap(Next[loc], Next[p]); // 交换0与它相邻位置的数字（如果位置合法）
				if (solve.find(Next) == solve.end()) { // 如果交换后还未被递推过 
					solve[Next] = solve[u] + 1;
					que.push(Next);
				} 
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	bfs();
	string line;
	while (getline(cin, line)) {
		line.erase(remove(line.begin(), line.end(), ' '), line.end()); // 删除字符串一行中的所有空格字符 
		cout << solve[line] << endl;
	}
    return 0;
}


Measured memory_bytes: 5296
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,n,m,tes,t,i,j,zx,xc,z[59],zi,pas;
pair <pair <int, int>, pair <int, int> > p[59];
void rec(int q, int w){
	if(q>n){
		c=0;d=0;
		for(int h=1; h<=tes; h++){
			if(z[p[h].first.second]-z[p[h].first.first]==p[h].second.first){
				c+=p[h].second.second;
			}
		}
		if(pas<c) pas=c;
		return;
	}
	for(int h=w; h<=m; h++){
		zi++;
		z[zi]=h;
		rec(q+1,h);
		zi--;
	}
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>m>>tes;
	for(t=1; t<=tes; t++){
		cin>>p[t].first.first>>p[t].first.second>>p[t].second.first>>p[t].second.second;
	}
	rec(1,1);
	cout<<pas;
	return 0;
}

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

int main(){
    int64_t H, W;
    cin >> H >> W;
    if(H > W) swap(H, W);
    if(H == 1){
        cout << 1 << endl;
        return 0;
    }
    int64_t ans = (H*W+1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
//const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L //setprecision(15)

int main() {
	int N; cin >> N;
	string s, t; cin >> s >> t;
	string tmp;
	int ans = INF;
	for (int i = 0; i <= t.length(); i++) {
		tmp = s;
		tmp = s + t.substr(t.length()-i);
		if (tmp.substr(0,N) == s &&
		    tmp.substr(i,N) == t) ans = min(ans, (int)tmp.length());
	}
	cout << ans << endl;
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

int H, N;
vi fie;
vvi dp;

int dfs(int h, int state) {
  if(h == H) return 0;
  if(dp[h][state] != -1) return dp[h][state];

  int ans = dfs(h + 1, fie[h]);

  rep(i, 0, 3) {
    if((state >> i) & 3) continue;
    if((fie[h] >> i) & 3) continue;
    ans = max(ans, dfs(h + 1, fie[h] | (3 << i)) + 1);
  }

  if(state == 0 && fie[h] == 0) {
    ans = max(ans, dfs(h + 1, (1 << 4) - 1) + 2);
  }

  return dp[h][state] = ans;
}

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

  cin >> H >> N;
  fie.resize(H);
  dp.resize(H, vi((1 << 4), -1));
  rep(i, 0, N) {
    int x, y;
    cin >> x >> y;
    fie[y] |= (1 << x);
  }

  cout << dfs(1, fie[0]) << endl;
}



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

int main() {
	int n, T,i;
	cin >> n >> T;
	vector<int> c(n), t(n);
	int ans = 114514;

	for (i = 0;i < n;i++) {
		cin >> c[i] >> t[i];
		if (t[i] <= T && c[i] < ans)ans = c[i];
	}
	if (ans == 114514)cout << "TLE" << endl;
	else cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    printf("%.10f\n",sqrt(pow(x1-x2,2)+pow(y1-y2,2)) );
    return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000




int main(){
	
	int N,K;
	cin>>N>>K;
	
	int ans = 0;
	for(int i=0;i<N;i++){
		int h;
		cin>>h;
		if(h>=K)ans++;
	}
	
	cout<<ans<<endl;
		
	
	return 0;
}



Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
        H, W = map(int, input().split())
        maze = [input() for _ in range(H)]
        cnt=0
        for i in maze:
            for j in i:
                if j=='#':
                    cnt+=1
        print('Possible' if cnt==(H-1)+(W-1)+1 else 'Impossible')

resolve()

Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) {
		cout << "No";
		return 0;
	}
	if (a != b && b != c && c != a) {
		cout << "No";
		return 0;
	}
	cout << "Yes";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  long long ans = 1;
  const long long mod = 1e9 + 7;
  for (int i = 1; i <= n; i++) {
	ans = ans * i % mod;
  }
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const char newl = 10;
const string sep = "\n_____\n";
const ll MOD = 1000000007; // 998244353
const int maxN = 300005;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void run(){
   int k;
   cin >> k;
   ll sum = 0;
   for (int a = 1; a <= k; a++)
      for (int b = 1; b <= k; b++)
         for (int c = 1; c <= k; c++) {
            sum += __gcd(__gcd(a,b), c);
         }
   cout << sum;
}
int main(){
   ios_base::sync_with_stdio(0);cin.tie(0);
   cout.tie(0);
   // stress(); return 0;
   int t = 1;
   // cin >> t;
   for (int tc = 1; tc <= t; tc++) {
      // cout << "Case #" << tc << ": ";
      run();
      cout << newl;
   }
   return 0;
}

Measured memory_bytes: 3652
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


n,k = map(int,input().split())

l = map(int,input().split())


l = sorted(l,reverse=True)

ans = 0
for i in range(k):
    ans += l[i]

print(ans)




Measured memory_bytes: 2940
N = int(input())
a = [[0,0,0]]+[list(map(int,input().split())) for n in range(N)]


def check(a1,a2):
    l = abs(a1[1]-a2[1])+abs(a1[2]-a2[2])
    t = abs(a1[0]-a2[0])
    if l <= t and l%2 == t%2:
        return True
    return False

flag = True
for i in range(N):
    r = check(a[i],a[i+1])
    if r==False:
        flag = False
        break

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 28148
use std::collections::HashMap;

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! 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")
    };
}

const MOD: usize = 1_000_000_000 + 7;

fn main() {
    input!{
        n: usize
    }
    let mut table = vec![HashMap::new(); n];
    let result = dfs(&mut table, 0, n, "TTT".to_string());
    println!("{}", result);
}

fn dfs(table: &mut Vec<HashMap<String, usize>>, current: usize, n: usize, last3: String) -> usize {
    if current == n {
        return 1;
    }
    if table[current].contains_key(&last3) {
        return table[current][&last3];
    }
    let mut result = 0;
    for c in "ACGT".chars() {
        let ns = last3.clone() + &(c.to_string());
        if ok(&ns) {
            let last3 = ns.chars().skip(1).collect();
            result = (result + dfs(table, current + 1, n, last3)) % MOD;
        }
    }
    table[current].insert(last3, result);
    result
}

fn ok(last4: &String) -> bool {
    let chars = last4.chars().collect::<Vec<char>>();
    for i in 0..4 {
        let s = if i >= 1 {
            let mut tmp = chars.clone();
            let t = tmp[i];
            tmp[i] = tmp[i - 1];
            tmp[i - 1] = t;
            tmp.into_iter().collect::<String>()
        } else {
            chars.clone().into_iter().collect::<String>()
        };
        if s.contains("AGC") {
            return false;
        }
    }
    true
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(n,m,v) vector<int> v((n),(m));
int ans=INT_MAX;
int n;
vec(8,0,k);
int a[3];
vec(8,0,v);
void init(){
    cin>>n>>a[0]>>a[1]>>a[2];
    
    rep(i,n)cin>>v[i];
}

int dfs(int i){
    if(i==n){
        int mp=0;
        vec(4,0,cnt);
        vec(3,0,tmp);
       /* rep(kk,n){
            cout<<k[kk]<<" ";
        }
        cout<<endl;*/
        rep(jj,n){
            cnt[k[jj]]++;
            tmp[k[jj]]+=v[jj];
        }
        if(cnt[0]*cnt[1]*cnt[2]!=0){
            rep(jj,3)mp+=abs(tmp[jj]-a[jj]);
            mp+=((cnt[0]+cnt[1]+cnt[2]-3)*10);
            return mp;
        }
        return INT_MAX;
    }
    rep(j,4){
        k[i]=j;
        //cout<<"dd"<<endl;
        ans=min(dfs(i+1),ans);
    }
    return ans;
}

int main(){
    
    init();
    cout<<dfs(0)<<endl;
    return 0;
}

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

int main() {

    int a1, a2, a3; std::cin >> a1 >> a2 >> a3;
    int sum = a1+a2+a3;
    if (sum>21) {
        std::cout << "bust" << '\n';
    }else{
        std::cout << "win" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
import itertools
import math
import fractions
import functools
import copy

n,d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
l = list(range(0,n))
pair = list(itertools.combinations(l, 2))
count = 0
for i in range(len(pair)):
    distance = 0
    for j in range(d):
        distance += (x[pair[i][0]][j] - x[pair[i][1]][j])**2
    if (math.sqrt(distance)).is_integer():
        count += 1
print(count)

Measured memory_bytes: 63980
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
typedef long long ll;
#define mp make_pair
#define rep(i,k,n) for(int i=k;i<n;i++)
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define boostt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const ll mod = 1000000007;
const ll inf = 2e18;
const ll N = 1e5;
ll fastpow(ll a,ll b){
  if(b == 0)
    return 1;
  else if(b%2 == 0)
   return fastpow(a*a,b/2);
  else if(b%2 != 0 )
   return a*fastpow(a*a,(b-1)/2);
}
void max_self(ll &a,ll b){
  a = max(a,b);
}
ll Dp[3*N];
signed main(){
       ll n,w;
       cin>>n>>w;
       for(ll i=0;i<n;i++){
         ll weight,value;
         cin>>weight>>value;
         for(ll weight_already=w;weight_already>=0;weight_already--){
             max_self(Dp[weight_already+weight],Dp[weight_already]+value);
         }
       }
       ll ans = 0;
       for(ll i=0;i<=w;i++){
        max_self(ans,Dp[i]);
       }
       cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

import sys
from collections import deque

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def bfs(N: int, nodes: list, src: int) -> list:
    """ 幅優先探索(頂点数, 隣接リスト(0-indexed), 始点) """

    # 頂点[ある始点からの最短距離] (経路自体を知りたい時はここに前の頂点も持たせる)
    res = [[INF] * N for i in range(3)]
    # スタート位置
    que = deque([(0, src)])
    res[0][src] = 0
    # キューが空になるまで
    while len(que) != 0:
        # 現在のノード
        k, cur = que.popleft()
        # 出発ノードcurの到着ノードでループ
        for nxtk, nxt in nodes[k][cur]:
            # 今回の経路のが短い時
            if res[k][cur] + 1 < res[nxtk][nxt]:
                res[nxtk][nxt] = res[k][cur] + 1
                # 後ろに詰めて、近い方から処理するようにする
                que.append((nxtk, nxt))
    # ノードsrcからの最短距離リストを返却
    return res

N,M=MAP()
nodes=[[] for i in range(N)]
for i in range(M):
    u,v=MAP()
    nodes[u-1].append(v-1)
S,T=MAP()
S-=1
T-=1

# 元の頂点を3層に拡張する
nodes2=[[[] for j in range(N)] for i in range(3)]
for i in range(3):
    for u, node in enumerate(nodes):
        for v in node:
            nodes2[i][u].append(((i+1)%3, v))

res=bfs(N, nodes2, S)
if res[0][T]==INF:
    print(-1)
else:
    # けんけんぱの回数なので/3する
    print(res[0][T]//3)


Measured memory_bytes: 84696
#include <iostream>
using namespace	std;
int main(){

  int h,w,hw[10][10],r=0;
  cin>>h>>w;
  for(int i=0;i<10;i++) for(int j=0;j<10;j++) cin>>hw[i][j];
  for(int k=0;k<10;k++)
    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++) hw[i][j]=min(hw[i][j],hw[i][k]+hw[k][j]);
  for(int i=0,a;i<h;i++) for(int j=0;j<w;j++){
      cin>>a;
      if(~a) r+=hw[a][1];
    }
  cout<<r<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  int N, M, sum = 0;
  cin >> N >> M;
  
  vector<int> A;
  for(int i = 0; i < N; ++i){
    int a;
    cin >> a;
    A.push_back(a);
    sum += a;
  }
  
  double check = ceil(sum / (4.0*M));
  int cnt = 0;
  
  for(int i = 0; i < N; ++i){
    if(A[i] >= check){
      ++cnt;
    }
  }
  
  if(cnt >= M){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int A,B;cin>>A>>B;
    cout<<((B%A)?B-A:A+B)<<endl;
}


Measured memory_bytes: 3504
import collections

N = int(input())

A = [input() for i in range(N)]

sA = list(set(A))
# sAs = sorted(sA)

c = collections.Counter(A)


# print(sA)

count = [] 

# print(count)

for i in range(len(sA)):
    w = sA[i]
    count.append(c[w])
    # count[i] = ss
    
# print(count)

point = []

maX = max(count)

# print(maX)

point2 = [i for i, x in enumerate(count) if x == maX]

ancer = [sA[point2[i]] for i in range(len(point2))]

# print(ancer)

ancerABC = sorted(ancer)

for i in range(len(ancerABC)):
    print(ancerABC[i])
    


    


Measured memory_bytes: 51172
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//const ll INF = 1e18;
//const ll MOD = 1e9+7;
//const double pi = 3.14159265358979;
using vl = vector<ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((ll)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((ll)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll N;
ll Main() {
    cin >> N;
    ll ans = 0;
    for (ll i=1; i<=N; i++) {
        for (ll j=i; j<=N; j+=i) {
            ans += j;
        }
    }
    cout << ans << endl;
    return 0;
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3652
N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
    dp[1] = 1
else:
    dp[1] = 0
for i in range(2, N + 1):
    if i in a:
        continue
    dp[i] = dp[i - 1] + dp[i - 2]
    dp[i] %= INF

print(dp[N])


Measured memory_bytes: 56664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    
    vector<int> p(n), q(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) cin >> q[i];
    
    
    vector<int> a(n);
    for(int i = 0; i < n; i++) a[i] = i + 1;
    
    map<vector<int>, int> mp;
    
    do{
        mp[a] = mp.size();
    }while(next_permutation(a.begin(), a.end()));
    
    int ans = abs(mp[p] - mp[q]);
    
    cout << ans << endl;
    
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif

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

#define pln(x) cout << (x) << endl
#define gcd __gcd

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

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

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

class UnionFind{
  vector<int> _parent, _depth, _size;
public:
  UnionFind(int n): _parent(n), _depth(n,1), _size(n,1){REP(i, n) _parent[i] = i;}
  int root(int i){
    if(_parent[i] == i) return i;
    else return _parent[i] = root(_parent[i]);
  }
  bool same(int i, int j){return root(i) == root(j);}
  int merge(int i, int j){
    int ri = root(i), rj = root(j);
    if(ri == rj) return ri;
    if(ri != rj){
      if(_depth[ri] < _depth[rj]){
	_parent[ri] = rj; _size[rj] += _size[ri];
	return rj;
      }else{
	_parent[rj] = ri; _size[ri] += _size[rj];
	if(_depth[ri] == _depth[rj]) ++_depth[ri];
	return ri;
      }
    }
  }
  int size(int i){return _size[root(i)];}
};

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

  LLI n,m;
  while(cin >> n >> m){
    vector<int> a(m), b(m);
    REP(i,m) cin >> a[i] >> b[i];
    REP(i,m){
      --a[i]; --b[i];
    }

    reverse(ALL(a));
    reverse(ALL(b));
    
    UnionFind uf(n);
    vector<LLI> ans(m);

    LLI temp = 0;
    
    REP(i,m){
      ans[i] = n*(n-1)/2 - temp;
	    
      if(!uf.same(a[i],b[i])){
	LLI x = uf.size(a[i]);
	LLI y = uf.size(b[i]);
	uf.merge(a[i], b[i]);
	LLI z = uf.size(a[i]);

	temp = temp - x*(x-1)/2 - y*(y-1)/2 + z*(z-1)/2;
      }
    }

    reverse(ALL(ans));
    for(auto x : ans) cout << x << endl;
    cerr << endl;
  }
  
  return 0;
}


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

using namespace std;

long long inf=1000000000;

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

	cout<<0<<" "<<0<<" "<<inf<<" "<<1<<" "<<(inf-s%inf)%inf<<" "<<(s+(inf-s%inf)%inf)/inf<<endl;

	return 0;
}


Measured memory_bytes: 256
n, k=map(int, input().split())
a=list(map(int, input().split()))
table=[0]*(n+1)
 
for i in range(n):
    table[a[i]]+=1
 
l=sorted(table, reverse=True)
get=0
for i in range(k):
    get+=l[i]
 
print(sum(l)-get)

Measured memory_bytes: 24852