akhauriyash/Code-Regression huggingface dataset:
//vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
//includeとusing
#include <bits/stdc++.h>
using namespace std;
//型名省略
using ll = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using pll = pair<ll, ll>;
//定数
const ll INF = 1e9;
const ll MOD = 1e9+7;
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define all(A) A.begin(), A.end()
//入力
ll llin() {ll x; cin >> x; return x;}
string stin() {string s; cin >> s; return s;}
vl vlin(ll n) {vl a(n); rep(i,n){cin >> a[i];} return a;}
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}


//main関数
int main() {
    string s, t; cin >> s >> t;

    ll ans = t.size();
    rep(i,s.size() - t.size() + 1){
        ll diff = 0;
        rep(j,t.size()){
            if(s[i + j] != t[j]) diff++;
        }
        ans = min(ans, diff);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define inf (int)(1e8)
using namespace std;

using P = pair<int, int>;
#define fi first
#define se second

int h, w, k;
int d[] = {0, -1, 0, 1};
P st, go;
vector<string> s;
vector<vector<int>> memo;

int solve();
bool isvalid(P &now) {
  return now.first >= 0 && now.first < h && now.se >= 0 && now.se < w &&
         s[now.fi][now.se] == '.';
}

int main() {
  cin >> h >> w >> k;
  cin >> st.first >> st.second >> go.first >> go.second;
  s.resize(h);
  for (int i = 0; i < h; ++i) cin >> s[i];
  cout << solve() << endl;
  return 0;
}

int solve() {
  queue<P> qu;
  --st.first, --st.second, --go.first, --go.second;
  memo.assign(h, vector<int>(w, inf));
  memo[st.fi][st.se] = 0;
  qu.push(st);
  while (qu.size()) {
    P now = qu.front();
    int cos = memo[now.fi][now.se] + 1;
    qu.pop();
    for (int i = 0; i < 4; ++i) {
      P to = now;
      for (int j = 0; j < k; ++j) {
        to.fi += d[i];
        to.se += d[1 ^ i];
        if (!isvalid(to) || memo[to.fi][to.se] < cos) break;
        if (memo[to.fi][to.se] > cos) {
          memo[to.fi][to.se] = cos;
          qu.push(to);
        }
      }
    }
  }
  return memo[go.fi][go.se] == inf ? -1 : memo[go.fi][go.se];
}

Measured memory_bytes: 12160
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a*b;
        int length = (a+b)*2;
        System.out.println(area+" "+length);
    }
}



Measured memory_bytes: 26220
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
 int s,d,f=0,g,h,i,j;
 char a[20];
scanf("%s",a);
for(i=0;i<6;i++) if(a[i]=='1') f++;
printf("%d\n",f);
return 0;
}

Measured memory_bytes: 128
N = int(input())
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

arr = factorize(N)

count = 0
for p,e in arr:
  i = 1
  while True:
    if e < i:
      break
    e -= i
    i += 1
    count += 1      

print(count)

Measured memory_bytes: 9220
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<i64>();
    if n % 2 == 1 {
        println!("0");
        return;
    }
    let max_factorial = 27;
    let mut ans = 0;
    let mut count = 0;
    for i in (0..max_factorial).rev() {
        let temp = n / (2 * 5i64.pow(i)) - count;
        ans += temp * i as i64;
        count += temp;
        // debug!(temp, count);
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

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


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
using namespace std;
int arr[1000];
int main(){
	int k,n;
	cin >> k >> n;
	for(int i=0;i<k;i++)
		cin >> arr[i];
	sort(arr,arr+k);
	long long sum =0;
	for(int i=0;i<n;i++)
		sum += arr[i];
	cout << sum << endl;
	
}

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

N = int(input())


"""
S = []
for i in range(N):
  S.append( input() )

print(S)
"""

ans = [0]*4

for i in range(N):
  S = input()

  if ( S == "AC" ):
    ans[0] += 1
  elif ( S == "WA" ):
    ans[1] += 1
  elif ( S == "TLE" ):
    ans[2] += 1
  else:
    ans[3] += 1

print("AC x",ans[0])
print("WA x",ans[1])
print("TLE x",ans[2])
print("RE x",ans[3])

Measured memory_bytes: 9216
#!/usr/bin/env python3
import sys
import fractions

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    A, B = map(int, readline().split())
    print(A * B // fractions.gcd(A, B))


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
	int n;
	cin>>n;
	int k;
	cin>>k;
	int cost[n+1];
	int dp[n+1];
	dp[1] = 0;
	dp[2] = abs(cost[2]-cost[1])+dp[1];
	for(int i=1;i<=n;i++)
	{
		cin>>cost[i];
	}
	for(int i=2 ;i<=n;i++)
	{
		int minn = INT_MAX;
		for(int j=i-1;j>=1 && j>=i-k;j--)
		{
			minn = min(minn, abs(cost[i]-cost[j]) + dp[j]);
		}
		dp[i] = minn;
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 4368
h, w = map(int, input().split())
S = ["."*(w+2)] + [ "."+input()+"." for _ in range(h) ] + ["."*(w+2)]
for i in range(h+2):
  for j in range(w+2):
    if S[i][j] == "#":
      for k in range(4):
        if S[i+1][j] != "#" and S[i][j+1] != "#" and S[i-1][j] != "#" and S[i][j-1] != "#":
          print("No")
          exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const char ASCII_L_OFFSET = 0x61;
const char ASCII_U_OFFSET = 0x41;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;
    S[K - 1] += 0x20;
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
using namespace std;
int main()
{
string ss;
string ans="A";
while(cin >> ss){
if(ans[ans.length()-1]==ss[0])ans+=ss[2];
else if(ans[ans.length()-1]==ss[2])ans+=ss[0];
else ;
}
cout << ans[ans.length()-1] << "\n";
return 0;
}

Measured memory_bytes: 1164
a,b = gets.chomp.split.map(&:to_i)
n = b.to_s(2).size
as = Array.new(n)
bs = Array.new(n)
(1..n).each do |i|
  if ((b+1)/(2**(i-1))).even?
    bs[i] = 0
  else
    if ((b+1)%(2**(i-1))).even?
      bs[i] = 0
    else
      bs[i] = 1
    end
  end
  if (a/(2**(i-1))).even?
    as[i] = 0
  else
    if (a % (2**(i-1))).even?
      as[i] = 0
    else
      as[i] = 1
    end
  end
end
as[1] = (a/2).odd? ? 1 : 0
bs[1] = ((b+1)/2).odd? ? 1 : 0
a = as.reverse.join.to_i(2)
b = bs.reverse.join.to_i(2)
puts a ^ b


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

using namespace std;

const int Nmax = 1e5+5;
vector<int> v[Nmax];
int i, d[Nmax], x, n;

void dfs(int node)
{
    if(!v[node].size()) return;

    vector<int> val;
    for(auto it : v[node])
    {
        dfs(it);
        val.push_back(d[it]);
    }

    sort(val.begin(), val.end());
    reverse(val.begin(), val.end());

    int nr = 0;
    for(auto it : val)
        d[node] = max(d[node], it + (nr++));

    ++d[node];
}

int main()
{
    scanf("%d", &n);
    for(i=2; i<=n; ++i)
    {
        scanf("%d", &x);
        v[x].push_back(i);
    }

    dfs(1);

    printf("%d\n", d[1]);

    return 0;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  vector<bool> dp(K + 1);
  dp.at(0) = false;
  for (ll i = 1; i <= K; i++)
  {
    bool tmp = false;
    for (auto a : A)
    {
      if (i - a < 0)
        continue;
      
      if (!dp.at(i - a))
      {
        tmp = true;
        break;
      }
    }
    dp.at(i) = tmp;
  }

  cout << ((dp.at(K)) ? "First" : "Second") << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0),cin.tie(0);
	ll k, d;
	cin >> k >> d;
	ll i = d + max((ll)0, (100 * (10 - k)));
	cout << i;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<limits.h>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<set>
#include<vector>
#include<queue>
#include<set>
#include<stdlib.h>
#include<time.h>
using namespace std;
typedef long long ll;
#define inf	0x3f3f3f3f
typedef pair<int,int>	P;
int n,m;
int r;
int def[1001];
/*struct Road{
	int ldis;
	int sdis;
};
vector<Road> roads[300][300];
*/
int l[300][300];
int s[300][300];
ll dp[1010][300];
void init() {
	//memset(,inf,sizeof(road));
	memset(l,inf,sizeof(l));
	memset(s,inf,sizeof(s));
	memset(dp,inf,sizeof(dp));
	for(int i=1; i<=n; i++) {
		l[i][i]=0;
		s[i][i]=0;
	}
}

void floyd() {
	for(int k=1; k<=n; k++) {
		for(int i=1; i<=n; i++) {
			for(int j=1; j<=n; j++) {
				if(l[i][j]>l[i][k]+l[k][j]) {
					l[i][j]=l[i][k]+l[k][j];
				}
				if(s[i][j]>s[i][k]+s[k][j]) {
					s[i][j]=s[i][k]+s[k][j];
				}
			}
		}
	}
}

ll solve() {
	floyd();
	for(int i=1; i<=n; i++) {
		dp[1][i]=s[def[1]][i]+l[i][def[1]];
	}
	for(int i=2; i<=r; i++) {
		for(int j=1; j<=n; j++) {	//上次停船地方
			//分析旱路
			dp[i][j]=min(dp[i][j],dp[i-1][j]+l[def[i-1]][def[i]]);
			//将船停到新地方，为下一次做准备
			for(int k=1; k<=n; k++) {
				dp[i][k]=min(dp[i][k],dp[i-1][j]+l[def[i-1]][j]+s[j][k]+l[k][def[i]]);
			}
		}
	}
	
	return *min_element(dp[r]+1,dp[r]+1+n);
}

int main() {
	int x,y,t;
	char str[2];
	//cout<<(ll)inf<<endl;
	while(scanf("%d%d",&n,&m)!=EOF) {
		if(n==0&&m==0){
			break;
		}
		init();
		while(m--) {
			scanf("%d%d%d%s",&x,&y,&t,str);
			if(str[0]=='L') {
				l[x][y]=l[y][x]=t;
			} else if(str[0]=='S') {
				s[x][y]=s[y][x]=t;
			}
		}
		scanf("%d",&r);
		for(int i=1; i<=r; i++) {
			scanf("%d",&def[i]);
		}
		printf("%lld\n",solve());
	}

	return 0;
}


Measured memory_bytes: 6184
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

struct Cake{
    ll x,y,z;
};

inline ll val(const Cake&a, int mode) {
    ll ret=0;

    if(mode&1)ret+=a.x;else ret-=a.x;
    if(mode&2)ret+=a.y;else ret-=a.y;
    if(mode&4)ret+=a.z;else ret-=a.z;
    return ret;
}

istream& operator>>(istream&i, Cake&c){return i>>c.x>>c.y>>c.z;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int n,m;
    cin>>n>>m;
    vector<Cake> cakes(n);
    cin>>cakes;
    ll max=0;
    ll s;

    REP(i,8){
        sort(all(cakes), [i](const Cake&a, const Cake&b){return val(a, i)>val(b,i);});
        s=0;
        REP(j,m)s+=val(cakes[j],i);
        chmax(max, s);
    }
    cout<<max<<endl;

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    A,V = map(int,input().split())
    B,W = map(int,input().split())
    T = int(input())

    if abs(A - B) <= T * (V - W):
        print('YES')
    else:
        print('NO')
if __name__ == '__main__':
    main()

Measured memory_bytes: 9188
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		
		int a=s.nextInt();
		for(int i=0;i<a;i++){
			String b=s.next();
			String c=s.next();
			int d=0,e=0;
			int temp1=0,temp2=0;
			for(int j=0;j<b.length();j++){
				switch(b.charAt(j)){
					case 'm':
						if(temp2==0)d+=1000;
						else d+=1000*temp2;
						temp2=0;
						break;
					case 'c':
						if(temp2==0)d+=100;
						else d+=100*temp2;
						temp2=0;
						break;
					case 'x':
						if(temp2==0)d+=10;
						else d+=10*temp2;
						temp2=0;
						break;
					case 'i':
						if(temp2==0)d++;
						else d+=temp2;
						temp2=0;
						break;
					default:
						temp2=(int)b.charAt(j)-'0';
				}
			}
			for(int j=0;j<c.length();j++){
				switch(c.charAt(j)){
					case 'm':
						if(temp1==0)e+=1000;
						else e+=1000*temp1;
						temp1=0;
						break;
					case 'c':
						if(temp1==0)e+=100;
						else e+=100*temp1;
						temp1=0;
						break;
					case 'x':
						if(temp1==0)e+=10;
						else e+=10*temp1;
						temp1=0;
						break;
					case 'i':
						if(temp1==0)e++;
						else e+=temp1;
						temp1=0;
						break;
					default:
						temp1=(int)c.charAt(j)-'0';
				}
			}
			int g=d+e;
			if(g/1000>1)System.out.print((int)g/1000+"m");
			else if(g/1000==1)System.out.print("m");
			if(g%1000/100>1)System.out.print((int)g%1000/100+"c");
			else if(g%1000/100==1)System.out.print("c");
			if(g%100/10>1)System.out.print((int)g%100/10+"x");
			else if(g%100/10==1)System.out.print("x");
			if(g%10>1)System.out.print(g%10+"i");
			else if(g%10==1)System.out.print("i");
			System.out.println();
		}
	}
}

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

int main() {
    string s;
    cin >> s;
    stack<char> stk;
    int ans = 0;
    for (char c : s) {
        if (stk.empty()) {
            stk.push(c);
        } else if (stk.top() == c) {
            stk.push(c);
        } else {
            ans += 2;
            stk.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra

xs,ys,xt,yt = map(int,input().split())
N = int(input())
XYR = np.empty((3,N+2),dtype=np.int64)
XYR[:,:2] = [[xs,xt],[ys,yt],[0,0]]

XYR[:,2:] = np.array([input().split() for _ in range(N)], dtype=np.int64).T

X,Y,R = XYR

dist = np.sqrt(np.square(X[:,None] - X[None,:]) + np.square(Y[:,None] - Y[None,:])) # euclid
dist -= R[:,None] + R[None,:]
np.maximum(dist, 0, out = dist)
dist[range(N+2), range(N+2)] = np.inf

graph = csgraph_from_dense(dist, null_value = np.inf)

answer = dijkstra(graph, indices = 0)[1]

print(answer)


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


int main()
{
	int n;
	long int min, max, sum = 0;
	int a[10000];
	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	
	min = a[0];
	max = a[0];
	for (int i = 1; i < n; i++){
		if (a[i]<min){
			min = a[i];
		}

		if (max < a[i]){
			max = a[i];
		}
	}

	cout << min << " " << max << " " << sum << endl;
	
	return 0;
}


Measured memory_bytes: 3108
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main() {
	int i, n, x, y, r;
	double dis1 = 0; double dis2 = 0; double dis3 = 0;double disinf = 0;
	vector<int> X,Y,R;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x;
		X.push_back(x);
	}
	for (i = 0; i < n; i++) {
		cin >> y;
		Y.push_back(y);
	}
	for (i = 0; i < n; i++) {
		r = max(X[i] - Y[i],Y[i]-X[i]);
		R.push_back(r);
	}
	for (i = 0; i < n; i++) {
		dis1 += R[i];
		dis2 += pow(R[i], 2);
		dis3 += pow(R[i], 3);
		if (R[i] > disinf)disinf = R[i];
	}
	cout << fixed << setprecision(7) << dis1 << endl;
	cout << fixed << setprecision(7) << pow(dis2,0.5) << endl;
	cout << fixed << setprecision(7) << pow(dis3,double(1)/3) << endl;
	cout << fixed << setprecision(7) << disinf << endl;
	char t;
	cin >> t;
	return 0;
}


Measured memory_bytes: 3472
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, x, ans;

main () {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> x;
		if (x % 2 == 1 && i % 2 == 1)
			++ans;
	}
	cout << ans << endl;
}
	
        	
//check for the constants

                                                                                   	

                     	             

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

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

  vector<vector<long long>> dp(N.length() + 1, vector<long long>(2));
  dp[0][0] = 0;
  dp[0][1] = 1;

  for(int i = 0; i < N.length(); i++){
    int now = N[i] - '0';
    dp[i + 1][0] = min(dp[i][0] + now, dp[i][1] + (10 - now));
    dp[i + 1][1] = min(dp[i][0] + (now + 1), dp[i][1] + (10 - now - 1));
  }
  cout << dp[N.length()][0] << endl;
}


Measured memory_bytes: 55924
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    string T;
    cin >> T;
    ll N = T.size();
    rep(i,0,N){
        if(T[i] == '?'){
            T[i] = 'D';
        }
    }
    print(T);
    

}

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

Measured memory_bytes: 3744
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer 降順ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        int [] abcxy = inputval();
        int a = abcxy[0];
        int b = abcxy[1];
        int c = abcxy[2];
        int x = abcxy[3];
        int y = abcxy[4];
        long ans;
        if (a+b >= 2*c){
            int largeNumPrice;
            if (x>=y){
                largeNumPrice = a;
            }else{
                largeNumPrice = b;
            }
            if (largeNumPrice <= 2*c){
                ans = Math.min(x,y) * c * 2 + Math.abs(x-y) * largeNumPrice;
            }else{
                ans = Math.max(x,y) * c * 2;
            }

        }else{
            ans = a*x + b*y;
        }

        System.out.println(ans);


    }

}



Measured memory_bytes: 32724
#define _GLIBCXX_DEBUG
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <random>
#include <utility>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <bitset>
#include <sstream>

using namespace std;

#define REP(i,x) for(int i=0; i<(x); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(int argc, const char * argv[]) {
    int n, m, k;
    cin >> n >> m >> k;
    vvi b(n, vi());
    UnionFind u(n);

    REP(i,m){
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        tmp1--;tmp2--;
        u.merge(tmp1,tmp2);
        b[tmp1].push_back(tmp2);
        b[tmp2].push_back(tmp1);
    }
    REP(i,k){
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        tmp1--;tmp2--;
        b[tmp1].push_back(tmp2);
        b[tmp2].push_back(tmp1);
    }

    REP(i,n){
        int ans = u.size(i)-1;
        for(int j : b[i]){
            if(u.issame(i,j))ans--;
        }
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 12160
<?php
fscanf(STDIN, "%d %d %d",$a,$b,$k);
//ユークリッド後除法
function euclidean($val1,$val2) {
	
	if ($val1<$val2) {
		
		$x = $val2;
		$y = $val1;
	}else {
		
		$x = $val1;
		$y = $val2;
	}
	if ($x % $y == 0) {
		
		return $y;
	}else {
		
		return euclidean($y, $x % $y);
	}
}
$y = euclidean($a, $b);
//最大公約数の約数
$divisor = array();
for ($i=1;$i<=$y;$i++){
	
	if ($y % $i == 0){
		
		$divisor[] = $i;
	}
}
echo $divisor[count($divisor) - $k];
?>

Measured memory_bytes: 3956
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()

int main() {
    string S;
    cin >> S;
    int count = 0;
    REP(i, 6){
        if (S[i] == '1')
            count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define mod 1000000007
typedef long long LL;
const int maxn = 100000 + 10;
LL fac[maxn], loc[maxn];
LL power(LL a, LL b) {
    a %= mod;
    LL ans = 1;
    while(b) {
        if(b & 1) ans = (ans * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }
    return ans;
}
LL inv(LL a) {
    return power(a, mod - 2) % mod;
}
void solve() {
    fac[0] = 1;
    for(int i = 1; i <= maxn-1; i++){
        fac[i] = (fac[i-1] * i) % mod;
    }
}
LL c(int n, int k) {
    if(k > n)return 0;
    return (fac[n] * inv(fac[k]) % mod * inv(fac[n-k]) % mod) % mod;
}
int main() {
	solve();
	int n, d, x;
	scanf("%d", &n);
	for(int i = 1; i <= n+1; i++) {
		scanf("%d", &x);
		if(loc[x]) 
			d = n+1 - (i - loc[x] + 1);
		loc[x] = i;
	} 
	printf("%d\n", n);
	for(int i = 2; i <= n+1; i++)
		printf("%lld\n", (c(n+1, i) - c(d, i-1) + mod) % mod);
	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
 
int main () {
	int a=0;
	string W;
	cin >> W ;
	transform(W.begin(),W.end(),W.begin(), ::toupper);

	while(1){
		string T;
		cin >> T;
		if(T=="END_OF_TEXT")break;
		transform(T.begin(),T.end(),T.begin(), ::toupper);

		if(T==W){
			a++;
		}
	}
	cout << a << endl;

	return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include<unordered_map>
using namespace std;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define inf mod1
#define all(x) x.begin(),x.end()
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
    fast;
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        ll n, m;
        cin >> n >> m;
        ll h[n];
        for(int i = 0; i < n; i++){
            cin >> h[i];
        }
        ll cur[n] = {};
        for(int i = 0; i < m; i++){
            ll x, y;
            cin >> x >> y;
            x--; y--;
            cur[x] = max(cur[x], h[y]);
            cur[y] = max(cur[y], h[x]);
        }
        ll o = 0;
        for(int i = 0; i < n; i++){
            if(h[i] > cur[i]){
                o++;
            }
        }
        cout << o << endl;
    }
}

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

int d[3][4]={{0,4,5,1},{0,2,5,3},{4,2,1,3}};//d,u,l,r

void dice(int a[6], int n){
	int tmp = a[d[n][0]];
	a[d[n][0]] = a[d[n][1]];
	a[d[n][1]] = a[d[n][2]];
	a[d[n][2]] = a[d[n][3]];
	a[d[n][3]] = tmp;
}

int check(int a[6], int b[6]){
	for(int i = 0;i < 6;i++)if(a[i] != b[i])return 0;
	return 1;
}

int func(int a[6], int b[6]){
	for(int i = 0;i < 6;i++){
		for(int j = 0;j < 4;j++){
			dice(b, 0);
			if(check(a, b))return 1;
		}
		if(i%2 == 0)dice(b, 1);
		else dice(b, 2);
	}
	return 0;
}

int calc(int a[100][6], int n){
	for(int i = 0;i < n-1;i++){
		int b[6], c[6];
		for(int j = 0;j < 6;j++)b[j] = a[i][j];
		for(int j = i+1;j < n;j++){
			for(int k = 0;k < 6;k++)c[k] = a[j][k];
			if(func(b, c))return 1;
		}
	}
	return 0;
}

int main(){
	int a[100][6];
	int n;cin >> n;
	for(int j = 0;j < n;j++)
	for(int i = 0;i < 6;i++)cin >> a[j][i];
	
	if(calc(a, n))cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define nguyendz the_best

#define all(n) n.begin(),n.end()
#define ll int
#define ld long double
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define pll pair<ll,ll>
#define YES cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;
#define ff first
#define ss second
//#define ((x|y)-y) (x&(~y))
//#define gcd(fibo(x),fibo(y)) = fibo(gcd(x,y))
using namespace std;
const ll maxn=6e5+5;
const ll maxx=1e13;
const ll mod=1e9+7;
const ll mod1=998244353;

//vector<ll> ans;
//bool kt[maxn];

map<ll,map<ll,ll>> mp;
ll ans[maxn];
ll par1[maxn];
ll par[maxn];
vector<ll> st[maxn];
vector<ll> st1[maxn];
ll find_par(ll u)
{
    if (u==par[u]) return u ;
    return par[u]=find_par(par[u]);
}
void  dsu(ll a,ll b)
{
    ll u=find_par(a);
    ll v=find_par(b);
    if (u!=v)
    {
        if (st[u].size()<st[v].size()) swap(u,v);
        par[v]=u;
        for (auto p:st[v])
        {
            st[u].pb(p);
        }
        st[v].clear();
    }
}
ll find_par1(ll u)
{
    if (u==par1[u]) return u ;
    return par1[u]=find_par1(par1[u]);
}
void  dsu1(ll a,ll b)
{
    ll u=find_par1(a);
    ll v=find_par1(b);
    if (u!=v)
    {

        if (st1[u].size()<st1[v].size()) swap(u,v);
        par1[v]=u;
        for (auto p:st1[v])
        {
            st1[u].pb(p);
        }
        st1[v].clear();
    }
}

int main()
{
    // freopen("test.txt","r",stdin);
    // freopen("CHEMIST.OUT","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,k,l;
    cin>>n>>k>>l;
    for (int i=1;i<=n;i++)
    {
        par[i]=i;
        st[i].pb(i);
        par1[i]=i;
        st1[i].pb(i);
    }
    for (int i=1;i<=k;i++)
    {
        ll x,y;
        cin>>x>>y;
        dsu(x,y);
    }
    for (int i=1;i<=l;i++)
    {
           ll x,y;
           cin>>x>>y;
           dsu1(x,y);
    }
    for (int i=1;i<=n;i++)
    {
      auto u=find_par(i);
      auto v=find_par1(i);
    //  cout <<u<<" "<<v<<endl;
      mp[u][v]++;
    }
    for (int i=1;i<=n;i++)
    {
        auto u=find_par(i);
      auto v=find_par1(i);
        cout <<mp[u][v]<<" ";
    }
 //   for (int i=1;i<=n;i++) cout <<ans[i]<<" ";


}


Measured memory_bytes: 71168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int N, M; cin >> N >> M;
  vi box(N, 1);
  vector<bool> red(N, false);
  red[0] = true;

  rep(i,M) {
    int x, y; cin >> x >> y; --x; --y;
    if (red[x]) red[y] = true;
    --box[x]; ++box[y];
    if (box[x] == 0) red[x] = false;
  }

  int sum = 0;
  rep(i,N) if (red[i]) ++sum;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 640
H,W = map(int,input().split())
s = [input() for _ in range(H)]

#独立した黒マスがあるか？
flag = True

for i in range(H):
    for j in range(W):
        f2 = False
        if s[i][j] == '#' :
            if i-1 >= 0 and s[i-1][j] == '#' :
                f2 = True
            if j-1 >= 0 and s[i][j-1] == '#' :
                f2 = True
            if i+1 < H and s[i+1][j] == '#' :
                f2 = True
            if j+1 < W and s[i][j+1] == '#' :
                f2 = True
            if not(f2):
                flag = False
                break
    else:
        continue
    break


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




Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair

using namespace std;
int n,q;
string s;
set<int>pos[27];

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>s>>q;
    for(int i=0;i<n;i++) pos[s[i]-'a'].insert(i);
    while(q--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            int x;
            char c;
            cin>>x>>c;
            x--;
            pos[s[x]-'a'].erase(x);
            s[x]=c;
            pos[s[x]-'a'].insert(x);
        }
        else
        {
            int l,r;
            cin>>l>>r;
            l--,r--;
            int cnt=0;
            for(int i=0;i<='z'-'a';i++)
            {
                auto it=pos[i].lower_bound(l);
                if(it==pos[i].end()) continue;
                if(*it<=r) cnt++;
            }
            cout<<cnt<<'\n';
        }
    }
}


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

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

#define MOD 1000000007

#include <iostream>
#include <sstream>
#include <vector>

template<typename T_bit_data>
class BIT
{
private:
    int cnt; // 実際の要素数
    std::vector<T_bit_data>* data; // データ本体
public:
    BIT(int n)
    {
        cnt = n;
        data = new std::vector<T_bit_data>(cnt + 1);
    }

    virtual ~BIT() { delete data; }

    T_bit_data Sum(int k)
    {
        if(k <= 0 || cnt < k) {
            std::ostringstream s;
            s << "k = " << k;
            throw std::out_of_range(s.str());
        }
        T_bit_data s = 0;
        while(k > 0) {
            s += (*data)[k];
            // 1 であるビットのうち一番下のビットを 0 に
            k -= k & -k; // 目的の 1 であるビットは k & -k で取り出せる
        }
        return s;
    }

    void Add(int k, T_bit_data a)
    {
        if(k <= 0 || cnt < k) {
            std::ostringstream s;
            s << k << " -> " << a;
            throw std::out_of_range(s.str());
        }
        while(k <= cnt) {
            (*data)[k] += a;
            k += k & -k;
        }
    }

    void Show()
    {
        for(int i = 1; i <= cnt; i++) {
            std::cout << (*data)[i] << " ";
        }
        std::cout << std::endl;
    }
};

int main()
{
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);
    rep(n, N) {
        cin >> A[n];
    }

    BIT<ll> bit(2001);
    ll ans = 0;
    rep(i, N) {
        ans += i - bit.Sum(A[i]);
        bit.Add(A[i], 1);
    }
    ans = (ans * K) % MOD;

    ll m = (K * (K - 1) / 2) % MOD;
    rep(i, N) {
        ans = (ans + (N - bit.Sum(A[i])) * m % MOD) % MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
vector<l_l> v;
ll N;
vector<ll> A, B;
vector<ll> idx;
vector<ll> cnt;
vector<ll> Mindex;
bool visited[200100];
int main() {
    cin >> N;
    Mindex.resize(N);
    v.resize(N);
    A.resize(N);
    B.resize(N);
    cnt.resize(N);
    idx.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> v[i].second;
    }
    for(int i = 0; i < N; i++) {
        cin >> v[i].first;
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < N; i++) {
        A[i] = v[i].second;
        B[i] = v[i].first;
        //cerr << A[i] << " " << B[i] << endl;
    }
    for(ll i = 0; i < N; i++) {
        auto itr = lower_bound(B.begin(), B.end(), A[i]);
        idx[i] = distance(B.begin(), itr);
        if(idx[i] == N) {
            cout << "No" << endl;
            return 0;
        }
        cnt[idx[i]]++;
        chmax(Mindex[idx[i]], i);
    }
    ll nowcnt = 0;
    bool ok = false;
    for(int i = 0; i < N; i++) {
        nowcnt += cnt[i];
        if(nowcnt < i + 1) {
            cout << "No" << endl;
            return 0;
        }
        if(nowcnt > i + 1) {
            ok = true;
        }
        if(i > 0) {
            chmax(Mindex[i], Mindex[i-1]);
        }
        if(i < N - 1 and Mindex[i] <= i) ok = true;
    }
    ll nowpos = N - 1;
    string ans = "No";
    for(int timer = 0; timer < N; timer++) {
        if(visited[nowpos]) {
            ans = "Yes";
            break;
        }
        visited[nowpos] = true;
        nowpos = idx[nowpos];
    }
    cout << ans << endl;
    /*
    for(int i = 0; i < N; i++) {
        if(idx[i] == i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    */
    /*
    ll now = N - 1;
    set<int> st;
    for(int i = 0; i < N; i++) {
        st.insert(i);
    }
    for(int timer = 0; timer < N; timer++) {
        if(visited[now]) {
            cout << "Yes" << endl;
            return 0;
        }
        visited[now] = true;
        auto itr = st.upper_bound(idx[now]);
        if(itr == st.begin()) {
            cout << "No" << endl;
            return 0;
        }
        itr--;
        now = *itr;
        st.erase(itr);
    }
    cout << "No" << endl;
    */
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
using namespace std;

#define REP(i, n) for(int i=0;i<(int)n;i++)
typedef vector<int> vi;

int T, n, m;

int main(){
	cin >> n;
	vi d(n);
	set<int> s;
	REP(i, n){
		cin >> d[i];
		s.insert(d[i]);
	}
	REP(i, n-1){
		s.insert(d[i] * 10 + d[i+1]);
	}
	REP(i, n-3){
		s.insert(d[i] * 1000 + d[i+1] * 100 + d[i+2] * 10 + d[i+3]);
	}
	REP(i, n-2){
		s.insert(d[i] * 100 + d[i+1] * 10 + d[i+2]);
	}
	for(int i=0;;i++){
		if(s.count(i) == 0){
			cout << i << endl;
			return 0;
		}
	}
	assert(false);
	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define MX 50
#define EPS 0.00000000001
#define MOD 1000000007
#define PI acos(-1)
#define INF 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    LL sx = 0, sy = 0, a1[a+1],b1[b+1],c1[c];

    a1[a] = INT_MAX;
    loop(i,0,a) cin>>a1[i];
    sort(a1,a1+a);
    b1[b] = INT_MAX;
    loop(i,0,b) cin>>b1[i];
    sort(b1,b1+b);
    loop(i,0,c) cin>>c1[i];
    sort(c1,c1+c,greater<int>());

    int id1 = a - x, id2 = b - y, id3 = c;
    loop(i,0,c)
    {
        if((c1[i] < a1[id1]) && (c1[i] < b1[id2])) {id3 = i; break;}
        else if(c1[i] < a1[id1]) {++id2;}
        else if(c1[i] < b1[id2]) {++id1;}
        else if(a1[id1] < b1[id2]) ++id1;
        else ++id2;
    }

    LL ans = 0;
    loop(i,id1,a) ans += a1[i];
    loop(i,id2,b) ans += b1[i];
    loop(i,0,id3) ans += c1[i];

    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
double cal(long long x)
{
    long long sum=0,temp=x;
    while(x)
	{
        sum+=x%10;
        x/=10;
    }
    return (double)temp/sum;
}
int main()
{
	long long num=0,bot=1,temp1,temp2;
    int k;
    scanf("%d",&k);
    while(1)
	{
        while(1)
		{
			temp1=num+bot;
			temp2=num+bot*10;
			if(cal(temp1)<=cal(temp2))break;
            else bot=temp2-num;
        }
        num+=bot;
        printf("%lld\n",num);
        k--;
        if(!k)break;
    }
}

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

using namespace std;

int main() {
	int N = 0;
	long long diff=0, step=0;
	cin >> N;
	vector <long long> A(N);

	for (int i = 0; i < N; i++){
		cin >> A[i];
		if (i != 0) {
			diff = A[i - 1] - A[i];
			if (diff > 0) {
				step += diff;
				A[i] += diff;
			}
		}
	}

	cout << step << endl;
	return 0;
}


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

using namespace std;

void solve() {
  int N;
  cin >> N;
  int64_t res = 0;
  vector<vector<pair<int, int>>> K(N);
  for (int i = 0; i < N; i++) {
    int k, l, r;
    cin >> k >> l >> r;
    k--;
    K[k].emplace_back(make_pair(l, r));
    res += min(l, r);
  }
  priority_queue<int, vector<int>, greater<int>> que;
  for (int i = 0; i < N; i++) {
    for (auto k : K[i]) {
      if (k.first > k.second) que.push(k.first - k.second);
    }
    while ((int)que.size() > i + 1) {
      que.pop();
    }
  }
  while (!que.empty()) {
    res += que.top();
    que.pop();
  }
  for (int i = N - 1; i > -1; i--) {
    for (auto k : K[i]) {
      if (k.second > k.first) que.push(k.second - k.first);
    }
    while ((int)que.size() > N - i - 1) {
      que.pop();
    }
  }
  while (!que.empty()) {
    res += que.top();
    que.pop();
  }
  cout << res << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 12452
#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=200010;
const double DINF=1e40;
const double EPS=1e-6;
int n;
int pre[N];
int col[N];
int bel[N];
int c[N][2];
struct Data{
	int u;
	double x;
	Data(){}
	Data(int _u,double _x):u(_u),x(_x){}
	friend bool operator < (const Data &a,const Data &b){
		return a.x<b.x;
	}
};
priority_queue<Data> q;
bool use[N];
void readData(){
	scanf("%d",&n);
	for(int v=2;v<=n;v++)
		scanf("%d",&pre[v]);
	for(int i=1;i<=n;i++) 
		scanf("%d",&col[i]);
}
int findBel(int u){
	return bel[u]==u?u:(bel[u]=findBel(bel[u]));
}
double getVal(int u){
	return c[u][1]?(1.0*c[u][0]/c[u][1]):DINF;
}
void init(){
	for(int i=1;i<=n;i++){
		bel[i]=i;
		c[i][0]=(col[i]==0);
		c[i][1]=(col[i]==1);
		if(i>1)
			q.push(Data(i,getVal(i)));
	}
}
bool legal(int u,double now){
	return fabs(now-getVal(u))<=EPS;
}
void solve(){
	ll ans=0;
	Data cur;
	int u,fp;
	while(!q.empty()){
		cur=q.top();
		q.pop();
		u=cur.u;
		if(use[u]||!legal(u,cur.x))
			continue;
		use[u]=true;
		fp=findBel(pre[u]);
		ans+=1ll*c[fp][1]*c[u][0];
		c[fp][0]+=c[u][0];
		c[fp][1]+=c[u][1];
		if(fp!=1)
			q.push(Data(fp,getVal(fp)));
		bel[u]=fp;
	}
	printf("%lld\n",ans);
}
int main(){
	readData();
	init();
	solve();
	return 0;
}


Measured memory_bytes: 9840
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}
int main(){
    ll n,k,q;cin >> n >> k >>q;
    vl v(n);rep(i,n)cin >> v[i];
    ll ans=INF;
    rep(i,n){
        ll ret=0;
        vl copy=v;
        rep(j,n){
            if(copy[j]<v[i])copy[j]=-1;
        }
        //rep(j,n)cout << copy[j] <<" ";cout << endl;
        vl use;priority_queue<ll,vl,greater<ll>> que,init;
        rep(j,n){
            while(j<n&&copy[j]!=-1){
                que.push(copy[j]);j++;
            }
            while(que.size()>=k){
                use.pb(que.top());que.pop();
            }
            que=init;
        }
        sort(all(use));
        //for(auto p:use)cout << p <<" ";cout << endl;
        if(use.size()>=q)chmin(ans,use[q-1]-use[0]);
        //cout << ans <<endl;
    }
    cout << ans <<endl;
} 

Measured memory_bytes: 3720