akhauriyash/Code-Regression huggingface dataset:
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.Unboxed          as AU
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Ord
import           Data.Time
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n =
  replicateM n (map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine)

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n =
  replicateM n (map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine)

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n (map BS.unpack . BS.words <$> BS.getLine)

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main :: IO ()
main = do
  numstr <- getLine
  putStrLn $ solve (map (read . (: "")) numstr)

solve :: [Int] -> String
solve nums = g nums opss
  where
    opss :: [[Op]]
    opss = replicateM 3 [Plus, Minus]
    showOps :: [Int] -> [Op] -> String
    showOps nums ops =
      (concat $ concat (zipWith (\a b -> [show a, show b]) (init nums) ops)) ++
      (show $ last nums) ++ "=7"
    g :: [Int] -> [[Op]] -> String
    g nums (ops:opss)
      | f (tail nums) ops (head nums) == 7 = showOps nums ops
      | otherwise = g nums opss
    f :: [Int] -> [Op] -> Int -> Int
    f [] [] acc = acc
    f (x:xs) (op:ops) acc
      | op == Plus = f xs ops (acc + x)
      | op == Minus = f xs ops (acc - x)

data Op
  = Plus
  | Minus
  deriving (Eq, Ord)

instance Show Op where
  show Plus  = "+"
  show Minus = "-"


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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  cout << a[n/2]-a[n/2-1] << endl;
}

Measured memory_bytes: 640
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let A: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    let mut c = std::collections::HashMap::new();
    for &a in &A { *(c.entry(a).or_insert(0)) += 1; }
    let B = {
        let mut B = A.clone();
        B.sort_by_key(|b| -b);
        B
    };
    let mut x = vec![];
    for &b in &B {
        if c[&b] >= 2 {
            x.push(b);
            *(c.entry(b).or_insert(0)) -= 2;
        }
    }
    let ans = if x.len() >= 2 { x[0] * x[1] } else { 0 };

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

Measured memory_bytes: 12540
#include <iostream>
using namespace std;
int main(void)
{
	int N;
	cin >> N;
	if (N == 1)
	{
		cout << "Hello World" << endl;
	}
	else
	{
		int A, B;
		cin >> A >> B;
		cout << A + B << endl;
	}
	return 0;
}

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

using namespace std;
using P = pair<int, bool>;
using ll = long long;


int pow(int a, int n) {
    int res = 1;
    while (n > 0) {
        if (n & 1) {
            res *= a;
        }
        a *= a;
        n >>= 1;
    }
    return res;
}

int main() {
    int N, M; cin >> N >> M;
    vector<P> D(N);
    vector<int> S(M), C(M);
    for (int i = 0; i < M; i++) {
        cin >> S[i] >> C[i];
        S[i]--;
    }

    for (auto& d:D) {
        d.first = 0;
        d.second = false;
    }

    for (int i = 0; i < M; i++) {
        if (!D[S[i]].second) {
            D[S[i]].first = C[i];
            D[S[i]].second = true;
        } else if (D[S[i]].second && D[S[i]].first != C[i]) {
            cout << -1 << endl;
            return 0;
        } 
    }

    if (N > 1 && D[0].second && D[0].first == 0) {
        cout << -1 << endl;
        return 0;
    } else if (N > 1 && !D[0].second && D[0].first == 0) {
        D[0].first = 1;
    }

    int ans = 0;

    for (int i = 0; i < N; i++) {
        ans += D[i].first * pow(10, (N-i-1));
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i;
	char str[50];
	scanf("%s", str);
	for (i = 0; i < 49; i++)
	{
		if (str[i] == ',') str[i] = ' ';
	}
	printf("%s\n", str);
	return 0;
}

Measured memory_bytes: 128
from sys import stdin
from math import ceil

def main():
    health_strengh = [int(x) for x in stdin.readline().split()]

    if ceil(health_strengh[2] / health_strengh[1]) > ceil(health_strengh[0] / health_strengh[3]):
        print("No")
    elif ceil(health_strengh[2] / health_strengh[1]) <= ceil(health_strengh[0] / health_strengh[3]):
        print("Yes")
    
main()

Measured memory_bytes: 9044
use std::io::*;

const MOD : i64 = 1e9 as i64 + 7;

fn main(){
    let mut c : [[i64; 2001]; 2001] = [[0; 2001]; 2001];
    for i in 0..2001{
        c[i][0] = 1;
        for j in 1..(i + 1){
            c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
            c[i][j] %= MOD;
        }
    }
    let n : usize = input();
    let k : usize = input();
    for i in 1..(k + 1){
        println!("{}", (c[n - k + 1][i] * c[k - 1][k - i]) % MOD);
    }
}

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

Measured memory_bytes: 35580
#include<bits/stdc++.h>
#define fir first
#define sec second
#define db double
#define ll long long
#define ev eg[i].v
#define pb push_back
#define INF 1000000007
#define pir pair<int,int>
#define Rep(i,l,r) for(int i=(l);i<=(r);++i)
#define RepD(i,r,l) for(int i=(r);i>=(l);--i)
#define RepG(i,x) for(int i=hd[x];i;i=eg[i].nxt)
using namespace std;

const int N=1e5+5;

ll hd[N],cnt=0;bool vis[N];
struct Eg{ll v,nxt;}eg[N*2];
ll a[N],b[N],c[N],fa[N],f[N],g[N];

ll find(ll x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void add(ll u,ll v){eg[++cnt]=(Eg){v,hd[u]},hd[u]=cnt;}

bool cmp(ll x,ll y){return a[x]<a[y];}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ll n,m;
	scanf("%lld%lld",&n,&m);
	Rep(i,1,n) scanf("%lld%lld",&a[i],&b[i]),a[i]=max(a[i]-b[i],0ll);
	Rep(i,1,m){
		ll u,v;
		scanf("%lld%lld",&u,&v);
		add(u,v),add(v,u);	
	}
	Rep(i,1,n) c[i]=fa[i]=i;
	sort(c+1,c+n+1,cmp);
	Rep(k,1,n){
		ll x=c[k];
		vis[x]=1,f[x]=a[x],g[x]=b[x];
		RepG(i,x)
			if(vis[ev]){
				ll ff=find(ev);
				if(x==ff) continue;
				fa[ff]=x,g[x]+=g[ff];
				f[x]=min(f[x],max(f[ff],a[x]-g[ff]));	
			}
	}
	printf("%lld\n",f[c[n]]+g[c[n]]);
	return 0;
}




Measured memory_bytes: 8960
#include<stdio.h>
int main()
{
    int i,n[10],j,a;
    for(i=0;i<10;i++)
        scanf("%d",n+i);
    for(i=0;i<10;i++)
    {
        for(j=i+1;j<10;j++)
            if(n[i]<n[j])
        {
            a=n[i];
            n[i]=n[j];
            n[j]=a;
        }
    }
    for(i=0;i<3;i++)
        printf("%d\n",n[i]);
    return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n; cin>>n;
	int a[200020];
	for(int i=0; i<n; i++) cin>>a[i];
	map<int, ll> mp1, mp2;
	for(int i=0; i<n; i++){
		mp1[i-a[i]]++;
		mp2[i+a[i]]++;
	}
	ll ans=0;
	for(auto p:mp1){
		int x=p.first;
		if(mp2.find(x)!=mp2.end()){
			ans+=p.second*mp2[x];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 27368
//ABC083B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<long long int> a(n), count(n);
	for(int i=0;i<n;i++){
		cin >> a.at(i);
		count.at(i) = 0;
		while(a.at(i)%2 == 0){
			count.at(i)++;
			a.at(i) /= 2;
		}
	}
	sort(count.begin(),count.end());
	cout << count.at(0) << endl;
	return 0;
}

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

signed main() {
  int N;cin>>N;
  int A,B,C;cin>>A>>B>>C;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int ans=1e9;
  do{
    for(int i=1;i<=N;i++){
      for(int j=i+1;j<=N;j++){
        for(int k=j+1;k<=N;k++){
          std::vector<int> w(3,0);
          for(int p=0;p<i;p++)w[0]+=v[p];
          for(int p=i;p<j;p++)w[1]+=v[p];
          for(int p=j;p<k;p++)w[2]+=v[p];
          sort(w.begin(),w.end());
          ans=min(ans,abs(C-w[0])+abs(B-w[1])+abs(A-w[2])+(k-3)*10);
        }
      }
    }
  }while(std::next_permutation(v.begin(), v.end()));
  cout<<ans<<endl;
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main() {
    int i,n,m,k,sum=0;
    c_p_c();
  	cin>>n>>m;
  	string s[n];
  	fo(i,n) cin>>s[i];


  	for (int i = 0; i < n; ++i)
  	{
  		for (int j = 0; j < m; ++j)
  		{
  			/* code */
  			
  	
  		int c=0;
  		// watch(s[i][j]);

  		if(s[i][j]=='.'){
  			// cout<<s[i][j]<<endl;

  			if(i-1>=0 and s[i-1][j]=='#'){
  				c++;
  			}
  			if(i+1<n and s[i+1][j]=='#')c++;
  			if(j+1<m and s[i][j+1]=='#') c++;
  			if(j-1>=0 and s[i][j-1]=='#') c++;

  			if(i-1>=0 and j-1>=0 and s[i-1][j-1]=='#') c++;
  			if(i-1>=0 and j+1<m and s[i-1][j+1]=='#') c++;
  			if(i+1<n and j-1>=0 and s[i+1][j-1]=='#') c++;
  			if(i+1<n and j+1<m and s[i+1][j+1]=='#') c++;
  			// watch(c);
  			s[i][j]=c+'0';



  		}


  	}}

  	fo(i,n){
  		cout<<s[i]<<endl;
  		// cout<<endl;/
  	}

 	return 0;

   }

Measured memory_bytes: 3596
n = int(input())
L = [0] * (n + 1)

for i in range(n + 1):
    if i == 0:
        L[i] = 2
    elif i == 1:
        L[i] = 1
    else:
        L[i] = L[i - 1] + L[i - 2]

print(L[-1])

Measured memory_bytes: 3060
/*depth first search
not lie in stack
*/
#include <iostream>
using namespace std;
static const int N=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int M[N][N],n;
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
	int v;
	color[u]=GRAY;
	d[u]=++tt;
	for(v=0;v<n;v++){
		if(M[u][v]==0)
			continue;
		if(color[v]==WHITE){
			dfs_visit(v);
		}
	}
	color[u]=BLACK;
	f[u]=++tt;
	
}

void dfs(){
	int u;
	for(int i=0;i<n;i++){
		color[i]=WHITE;
	}
	tt=0;
	
	for(u=0;u<n;u++){
		if(color[u]==WHITE)
			dfs_visit(u);
	}
	
	for(int i=0;i<n;i++)
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
}

int main(){
	
	int k,u,v;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)
			M[i][j]=0;
	}
	for(int i=0;i<n;i++){
		cin>>u>>k;
		u--;
		for(int j=0;j<k;j++){
			cin>>v;
			v--;
			M[u][v]=1;
		}
	}
		
	dfs();	

	return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const ll INF = 1LL << 40;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> T(N), D(N);
    rep(i, 0, N) {
        cin >> T[i] >> D[i];
    }
    vector<vector<ll>> values(N);
    rep(i, 0, N) {
        values[T[i] - 1].push_back(D[i]);
    }
    rep(i, 0, N) {
        values[i].push_back(-INF);  // 番兵
        sort(all(values[i]));
        reverse(all(values[i]));
    }
    sort(all(values));
    reverse(all(values));
    ll ans = (ll)K * (ll)K;
    priority_queue<ll, vector<ll>, greater<ll>> que1;
    priority_queue<ll> que2;
    rep(i, 0, K) {
        ans += values[i].front();
        que1.push(values[i].front());
        rep(j, 1, values[i].size()) {
            que2.push(values[i][j]);
        }
    }
    rep(i, K, N) for (auto& v : values[i]) {
        que2.push(v);
    }
    ll sum = ans;
    rrep(x, K, 1) {
        ll now = que1.top();
        que1.pop();
        ll next = que2.top();
        que2.pop();
        sum += next - now + (ll)x * (ll)x - (ll)(x + 1) * (ll)(x + 1);
        chmax(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    if ((B - A) % 2 == 0) {
        cout << (B - A) / 2 << "\n";
    } else {
        cout << min(A + (B - A - 1) / 2, N - B + 1 + (B - A - 1) / 2) << "\n"; 
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
int main() {
   string N;
   int S = 0;
   cin >> N;
   rep(i,N.size()){
       S += N[i] - '0';
   }
   if(stoi(N) % S == 0){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }
   return 0;
}

Measured memory_bytes: 256
def main():
    s = input()
    c = 0
    pos = 0
    a = 0

    while pos < len(s):
        if s[pos] == 'A':
            a += 1
            pos += 1
        elif s[pos:pos+2] == 'BC':
            c += a
            pos += 2
        else:
            a = 0
            pos += 1

    print(c)
        


main()


Measured memory_bytes: 3628
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <tuple>
#include <vector>

// lib/quo.hpp
#ifndef QUO_H
#define QUO_H

/*
a == tools:quo(a, b) * b + tools::mod(a, b)
0 <= tools::mod(a, b) < std::abs(b)
*/

namespace tools {
  template <typename T>
  constexpr T quo(const T lhs, const T rhs) {
    return lhs > 0 ? lhs / rhs : rhs > 0 ? -((-lhs - 1 + rhs) / rhs) : (-lhs - 1 + -rhs) / -rhs;
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/extgcd.hpp
#ifndef EXTGCD_HPP
#define EXTGCD_HPP


/*
usage:

std::tuple<int, int, int> result = tools::extgcd(4, 5);
int gcd = std::get<0>(result);
int x0 = std::get<1>(result);
int y0 = std::get<2>(result);
*/

namespace tools {
  template <typename T>
  std::tuple<T, T, T> extgcd(T prev_r, T r) {
    T prev_s = 1;
    T prev_t = 0;
    T s = 0;
    T t = 1;
    while (r != 0) {
      const T q = quo(prev_r, r);
      const T next_r = prev_r - q * r;
      prev_r = r;
      r = next_r;
      const T next_s = prev_s - q * s;
      prev_s = s;
      s = next_s;
      const T next_t = prev_t - q * t;
      prev_t = t;
      t = next_t;
    }
    return std::make_tuple(prev_r, prev_s, prev_t);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::cout << 2 / std::get<0>(tools::extgcd<i64>(2, N)) * N << std::endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[int(x) for x in input().rstrip().split()]
x1=sum(a)-2*sum([a[i] for i in range(1,n-1,2)])
x=[x1]
for i in range(1,n):
  x.append(2*a[i-1]-x[i-1])
print(*x)

Measured memory_bytes: 20716
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int a[101][101],b[101];
    int m,n,i,j,sum[101];
    
    scanf("%d %d", &n, &m);
    
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            scanf("%d",&a[i][j]);
        }
    }
    
    for(i=0; i<m; i++){
        scanf("%d",&b[i]);
    }
    
    for(i=0; i<n; i++){
        sum[i] = 0;
        for(j=0; j<m; j++){
            sum[i] += a[i][j]*b[j];
        }
        printf("%d\n",sum[i]);
    }
    
    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <iomanip>
#include<cmath>
using namespace std;
int main(void){
    double r;
    cin >>r;
    
    double pi=acos(-1);
    cout<<fixed<<setprecision(6);
    double area = r*r*pi;
    double cir=(r+r)*pi;
    cout<<area<<" "<<cir<<endl;

    
}



Measured memory_bytes: 3276
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string s,t;
  cin >> s >>t;
  int flag = 0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)==t.at(i));
    else flag = 1;
  }
  if(flag==1)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3540
# list(map(int,input().split()))

s=input()
n = len(s)
flag = True
if flag:
	flag = s == s[::-1]
if flag:
	t = s[:(n - 1) // 2]
	flag = t == t[::-1]
if flag:
	t = s[(n + 2) // 2:]
	flag = t == t[::-1]
if flag:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 3060
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
using namespace std;


#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<VV> VVV;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}


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

	int max1 = 0,flag,premax=1,ite=1;

	if (s[0] == '0') {
		flag = 0;
		k--;
	}
	else {
		flag = 1;
	}

	for (int i = 1; i < s.length(); i++) {
		if ((s[i] == '0') && (flag == 1)) {
			if (k == 0) {
				if (max1 < premax)max1 = premax;
				while ((s[ite] != '1') || (s[ite-1] != '0')) {
					ite += 1;
					premax--;
				}
				ite++;
			}
			else {
				k -= 1;
				premax += 1;
			}
		}
		else {
			premax += 1;
		}

		if (s[i] == '0') {
			flag = 0;
		}
		else {
			flag = 1;
		}
	}
	cout << max(max1,premax) << endl;;
}


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

int a, b, q;
vector<long long> va;
vector<long long> vb;
int idxA, idxB;

class X {
    public : int idx;
    public : long long x;
    public : long long l;
    X(int i, long long s){
        idx = i;
        x = s;
    }
};
vector<X> vX;

bool cmp_idx(const X &a, const X &b){
    return a.idx < b.idx;
}

bool cmp_x(const X &a, const X &b){
    return a.x < b.x;
}

void init() {
    cin >> a >> b >> q;
    for(int i = 0; i < a; i++){
        long long s;
        cin >> s;
        va.push_back(s);
    }
    for(int i = 0; i < b; i++){
        long long s;
        cin >> s;
        vb.push_back(s);
    }
    for(int i = 0; i < q; i++){
        long long x;
        cin >> x;
        X X(i, x);
        vX.push_back(X);
    }
    sort(vX.begin(), vX.end(), cmp_x);
}

long long solve(long long x){
    for(int i = idxA; i < a; i++){
        if(x < va.at(i)) break;
        idxA++;
    }
    for(int i = idxB; i < b; i++){
        if(x < vb.at(i)) break;
        idxB++;
    }
    long long westA, eastA, westB, eastB;
    if(idxA == 0) westA = -50000000000;
    else westA = va.at(idxA - 1);
    if(idxA == a) eastA = 50000000000;
    else eastA = va.at(idxA);
    if(idxB == 0) westB = -50000000000;
    else westB = vb.at(idxB - 1);
    if(idxB == b) eastB = 50000000000;
    else eastB = vb.at(idxB);
    long long minL = max(x - westA, x - westB);
    minL = min(minL, (eastA - x) + (eastA - westB));
    minL = min(minL, (x - westB) + (eastA - westB));
    minL = min(minL, (eastB - x) + (eastB - westA));
    minL = min(minL, (x - westA) + (eastB - westA));
    minL = min(minL, max(eastA - x, eastB - x));
    return minL;
}
 
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	init();
	
	for(int i = 0; i < q; i++){
	    vX.at(i).l = solve(vX.at(i).x);
	}
    sort(vX.begin(), vX.end(), cmp_idx);
 
	for(int i = 0; i < q; i++){
	    cout << vX.at(i).l << "\n";
	}
	return 0;
}

Measured memory_bytes: 6640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class281
    {
        static void Main()
        {
            var NM = Array.ConvertAll(Console.ReadLine().Split(),int.Parse );
            int N = NM[0], M = NM[1];
            var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            int ans = N - A.Sum();
            if (ans < 0) Console.WriteLine(-1);
            else Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28892
/*
Hey there stalker....

█▀▀▄░░░░░░░░░░░▄▀▀█
░█░░░▀▄░▄▄▄▄▄░▄▀░░░█
░░▀▄░░░▀░░░░░▀░░░▄▀
░░░░▌░▄▄░░░▄▄░▐▀▀
░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█
░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█
▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█
█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀
░▀▄░░▀░░▀▀▀░░▀░░░▄█▀
░░░█░░░░░░░░░░░▄▀▄░▀▄
░░░█░░░░░░░░░▄▀█░░█░░█
░░░█░░░░░░░░░░░█▄█░░▄▀
░░░█░░░░░░░░░░░████▀
░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀

Like what you see?
*/
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pii         pair<ll ,ll>
#define vi          vector<ll>
#define present(container, element) (container.find(element) != container.end()) /* For set n maps */
#define cpresent(container, element) (find(all(container),element) != container.end()) /* For vectors */
#define all(a)      (a).begin(),(a).end()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define F           first
#define S           second
#define I           insert
#define sz(x)       (ll)x.size()
#define rep(i,a,b)    for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define trav(a, x) 	for(auto& a : x)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lcase(a) (char)tolower(a)
#define ll long long int
#define lld long double
#define endl "\n"
#define PI 3.14159265358979323844
#define MOD 1000000007
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define mod 1e9 + 7
const int N = 1e5 + 5;
/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

int32_t main()
{
   IOS

    int TESTS=1;
    //cin >> TESTS;
    while (TESTS--)
    {
    	ll n;
    	cin >> n;
        vi v(n+1);
       map<int ,int >mp;
        for(int i=1;i<=n;i++)
        {
        	cin >> v[i];
        }
        for(int i=1;i<=n;i++)
		{
			mp[i+v[i]]++;

		}
		ll ans=0;

		for(int i=1;i<=n;i++)
		{
			ans+=mp[i-v[i]];


		}//		for(auto ap:mp)
//		{
//			cout<< ap.first << " "<< ap.second << endl;
//		}


		cout<< ans << endl;







    }
    return 0;
}


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;

    
    return 0;
}


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

#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=1e5+5;
vector<int>lk[N];
int fa[N],deep[N];
int s[N];
int np[N],p1[N],p2[N];

void dfs(int x,int fr)
{
	fa[x]=fr;deep[x]=deep[fr]+1;
	for(auto y:lk[x])
	if(y!=fr)dfs(y,x);
}

int main()
{
	int n;
	cin>>n;
	rep(i,1,n)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		lk[x].push_back(y);lk[y].push_back(x);
	}
	dfs(1,0);
	int x=1;
	rep(i,2,n)
	if(deep[i]>deep[x])x=i;
	dfs(x,0);
	int y=1;
	rep(i,2,n)
	if(deep[i]>deep[y])y=i;
	for(int i=y;i;i=fa[i])s[i]=1;
	rep(i,1,n)
	if(!s[i]&&++s[fa[i]]==1)
	{
		puts("-1");
		exit(0);
	}
	vector<int>a;
	for(int i=y;i;i=fa[i])a.push_back(s[i]);
	int top=0;
	for(auto i:a)
	{
		np[top+1]=top+i;
		rep(j,1,i-1)np[top+1+j]=top+j;
		top+=i;
	}
	rep(i,1,n)p1[np[i]]=i;
	top=0;
	for(auto it=a.end();--it>=a.begin();)
	{
		int i=*it;
		np[top+1]=top+i;
		rep(j,1,i-1)np[top+1+j]=top+j;
		top+=i;
	}
	rep(i,1,n)p2[np[i]]=i;
	int i=1;
	while(p1[i]==p2[i]&&i<=n)++i;
	if(p1[i]<p2[i])
	{
		rep(i,1,n)printf("%d ",p1[i]);
	}
	else
	{
		rep(i,1,n)printf("%d ",p2[i]);
	}
}


Measured memory_bytes: 13816
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>

namespace n91 {

void main_() {
  u32 a, b, c;
  std::cin >> a >> b >> c;
  std::cout << std::max(c, a - b) - (a - b) << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


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

int main(){
    int N; cin >> N;
    vector<int> p(N);
    for(int i = 0; i < N; i++) cin >> p[i];

    vector<int> pA(N);                      //pのソートされたもの
    copy(p.begin(), p.end(), pA.begin());
    sort(pA.begin(), pA.end());

    int ans = N;
    for(int i = 0 ; i < N; i++){
        if(p[i] == pA[i]) ans--;
    }
    cout << ((ans <= 2) ? "YES" : "NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <typeinfo>
#include <list>
#include <queue>
#include <stack>
#include <limits.h>
#include <unordered_set>
#include <map>
#include <cstring>

using namespace std;

typedef long long ll;

int mod = 1e9 + 7;

int Solve(int N, vector<ll> A, vector<ll> B) {
    vector<ll> record;
    ll residue = 0;
    int res = 0;
    for (int i =0; i < N; i++) {
        if (A[i] > B[i]) {
            record.push_back(A[i] - B[i]);
        }
        if (A[i] < B[i]){
            residue += B[i] - A[i];
            res++;
        }
    }
    sort(record.begin(), record.end(), greater<int>());
    int i = 0, n = record.size();
    while (residue > 0 && i < n) {
        residue -= record[i++];
        res++;
    }
    if (residue > 0) {
        return -1;
    }
    return res;
}


int main() {
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    cout << Solve(N, A, B);
    return 0;
}


Measured memory_bytes: 3964
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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


int main() {
	int N;
	cin >> N;
	map<string, int> ss;
	rep(i , N) {
		string s;
		cin >> s;
		ss[s]++;
	}
	vector<pair<int, string> > a;
	for (auto m : ss) {
		a.push_back(make_pair(m.second, m.first));
	}

	sort(a.rbegin(), a.rend());

	int count = a[0].first;
	int ans = 0;

	rep(i , a.size()) {
		if (a[i].first != count) {
			break;
		}
		ans++;
	}
	for (int i = ans - 1; i >= 0; i--) {
		cout << a[i].second << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long x;
  cin >> x;
  long long ans = (x + 10) / 11 * 2;
  if (x % 11 >= 1 && x % 11 <= 6) ans--;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <algorithm>

int f[3001][3001],n,q,x[3001],y[3001],a[3001],Pow[3001],ans;
const int P=1000000007;
inline int mul(const int &a,const int &b){return 1ll*a*b%P;}
inline int add(int a,const int &b){a+=b;return(a>=P)?a-P:a;}
inline int sub(int a,const int &b){a-=b;return (a<0)?a+P:a;}
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	Pow[0]=1;
	for(int i=1;i<=q;i++)scanf("%d%d",x+i,y+i),(x[i]>y[i])?std::swap(x[i],y[i]):(void)0,Pow[i]=add(Pow[i-1],Pow[i-1]);
	for(int i=q;i;i--){
		for(int j=1;j<=n;j++)
			if(j<x[i])f[j][x[i]]=f[j][y[i]]=mul(add(f[j][y[i]],f[j][x[i]]),(P+1)>>1);
			else if(j>x[i]&&j<y[i]){
				int tem=mul(add(f[x[i]][j],sub(1,f[j][y[i]])),(P+1)>>1);
				f[j][y[i]]=mul(add(f[j][y[i]],sub(1,f[x[i]][j])),(P+1)>>1);
				f[x[i]][j]=tem;
			}
			else if(j>y[i])f[x[i]][j]=f[y[i]][j]=mul(add(f[y[i]][j],f[x[i]][j]),(P+1)>>1);
		f[x[i]][y[i]]=(P+1)>>1;
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(a[i]<a[j])ans=add(ans,f[i][j]);
			else if(a[i]>a[j])ans=add(ans,sub(1,f[i][j]));
	printf("%d\n",mul(ans,Pow[q]));
} 

Measured memory_bytes: 35200
#include <stdio.h>

int
main(void)
{
	int i;
	int a;
	int b;
	int c;
	int cnt = 0;

	scanf("%d %d %d", &a, &b, &c);
	
	for (i = a; i <= b; i++) {
		if (c % i == 0)
			cnt++;
	}
	printf("%d\n", cnt);

	return 0;
}


Measured memory_bytes: 2092
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

n=int(input())
ans="{}:".format(n)
if is_prime(n)==True:
    ans+=' '
    ans+=str(n)
    print(ans)
    exit()
lis=[]
flag=True
import math
while flag:
    flag=False
    for i in range(2,n+1):
        if n%i==0:
            lis.append(i)
            n//=i
            flag=True
            break
for i in lis:
    ans+=" "
    ans+=str(i)
print(ans)


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

string s;
int n, k;

int main() {
  cin >> s >> k;
  n = s.length();
  vector<string> v;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j + 1 <= 5 && i + j - 1 < n; ++j)
      v.push_back(s.substr(i, j + 1));
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  cout << v[k - 1] << '\n';
  return 0;
}

Measured memory_bytes: 1660
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
    
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


N, M = map(int,input().split())
A = sorted(list(map(int,input().split())))

#if gcd(*A) % 2 != 0:
    #print(0)
    #exit(0)

#sisu_2 = factorization(A[0])[0][1] 
sisu_2 = min([factorization(A[i])[0][1] for i in range(min(1000,N))])

#lcm_a = lcm(*A)
#lcm_a_half = lcm_a // 2
lcm_a = lcm(*A) // 2
'''
l = []
sisu_a0 = 0
for i in range(N):
    sisu = 0
    while A[i]%2==0:
        A[i] //= 2
        sisu += 1
    
    if sisu_a0==0:
        sisu_a0 = sisu
    else:
        if sisu_a0!=sisu:
            print(0)
            exit()
'''
if (lcm_a % (2**sisu_2) == 0) or lcm_a > M:
#factorization(lcm_a)[0][1] != sisu_2 or lcm_a_half > M:
#if lcm_a > M:
    print(0)
    exit(0)
else:
    print(int((M-lcm_a) // (lcm_a*2) + 1))

Measured memory_bytes: 16308
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		int[] arr2 = Arrays.copyOf(arr, n);
		Arrays.sort(arr2);
		for(int i = 0; i < n; i++) {
			map.put(arr2[i], i);
		}
		for (int i = 0; i < n; i++) {
			if (map.get(arr[i]) < n/2) {
				System.out.println(arr2[n/2]);
			} else {
				System.out.println(arr2[(n/2)-1]);
			}
		}
	}
}


Measured memory_bytes: 106208
str = input()
q = int(input())
for i in range(q):
    s = input().split(" ")
    cmd,a,b = s[0],int(s[1]),int(s[2])
    if(cmd=="print"):
        print(str[a:b+1])
    elif(cmd=="reverse"):
        str = str[:a]+str[a:b+1][::-1]+str[b+1:]
    else:
        str = str[:a]+s[3]+str[b+1:]

Measured memory_bytes: 7624
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
struct Node;
vector<Node> V;
struct Node {
  int idx;
  vector<int> nbr;
  bool vst = false;
  int dfs() {
    vst = true;
    vector<int> subtree;
    for(int x : nbr) {
      if(!V[x].vst) {
        subtree.push_back(V[x].dfs());
      }
    }
    if(subtree.size() == 0) return 0;
    sort(ALL(subtree), greater<int>());
    REP(i, subtree.size()) subtree[i] += i;
    sort(ALL(subtree), greater<int>());
    return subtree[0]+1;
  };
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  REP(i, N) V.emplace_back();
  FOR(i, 1, N) {
    int j;
    cin >> j;
    j--;
    V[i].nbr.push_back(j);
    V[j].nbr.push_back(i);
  }
  cout << V[0].dfs() << endl;
}

Measured memory_bytes: 13548
#include <stdio.h>
int main(void){
  int e1,e2,e3,e4;
  scanf("%d %d %d %d",&e1,&e2,&e3,&e4);
    if(e1==e2&&e3==e4){
      printf("yes");
    }else if(e1==e4&&e2==e3){
      printf("yes");
    }else if(e1==e3&&e2==e4){
      printf("yes");
    }else if(e1==e2==e3==e4){
      printf("yes");
    }else{
      printf("no");
    }
    printf("\n");
    return 0;
}
      



Measured memory_bytes: 2756
use std::io;
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn main() {
    let s: String = read();
    let p: String = read();
    let ss = format!("{}{}", s, s);
    let mut b = false;
    for i in 0..s.len() {
        if p == &ss[i..i + p.len()] {
            b = true;
            break;
        }
    }
    println!("{}", if b { "Yes" } else { "No" });
}



Measured memory_bytes: 5020
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import sys
sys.setrecursionlimit(40000000)

n,q = mi()
b = [[] for i in range(n)]
ans = [0]*n

# O(2n)
for i in range(n-1):
    a,c = mi()
    b[a-1].append(c-1)
    b[c-1].append(a-1)

# jun = []
# O(2n)
# def chil_pop(l,p):
#     jun.append(l)
#     for i in b[l]:
#         if i == p:
#             continue
#         chil_pop(i,l)
#     b[l] = p

# chil_pop(0,-1)


# O(q)
for i in range(q):
    p,x = mi()
    ans[p-1] += x


count = 0
q = [(0,-1)]
while q:
    c,p = q.pop()
    for i in b[c]:
        if i == p:
            continue
        ans[i] += ans[c]
        q.append((i,c))
    
    

# for i in jun[1:]:
#     ans[i] += ans[b[i]]

# ans_str = ''
# for i in range(n):
#     print(ans[i],end=' ')
#     # ans_str = ans_str + str(ans[i]) + ' '
print(*ans)


Measured memory_bytes: 60392
import qualified Data.IntMap as M

type Map = M.IntMap

main :: IO ()
main = do
  n <- read <$> getLine
  print . eval . iter f (n - 3) . insert [0, 2, 1] 0 . insert [2, 0, 1] 0 . insert [0, 1, 2] 0 . fromList $ zip triple (repeat 1)

f :: Map Integer -> Map Integer
f kvs = fromList . map ((,) <$> id <*> g) $ triple
  where
    g t@(x : y : z : _) = foldl step 0 [0 .. 3] `mod` m
      where
        step r w = r + if match [x, y, z, w] then 0 else kvs ! [y, z, w]

insert :: [Int] -> Integer -> Map Integer -> Map Integer
insert = M.insert . encode

fromList :: [([Int], Integer)] -> Map Integer
fromList = M.fromList . map ((,) <$> encode . fst <*> snd)

(!) :: Map Integer -> [Int] -> Integer
(!) = flip $ flip (M.!) . encode

triple :: [[Int]]
triple = sequence . replicate 3 $ [0 .. 3]

eval :: Map Integer -> Int
eval = fromInteger . M.foldl step 0
  where
    step r k = (r + k) `mod` m

bads :: [[Maybe Int]]
bads = [[Nothing, Just 0, Just 2, Just 1], [Just 0, Nothing, Just 2, Just 1], [Just 0, Just 2, Nothing, Just 1], [Just 0, Just 2, Just 1, Nothing], [Nothing, Just 2, Just 0, Just 1], [Just 2, Just 0, Just 1, Nothing], [Nothing, Just 0, Just 1, Just 2], [Just 0, Just 1, Just 2, Nothing]]

match :: [Int] -> Bool
match = or . map (and . map match') . flip map bads . zip
  where
    match' (x, Just y) | x /= y = False
    match' _ = True

m :: Integer
m = 10 ^ 9 + 7

iter :: (a -> a) -> Int -> a -> a
iter f = g
  where
    g 0 = id
    g n = f . g (pred n)

encode :: [Int] -> Int
encode = foldr step 0
  where
    step x r = x + 4 * r


Measured memory_bytes: 2556
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define prec(n) fixed<<setprecision(n)
#define MOD 1000000007
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}


vector<vi> dp(100001,vi(100,-1));
vector<vi> v(100000,vi(2));
int n;
int f(int weig,int indx){
    if(indx>=n)return 0;
    if(dp[weig][indx]!=-1)return dp[weig][indx];
    int ans=INT_MIN,a,b;a=b=ans;
    if(weig-v[indx][0]>=0)a=f(weig-v[indx][0],indx+1)+v[indx][1];
    b=f(weig,indx+1);
    ans=max(a,b);
    dp[weig][indx]=ans;
    return ans;
}

signed main(){
    FASTER;//ifstream cinn("input.txt");ofstream coutt("output.txt");
    int w;cin>>n>>w;
    for(int i=0;i<n;i++)cin>>v[i][0]>>v[i][1];
    cout<<f(w,0);
}


Measured memory_bytes: 87808
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cstdio>
using namespace std;

//???????????¨
bool lt(const complex<double>& a,const complex<double>& b){
  return a.real()<b.real() || (a.real()==b.real() && a.imag()<b.imag());
}

//??????????¬????????????¢??????????????????????±??????????
double cp(complex<double> a, complex<double> b){
  return (conj(a)*b).imag();
}

int main(){
  int n;
  while(cin >> n && n>0){

    //????????????
    vector<complex<double> > v;
    for(int i=0;i<n;i++){
      double x, y;
      scanf("%lf,%lf",&x,&y);
      v.push_back(complex<double>(x,y));
    }

    //C???R^2??¨???????????????????????§???????????????
    sort(v.begin(),v.end(),lt);

    //??????????????´????????´??????
    vector<complex<double> > u,b;

    //????????????????????§???v.front()??¨v.back()??????????????????????????§?????????
    u.push_back(v[0]);
    int i;
    for(i=0;i<n;i++){
      if(v[i].real()!=v[0].real()) break;
    }
    b.push_back(v[0]);
    b.push_back(v[i]);

    i=i+1;
    while(b.back()!=v.back()){
      b.push_back(v[i]);
      i++;

      int l=b.size();
      if(l<3) continue;
      if(cp(b[l-1]-b[l-2],b[l-3]-b[l-2])>0) continue;
      else{
	b.pop_back();
	b.pop_back();
	i--;
      }
    }

    i=1;
    while(u.back()!=v.back()){
      u.push_back(v[i]);
      i++;

      int l=u.size();
      if(l<3) continue;
      if(cp(u[l-1]-u[l-2],u[l-3]-u[l-2])<0) continue;
      else{
	u.pop_back();
	u.pop_back();
	i--;
      }
    }

    //u.front()==b.front()==v.front(), u.back()==b.back()==v.back()
    //??§???????????????2????????????u,v??§??????????????????
    cout << n-(b.size()+u.size()-2) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3224
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans_list = []

for i in range(n-k):
  if a[i + k] > a[i]:
    ans_list.append('Yes')
  else:
    ans_list.append('No')

for j in range(len(ans_list)):
  print(ans_list[j])

Measured memory_bytes: 31672
#include <iostream>
#define llint long long

using namespace std;

int N;
llint memo[100];

llint calc(int i)
{
	if(memo[i]) return memo[i];
	if(i == 0) return 2;
	if(i == 1) return 1;
	return memo[i] = calc(i-1) + calc(i-2);
}

int main(void)
{
	cin >> N;
	
	cout << calc(N) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  while(cin >>s){
    int f[3][3] = {0},ans = 0;
    for(int i=0; i<9; i++){
      if(s[i] == 'o') f[i%3][i/3] = 1;
      if(s[i] == 'x') f[i%3][i/3] = 2;
    }
    if(f[0][0]!=0){
      if(f[1][0] == f[0][0] && f[2][0] == f[0][0]) ans = f[0][0];
      if(f[0][1] == f[0][0] && f[0][2] == f[0][0]) ans = f[0][0];
      if(f[1][1] == f[0][0] && f[2][2] == f[0][0]) ans = f[0][0];
    }
    if(f[1][1]!=0){
      if(f[0][1] == f[1][1] && f[2][1] == f[1][1]) ans = f[1][1];
      if(f[1][0] == f[1][1] && f[1][2] == f[1][1]) ans = f[1][1];
      if(f[0][2] == f[1][1] && f[2][0] == f[1][1]) ans = f[1][1];
    }
    if(f[2][2]!=0){
      if(f[0][2] == f[2][2] && f[1][2] == f[2][2]) ans = f[2][2];
      if(f[2][0] == f[2][2] && f[2][1] == f[2][2]) ans = f[2][2];
    }
    if(ans == 0) cout <<"d"<<endl;
    else if(ans == 1) cout <<"o"<<endl;
    else cout <<"x"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1172