akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
a = []
n.times do
  t = gets.to_i
  a.push(t)
end
a.sort!
c = 0
b = a[0]
f = false
for e in a do
  if e != b
    if f == true
      c += 1
    end
    b = e
    f = true
  else
    if f == true
      f = false
    else
      f = true
    end
  end
end
if f
  c += 1
end
puts c

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

int main(void)
{
    char s[3];
    char t[3];

    int match = 0;
    int i;

    for(i=0;i<3;i++){
        cin >> s[i];
    }
    for(i=0;i<3;i++){
        cin >> t[i];
    }

    for(i=0;i<3;i++){
        if(s[i] == t[i]){
            match++;
        }
    }

    cout << match << endl;

    return 0;

    



}

Measured memory_bytes: 764
import std.stdio, std.string, std.conv, std.bigint, std.typecons, std.algorithm, std.array, std.math, std.range, std.functional;
 
void main() {
    auto N = readln.chomp.to!long;
    sort(readln.split.to!(long[])).group.filter!(g => g[1] >= 2).array.pipe!((g) {
        if (g.length == 0) return 0;
        if (g[$-1][1] >= 4) return g[$-1][0]^^2;
        if (g.length == 1) return 1;
        return g[$-1][0] * g[$-2][0];
    }).writeln;
}


Measured memory_bytes: 4404
n = int(input())
v = list(map(int, input().split()))
v_odd = []
v_even = []
for i in range(n):
    if i % 2 == 0:
        v_odd.append(v[i])
    else:
        v_even.append(v[i])

        
import collections
cl_odd = collections.Counter(v_odd)
cl_even = collections.Counter(v_even)


if cl_odd.most_common()[0][0] != cl_even.most_common()[0][0]:
    # even, odd列で最頻値が異なる場合
    print(len(v_odd) - cl_odd.most_common()[0][1] +
          len(v_even) - cl_even.most_common()[0][1])

elif cl_odd.most_common()[0][0] == cl_even.most_common()[0][0] and len(cl_odd) == 1 and len(cl_even) == 1:
    print(len(v_odd))

else:
    ans1 = 10**12
    if len(cl_odd) >= 2:
        ans1 = len(v_odd) - cl_odd.most_common()[1][1]
        ans1 += len(v_even) - cl_even.most_common()[0][1]

    ans2 = 10**12
    if len(cl_even) >= 2:
        ans2 = len(v_even) - cl_even.most_common()[1][1]
        ans2 += len(v_odd) - cl_odd.most_common()[0][1]

    print(min(ans1, ans2))


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    ll n, k;
    cin >> n >> k;
    vector <P> x(n);

    for (int i = 0; i < n; i++) {
        cin >> x[i].first >> x[i].second;
    }

    sort(x.begin(), x.end());
    ll now = 0;

    for (int i = 0; i < n; i++) {
        if (now < k) now += x[i].second;
        if (now >= k) {
            cout << x[i].first << endl;
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final long N = sc.nextLong() - 1;
        final int NUM = 26;
        
        StringBuilder str = new StringBuilder();
        str.append((char) ('a' + N % NUM));
        long n = N / NUM;
        
        while (0 < n) {
            str.append((char) ('a' + (n - 1) % NUM));
            n = (n - 1) / NUM;
        }
        
        System.out.println(str.reverse());
    }
}


Measured memory_bytes: 35700
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N,M,X,Y;
int x[101];
int y[101];

int main(){
    cin>>N>>M>>X>>Y;
    rep(i,N) cin>>x[i];
    rep(i,M) cin>>y[i];
    x[N]=X;
    y[M]=Y;

    int xmax=-100100, ymin=100100;
    for(int i=0;i<=N;i++){
        if(x[i]>xmax) xmax=x[i];
    }
    for(int i=0;i<=M;i++){
        if(y[i]<ymin) ymin=y[i];
    }

    if(ymin-xmax>0){
        cout<<"No War"<<endl;
    }else{
        cout<<"War"<<endl;
    }
}

Measured memory_bytes: 256
a=[]
for i in range(2):
    m=input().split()
    a.append(m)

list_1=[int(l) for l in a[0]]
list_2=[int(l) for l in a[1]]
total=0
largest=list_2[0]
smallest=list_2[0]


for x in range(list_1[0]):
    if largest<list_2[x]:
        largest=list_2[x]
    if smallest>list_2[x]:
        smallest=list_2[x]

for x in list_2:
    total+=x

print(smallest,largest,total)

Measured memory_bytes: 8660
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#define ll long long
#define N 300086
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int a[N];
ll sum[N],ans,mx1[N],mn1[N],mx2[N],mn2[N];
int main(){
    int n=read();for(int i=1;i<=n;i++)a[i]=read();
    for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i];
    int pt1=1,pt2=1;mn1[2]=min(a[1],a[2]);mx1[2]=max(a[1],a[2]);
    for(int i=3;i<=n;i++){
        while(pt1<i-1&&sum[i]-sum[pt1+1]>=sum[pt1+1])pt1++;
        while(pt2<i-1&&sum[i]-sum[pt2]>sum[pt2])pt2++;
        if(abs(sum[i]-2*sum[pt1])<=abs(sum[i]-2*sum[pt2])){
            mx1[i]=max(sum[i]-sum[pt1],sum[pt1]);mn1[i]=min(sum[i]-sum[pt1],sum[pt1]);
        }else{
            mx1[i]=max(sum[i]-sum[pt2],sum[pt2]);mn1[i]=min(sum[i]-sum[pt2],sum[pt2]);
        }
    }
    pt1=n;pt2=n;mn2[n-2]=min(a[n],a[n-1]);mx2[n-2]=max(a[n],a[n-1]);
    for(int i=n-3;i;i--){
        while(pt1>i+1&&sum[n]-sum[pt1-1]<=sum[pt1-1]-sum[i])pt1--;
        while(pt2>i+1&&sum[n]-sum[pt2]<sum[pt2]-sum[i])pt2--;
        if(abs(sum[n]-2*sum[pt1]+sum[i])<=abs(sum[n]-2*sum[pt2]+sum[i])){
            mx2[i]=max(sum[n]-sum[pt1],sum[pt1]-sum[i]);mn2[i]=min(sum[n]-sum[pt1],sum[pt1]-sum[i]);
        }else{
            mx2[i]=max(sum[n]-sum[pt2],sum[pt2]-sum[i]);mn2[i]=min(sum[n]-sum[pt2],sum[pt2]-sum[i]);
        }
    }
    ans=0;
    for(int i=2;i<=n-2;i++)if(ans==0)ans=max(mx1[i],mx2[i])-min(mn1[i],mn2[i]);
        else ans=min(ans,(ll)max(mx1[i],mx2[i])-min(mn1[i],mn2[i]));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12288
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = INF;
    rep(i,n) {
        if (i-k+1 < 0) continue;
        int r = i, l = i-k+1;
        int mn = min(abs(x[l]), abs(x[r]));
        int now = x[r]-x[l]+mn;
        ans = min(ans, now);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3748
import java.util.Scanner;

/*
問題文

*/

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();
        long k = sc.nextInt();

        long ans = 0;
        boolean flg = false;
        if (k <= a) {
            ans = k;
            flg = true;
        }

        k = k-a;

        if ( !flg && k <= b) {
            ans = a;
            flg = true;
        }

        k = k-b;

        if (!flg && k-c <= 0) {
            ans = a + (-1 * k);
        }
            System.out.println(ans);
    }
}

Measured memory_bytes: 35784
import java.util.Scanner;

// B - *e**** ********e* *e****e* ****e**
public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	String s = sc.next();
	String[] S = s.split("");
	int K = sc.nextInt();
	String mozi = S[K-1];
	for (int i = 0; i < N; i++) {
		if (!mozi.equals(S[i])) {
			S[i] = "*";
		}
	}

	for (int i = 0; i < N; i++) {
		System.out.print(S[i]);
	}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    int ans = 1;
    int weights = 1;
    n--;
    while (n > 0) {
        int cnt = 0;
        while (weights > cnt * k) {
            cnt++;
        }
        if (n >= cnt) {
            n -= cnt;
            weights += cnt;
            ans++;
        } else {
            break;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3192
x1,y1,x2,y2 = map(int,input().split())
x3 = x2 + (y1 - y2)
y3 = y2 + (x2 - x1)
x4 = x1 + (y1 - y2)
y4 = y1 + (x2 - x1)
print(x3,y3,x4,y4)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll a,b;
	cin>>a>>b;
	if(a>=13){
		cout << b;
	}
	else if(a<=5){
		cout << 0;
	}
	else{
		cout << b/2;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3600
'use strict'

const INF = 900719925474099;
function mapint(temp){
    return temp.split(' ').map((v)=>parseInt(v));
}

function lower_bound(d,a,b,e){
    for(var c;1<b-a;)
        d[c=0|(a+b)/2]<e ? a=c : b=c;
    return d[a]<e?b:a
};

const MOD = 1000000007;

function Main(input){
    let s = input.trim();
    let f = false;

    if(s[0]==s[1]) if(s[2]==s[3]) if(s[0]!=s[2]) f=true;
    if(s[0]==s[2]) if(s[1]==s[3]) if(s[0]!=s[1]) f=true;
    if(s[0]==s[3]) if(s[1]==s[2]) if(s[0]!=s[1]) f=true;

    if(f) console.log('Yes');
    else console.log('No');

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    ll n,m,R;
    cin >> n >> m >> R;
    vector<ll> r(R);
    rep0(i, R){
        cin >> r[i];
        --r[i];
    }
    sort(all(r));
    ll g[n][n];
    rep0(i, n)rep0(j, n)g[i][j] = 1e9;
    rep0(i, m){
        ll a,b,c;
        cin >> a >> b >> c;
        --a;
        --b;
        g[a][b] = c;
        g[b][a] = c;
    }
    rep0(k, n)rep0(i, n)rep0(j, n)g[i][j] = min(g[i][j],g[i][k] + g[k][j]);
    ll ans = 1e9;
    do {
        ll cnt = 0;
        rep0(i, R - 1)cnt += g[r[i]][r[i + 1]];
        ans = min(ans,cnt);
    } while (next_permutation(all(r)));
    pf(ans);
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static int[][] map;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext()) {
			int counter = 0;
			map = new int[12][12];
			for(int i = 0; i < 12; i++) {
				 String tmp = stdIn.next();
				for(int j = 0; j < 12; j++) {
					map[i][j] = Integer.parseInt(String.valueOf(tmp.charAt(j)));
				}
			}
			for(int i = 0; i < 12; i++) {
				for(int j = 0; j < 12; j++) {
					if(map[i][j] == 1) {
						counter++;
						check(i,j);
					}
				}
			}
			System.out.println(counter);
		}
		

	}
	
	public static void check(int x, int y) {
		if(x < 0 || x > 11 || y < 0 || y > 11 || map[x][y] == 0 ) {
			return;
		}
		map[x][y] = 0;
		check(x+1,y);
		check(x-1,y);
		check(x,y+1);
		check(x,y-1);
	}

}

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

string int2string(int n)
{
	string res;
	while(n!=0){
		res+=(n%10)+'0';
		n=n/10;
	}
	reverse(res.begin(),res.end());
	return res;
}


int main(){
	int N;
	int i,j,k;
	while(1){
	cin >> N;
		if(N==0){
			return 0;
		}
	string A;
	cin >> A;
	for(i=0;i<N;i++){
		string tmp;
		k=0;
		for(j=0;j<A.size();j++){
			if(A[j]==A[j+1]){
				k++;
			}else{
				tmp+=int2string(k+1);
				tmp+=A[j];
				k=0;
			}
		}
		// tmp ?????????????????????????????\??????
		A = tmp;
	}
	cout << A << endl;
	}
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////
int n,m;

int halflcm(int aa,int bb){
  int counta=0,countb=0;
  int a=aa,b=bb;
  while(a%2==0){
    a/=2;
    counta++;
  }
  while(b%2==0){
    b/=2;
    countb++;
  }
  if(counta==countb)return lcm(aa,bb)/2;
  return m+1;
}
signed main() {
  
  cin>>n>>m;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  int kousa=a[0],minhalflcm=a[0]/2;
  rep(i,n-1){
    kousa=lcm(kousa,a[i+1]);
    minhalflcm=halflcm(minhalflcm*2,a[i+1]);
    if(minhalflcm>m){cout<<0<<endl;exit(0);}
  }
  if(m>=minhalflcm)cout<<(m-minhalflcm)/kousa+1<<endl;
  else cout<<0<<endl;
}


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

int main()
{
	int N, P[30];
	cin >> N;
	
	for (int i = 0; i < N; i++)
	{
		cin >> P[i];
	}

	int ans = 0;

	for (int i = 1; i < N - 1; i++)
	{
		if ((P[i - 1] < P[i]) && (P[i] < P[i + 1]))
		{
			ans++;
		}

		else if ((P[i - 1] > P[i]) && (P[i] > P[i + 1]))
		{
			ans++;
		}
	}

	cout << ans;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}
string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k;
    cin>>n;
    string s;
    vector<string> v;
    vector<string> w;
    map<string,int> m;
    for (int i=0;i<n;++i)
    {
        cin>>s;
        if (!m[s])
        {
            v.push_back(s);
        }
        ++m[s];
    }
    w.push_back(v[0]);k=m[v[0]];
    for (int i=1;i<sz(v);++i)
    {
        if (m[v[i]]>k)
        {
            k=m[v[i]];
            w.clear();
            w.push_back(v[i]);
        }
        else if (m[v[i]]==k)
        {
            w.push_back(v[i]);
        }
    }
    sort(w.begin(), w.end());
    for (int i=0;i<sz(w);++i)
    {
        cout<<w[i]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 27120
n = gets.to_i
a = gets.split(' ').map(&:to_i)
if a.include?(1) != true
  puts '-1'
  exit
end

j = 1
count = 0
a.each do |i|
  if i == j
    j += 1
  else
    count += 1
  end
end
puts count

Measured memory_bytes: 15364
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        a = a^b;
        b = a^b;
        a = a^b;
    }
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }
    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

 //118
 /*
void solve(void){
   int a,b;
   cin >> a >> b;
   if(b%a == 0) cout << a+b <<endl;
   else cout << b-a<<endl;
}
*/ 
/*
void solve(void){
    int n,m;
    cin >> n >> m;
    int k;
    int num[m+1];
    rep(i,0,m+1) num[i] = 0;
    rep(i,0,n){
        cin >> k;
        rep(j,0,k){
            int a;
            cin >> a;
            num[a]++;
        }
    }
    int ans = 0;
    rep(i,0,m+1){
        if(num[i] == n) ans++;
    }
    cout << ans << endl;
}
*/

void solve(void){
    ll n;
    cin >> n;
    ll a[n];
    rep(i,0,n) cin >> a[i];
    ll d;
    d = gcd(a[0],a[1]);
    rep(i,2,n){
        d = gcd(a[i],d);
    }
    cout << d << endl;
}

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

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

template <typename F>
inline constexpr decltype(auto) fix(F&& f) noexcept {
    return [=](auto g) {
        return [=](auto&&... args) {
            return f(g(g), std::forward<decltype(args)>(args)...);
        };
    }([=](auto g) {
        return [=](auto&&... args) {
            return f(g(g), std::forward<decltype(args)>(args)...);
        };
    });
}

void solve() {
    ll N;
    cin >> N;
    using Graph = vector<Vi>;
    Graph g(N);
    for (ll i = 0; i < N - 1; i++) {
        int a;
        cin >> a;
        --a;
        g[a].emplace_back(i + 1);
    }

    Vl dp(N, -1);

    auto dfs = [&](auto&& self, int idx) -> void {
        if ((ll)g[idx].size() == 0) {
            dp[idx] = 0;
            return;
        }

        for (const auto& u : g[idx]) {
            self(u);
        }

        ll nchd = (ll)g[idx].size();
        vector<Pll> vec(nchd);
        for (ll i = 0; i < nchd; i++) {
            vec[i] = {dp[g[idx][i]], g[idx][i]};
        }
        sort(vec.begin(), vec.end(), greater<Pll>());

        ll val = 0;
        for (ll i = 0; i < nchd; i++) {
            auto [c, u] = vec[i];
            val = max(val, c + i + 1);
        }

        dp[idx] = val;
    };

    fix(dfs)(0);

    cout << dp[0] << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 23516
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n)  for (int i = 0; i < (int) (n); i++)
#define Rrep(i, n) for (int i = ((int) n - 1); i >= 0; i--)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
#define INF 2e15
#define MOD 10e9 + 7

typedef vector <int> vint;
typedef long long    ll;

ll  dp[3100][3100][4];
int w[3100][3100];

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    rep(i, 3100) {
        rep(j, 3100) {
            rep(k, 4) {
                dp[i][j][k] = 0;
            }
            w[i][j] = 0;
        }
    }

    int R, C, K;
    cin >> R >> C >> K;

    rep(i, K) {
        int r, c, v;
        cin >> r >> c >> v;
        w[r - 1][c - 1] = v;
    }

    rep(i, R) {
        rep(j, C) {
            for (int k = 2; k >= 0; k--) { // 拾うか拾わないか
                dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + w[i][j]);
            }
            rep(k, 4) {
                dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
                dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
            }
        }
    }
    ll ans = 0;
    rep(k, 4) ans = max(ans, dp[R - 1][C - 1][k]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 341496
# coding: utf-8
# Your code here!

import math
a, b, C = map(float,input().split())

S = (1/2)*a*b*math.sin(math.radians(C))
L = (a**2+b**2 - 2*a*b*math.cos(math.radians(C)))**(1/2) + a + b
h = 2*S/a

print(S,L,h, sep="\n")


Measured memory_bytes: 5712
#include <stdio.h>
int main(){
  int A,B,C,n1;
  scanf("%d%d%d",&A,&B,&C);
  if(A<=C&&B<=C){
    n1=10*C+A+B;
  }else if(A<=B&&C<=B){
    n1=10*B+A+C;
  }else{
    n1=10*A+B+C;
}
  printf("%d",n1);
  return 0;
}


Measured memory_bytes: 128
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto S = RD!string;
	string ans;
	foreach (c; S)
	{
		if (c == 'B')
		{
			if (ans.length != 0)
				ans.popBack;
		}
		else
			ans ~= c;
	}
	
	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0, x = 0, y = 0, z = 0,n=0,m=0, maxy = 0, mini = 9999, counter = 0, s = 0, endp = 0, checker = 0;
std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[100001];
long long int iremono2[100001],check[100001];
std::vector<unsigned long long int>kinds{}, ans{}, kaku{};
char moji, moji2;
bool okada = false, okada2 = false;
std::string output, output2, input, one, two;
char rev[100001];
unsigned long long int kakunou2[101][101] = {};
unsigned long long int M, A, R, C, H;

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}
int main()
{
	cin >> a >> b;
	cin >> input;
	for (int i = 1; i <= input.size(); i++) {
		check[i] = x;
	
		if (input[i - 1] == 'A'&&input[i] == 'C') {
			x++;
		}
	
	}

	rep(i, b) {
		cin >> iremono[i]>>iremono2[i];
	}
	rep(i, b) {
		cout << check[iremono2[i]] - check[iremono[i]]  << endl;;
	}
}

Measured memory_bytes: 3456
import collections
N = int(input())
xy_array = [list(map(int, input().split())) for i in range(N)]
if N == 1:
    print(1)
    exit()
# print(xy_array)
distance_array = []
for i in range(N):
    x_i, y_i = xy_array[i]
    for j in range(N):
        if i == j:
            continue
        x_j, y_j = xy_array[j]
        distance_array.append((x_i - x_j, y_i - y_j))

ans_array = collections.Counter(distance_array)
max_count = ans_array.most_common()[0][1]
print(N - max_count)


Measured memory_bytes: 40944
#include<cstdio>
#include<cctype>
int main()
{
	char ch;
	while(1)
	{
		scanf("%c", &ch);
		if( isalpha(ch) )
		{
			if( islower(ch) ) printf("%c", toupper(ch));
			else printf("%c", tolower(ch));
		}
		else printf("%c", ch);
	if ( ch == '\n' )break;
	}
	return 0;
}

Measured memory_bytes: 944
from collections import deque
N,Q = (int(x) for x in input().split())
connected = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append(b)
    connected[b-1].append(a)
counter = [0] * N
for _ in range(Q):
    p,x = (int(y) for y in input().split())
    counter[p-1] += x
ans = counter
q = deque([(1,0)])
searched = [0] * N
while q:
    a,p = q.popleft()
    if p != 0:
        ans[a-1] += ans[p-1]
    searched[a-1] = 1
    for child in connected[a-1]:
        if searched[child-1] == 0:
            q.append((child,a))
print(*ans)

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

int main(){
  string str;
  cin >> str;
  bool odd = true;
  bool even = true;
  for(int i=0; i<str.length(); i++){
    if((i+1) % 2 == 1){
      if(str[i] == 'L'){
        odd = false;
      }
    }else{
      if(str[i] == 'R'){
        even = false;
      }
    }
  }
  if(odd && even) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
#define pi 3.1415926

int a[3];

int main(){
    int p, q, r;
    cin >> p >> q >> r;
    cout << min(p + q, min(q + r, r + p));
}

    

	


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,i,j,minj,tmp,count=0;
    int A[100];

    scanf("%d",&n);
    for(i = 0; i < n; ++i)
        scanf("%d",&A[i]);

        for(i = 0; i < n; ++i){
            minj = i;
            for(j = i; j < n; j++){
                if(A[j] < A[minj]){
                    minj = j;   
                }
            } 
             if(minj != i){ 
                tmp = A[i];
                A[i] = A[minj];
                A[minj] = tmp; 
                count++; 
             }     
        }
    for(i =0; i < n; ++i){
        printf("%d",A[i]);
        if(i < n-1)
        printf(" ");
    }
    printf("\n");
    printf("%d\n",count);
    return 0;
}


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

int main(){
	int a,b,c;
  string s;
  
  cin >> a >> b;
  c = a*b;
  
  if(c % 2 ==0){
    cout << "Even" << endl;
  }else{
    cout << "Odd" << endl;
  }
  
  
  
}

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

#define ALL(obj) (obj).begin(),(obj).end()
template<class T> using priority_queue_reverse = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = 1'000'000'000LL + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
vector<string> split(const string &str, const char delemiter) {vector<string> res;stringstream ss(str);string buffer; while( getline(ss, buffer, delemiter) ) res.push_back(buffer); return res;}
int msb(int x) {return x?31-__builtin_clz(x):-1;}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string S; cin >> S;
    ll ans = 0;
    for(int i = 0; i < S.size(); ++i) {
        ans += (S[i]-'0');
        ans %= 9;
    }
    Yn(ans%9==0);
    return 0;
}


Measured memory_bytes: 3752
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int X = s.nextInt();
		int N = s.nextInt();
		int[] p = new int[N];
		for(int i=0; i<N; i++) {
			p[i] = s.nextInt();
		}
		Arrays.sort(p); //昇順にソート
		int i_X =-1; //p[i] = X を満たす整数i
		boolean existX = false;
		for(int i =0; i<N; i++) {
			if(p[i] == X ) {existX = true; i_X = i; break;}
		}

		int ans=0;
		int sumP =0;
		for(int i=0; i<N; i++) {
			sumP += p[i];
		}
		
		if(!existX) {ans = X; }
		else if(sumP == (N*(p[N-1]+p[0]))/2 ) { 
			if(X-p[0] <= p[N-1]-X) {ans = p[0]-1;}
			else {ans = p[N-1]+1;}
		}
		else { boolean da = false;
			for(int k=1; k<=i_X && k<=N-1-i_X; k++ ) {

				  if(p[i_X-k] !=  p[i_X]-k) {ans =p[i_X]-k;  da = true; break;}
				  else if(p[i_X+k] !=  p[i_X]+k) {ans =p[i_X]+k; da = true; break;}
				}
			if(!da) {
				if(X-p[0] <= p[N-1]-X) {ans = 9;}
					else {ans = 9; }	
				
			}
		
		}
		
		System.out.println(ans);
	}

}

Measured memory_bytes: 35908
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
        if (fopen("INPUT.txt", "r")) 
        {
            freopen ("INPUT.txt" , "r" , stdin);
            freopen ("OUTPUT.txt" , "w" , stdout);
        }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

        READV(A);
    READV(H);
    cout<<(A+H-1)/H<<endl;
 

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 256
// Frog 2 https://a...content-available-to-author-only...r.jp/contests/dp/tasks/dp_b
#include <bits/stdc++.h>
using namespace std;
 
const int INF = 1e9 + 5;
 
int n, k;
vector<int> h;
vector<int> memo;
vector<bool> computed;
 
// rec(x) is best score to get to position x
int rec(int pos) {
	if(pos == 0) {
		return 0;
	}
	if(computed[pos]) {
		return memo[pos];
	}
	int best = INF;
	for(int jump = 1; jump <= k && pos - jump >= 0; ++jump) {
		best = min(best, rec(pos - jump) + abs(h[pos] - h[pos-jump]));
	}
	computed[pos] = true;
	return memo[pos] = best;
}
 
int solve1() {
	return rec(n-1);
}
 
int solve2() { // pull dp
	vector<int> dp(n);
	for(int i = 1; i < n; i++) {
		dp[i] = INF; // and now compute dp[i]
		for(int jump = 1; jump <= k && i - jump >= 0; ++jump) {
			dp[i] = min(dp[i], dp[i-jump] + abs(h[i]-h[i-jump]));
		}
	}
	return dp[n-1];
}
 
void min_self(int& a, int b) {
	a = min(a, b);
}
 
int solve3() { // push dp
	vector<int> dp(n, INF);
	dp[0] = 0;
	for(int i = 0; i <= n - 2; ++i) {
		for(int jump = 1; jump <= k && i + jump < n; ++jump) {
			min_self(dp[i+jump], dp[i] + abs(h[i]-h[i+jump]));
		}
	}
	return dp[n-1];
}
 
const int B = 16 * 1024; // greater than 10,000
struct Tree {
	vector<int> a;
	vector<multiset<int>> values_in_leaves;
	void init() {
		a.resize(2*B, INF);
		values_in_leaves.resize(B);
		for(int i = 0; i < B; ++i) {
			values_in_leaves[i].insert(INF);
		}
	}
	int query_min(int L, int R) {
		if(L > R) {
			return INF;
		}
		L += B;
		R += B;
		int x = min(a[L], a[R]);
		while(L + 1 < R) {
			min_self(x, a[L+1]);
			min_self(x, a[R-1]);
			L /= 2;
			R /= 2;
		}
		return x;
	}
	void insert(int i, int value) {
		values_in_leaves[i].insert(value);
		a[i+B] = *values_in_leaves[i].begin();
		for(int j = (i + B) / 2; j >= 1; j /= 2) {
			a[j] = min(a[2*j], a[2*j+1]);
		}
	}
	void erase(int i, int value) {
		values_in_leaves[i].erase(values_in_leaves[i].find(value));
		a[i+B] = *values_in_leaves[i].begin();
		for(int j = (i + B) / 2; j >= 1; j /= 2) {
			a[j] = min(a[2*j], a[2*j+1]);
		}
	}
};
Tree sum, diff;
 
void insert(int i, const vector<int>& dp) {
	sum.insert(h[i], dp[i] + h[i]);
	diff.insert(h[i], dp[i] - h[i]);
}
void erase(int i, const vector<int>& dp) {
	sum.erase(h[i], dp[i] + h[i]);
	diff.erase(h[i], dp[i] - h[i]);
}
 
int solve4() { // pull dp with segment trees
	vector<int> dp(n);
 
	// O(N * log(H))
	for(int i = 1; i < n; ++i) {
		insert(i-1, dp);
		if(i - k - 1 >= 0) {
			erase(i-k-1, dp);
		}
		// [i-k, i-1]
		dp[i] = INF;
 
		min_self(dp[i], diff.query_min(0, h[i]) + h[i]);
		min_self(dp[i], sum.query_min(h[i]+1, 10 * 1000) - h[i]);
	}
	return dp[n-1];
}
 
int main() {
	sum.init();
	diff.init();
	cin >> n >> k;
	h.resize(n);
	memo.resize(n, 0);
	computed.resize(n, false);
	for(int& x : h) {
		cin >> x;
	}
	cout << solve4();
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;
  int n = s.length();

  vector<vector<int>> next(26, vector<int>(n + 1, n));
  for (int c = 0; c < 26; c++) {
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == c + 'a') {
        next[c][i] = i;
      } else {
        next[c][i] = next[c][i + 1];
      }
    }
  }

  vector<int> jump(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      jump[i] = max(jump[i], next[j][i]);
    }
  }
  vector<int> dp(n + 2);
  for (int i = n - 1; i >= 0; i--) {
    if (jump[i] < n) {
      dp[i] = dp[jump[i] + 1] + 1;
    }
  }
  
  int L = dp[0], pos = 0;
  vector<int> ans(L);
  for (int i = 0; i < L; i++) {
    for (int j = 0; j < 26; j++) {
      if (dp[next[j][pos] + 1] < L - i) {
        ans[i] = j;
        pos = next[j][pos] + 1;
        break;
      }
    }
  }
  for (auto i : ans) {
    cout << char(i + 'a');
  }

  vector<bool> visit(26);
  for (int i = pos; i < n; i++) {
    visit[s[i] - 'a'] = true;
  }
  for (int i = 0; i < 26; i++) {
    if (!visit[i]) {
      cout << char(i + 'a') << '\n';
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 25456
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

int m[100][100];
int dp[101][101];

int main() {
    int H, W;
    char c;
    cin >> H >> W;
    rep(i, H) {
        rep(j, W) {
            cin >> c;
            m[i][j]  = c == '#' ? 1 : 0;
            dp[i][j] = 0;
        }
    }

    for(int i=1; i<W; ++i) {
        dp[0][i] += dp[0][i-1];
        if(m[0][i-1] == 0 && m[0][i] == 1) {
            dp[0][i]++;
        }
    }

    for(int i=1; i<H; ++i) {
        dp[i][0] += dp[i-1][0];
        if(m[i-1][0] == 0 && m[i][0] == 1) {
            dp[i][0]++;
        }
    }

    for(int i=1; i<H; ++i) {
        for(int j=1; j<W; ++j) {
            int cand1 = dp[i-1][j];
            int cand2 = dp[i][j-1];
            if(m[i-1][j] == 0 && m[i][j] == 1)
                cand1++;
            if(m[i][j-1] == 0 && m[i][j] == 1)
                cand2++;
            dp[i][j] = min(cand1, cand2);
        }
    }

#if 0
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            printf("%03d ", dp[i][j]);
        }
        printf("\n");
    }
#endif
    int ret = dp[H-1][W-1];
    if(m[0][0] ==1)
        ret++;
    cout << ret << endl;

    return 0;
}



Measured memory_bytes: 3228
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n,a,b;
	cin >> n >> a >> b;
	cout << min(a,b) << " " << ((a+b)>n?a+b-n:0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
signed main(){
  int a,b,c;
  cin>>a>>b;
  if(a<=5){
    cout<<"0\n";
  }
  else{
    if(a>=6 && a<=12){
      cout<<b/2<<"\n";
    }
    else{
      cout<<b<<"\n";
    }
  }
  return(0);
}


Measured memory_bytes: 256
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()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n:usize = read();
    let an = read_vec::<i64>();
    let bn = read_vec::<i64>();
    let mut ans = 0 as i64;
    for j in 0..n { 
        let now_point = an.iter().take(j+1).fold(0,|y,x| y + x) + bn.iter().skip(j).fold(0,|y,x| y + x);
        ans = std::cmp::max(ans,now_point);
    }
    println!("{}",ans);
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{
    int A, B, C, D;
    scanf("%d %d %d %d", &A, &B, &C, &D);

    while(1) {
        C -= B;
        if (C <= 0) {
            printf("Yes\n");
            return 0;
        }
        A -= D;
        if (A <= 0) {
            printf("No\n");
            return 0;
        }
    }

}

Measured memory_bytes: 2088
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

int i,j,k,N,M,s[11],c[11],ans,fact[5];

int main()
{
  cin>>N>>M;
  
  for(i=0;i<M;i++)
  {
    cin>>s[i]>>c[i];
  }
  
  if(N>1)
  {
    for(i=0;i<M;i++)
    {
      if(s[i]==1 && c[i]==0)
      {
        cout << -1;
        
        return 0;
      }
    }
    
  }
  
  for(i=0;i<M;i++)
  {
    for(j=i+1;j<M;j++)
    {
      if(s[i]==s[j] && c[i]!=c[j])
      {
        cout << -1;
        
        return 0;
      }     
      
      if(s[i]==s[j] && c[i]==c[j])
      {
        c[j]=0;
      }
      
    }
  }
  
  ans=0;
  fact[0]=1;
  fact[1]=10;
  fact[2]=100;
  
  for(i=0;i<M;i++)
  {
    ans+=fact[N-s[i]]*c[i];
    
  }
  
  if(N==3 && ans<100)
  {
    ans+=100;
  }
  else if(N==2 && ans<10)
  {
    ans+=10;
  }
  
  cout <<ans;
  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n[3], a[8000], m, l, p;
int main() {
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	n[0] = 1000000000;
	n[1] = 1000000000;
	n[2] = 1000000000;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			if (i != j) {
				if (a[j] < 10) { l = 10; }
				else if (a[j] < 100) { l = 100; }
				else if (a[j] < 1000) { l = 1000; }
				else if (a[j] < 10000) { l = 10000; }
				else { l = 100000; }
				p = a[i] * l + a[j];
				if (n[0] > p) {
					n[2] = n[1];
					n[1] = n[0];
					n[0] = p;
				}
				else if (n[1] > p) {
					n[2] = n[1];
					n[1] = p;
				}
				else if (n[2] > p) {
					n[2] = p;
				}
			}
		}
	}
	cout << n[2] << endl;
	return 0;
}

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

int main(){
    int n; cin >> n;
    vector<double> x(n);
    vector<double> y(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) cin >> y[i];    
    double p1 = 0, p2 = 0, p3 = 0, pinf = 0;
    for (int i = 0; i < n; i++) p1 += abs(x[i]-y[i]);
    for (int i = 0; i < n; i++) p2 += (x[i]-y[i])*(x[i]-y[i]);
    p2 = sqrt(p2);
    for (int i = 0; i < n; i++) p3 += abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
    p3 = cbrt(p3);
    for (int i = 0; i < n; i++) pinf = max(pinf, abs(x[i]-y[i]));
    cout << fixed << setprecision(5);
    cout << p1 << endl;
    cout << p2 << endl;
    cout << p3 << endl;
    cout << pinf << endl;
    return 0;
}


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

using namespace std;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int ma = (n - 1) * (n - 2) / 2;
  if (ma < k) {
    cout << -1 << endl;
    return 0;
  }

  vector< pair<int, int> > ans;
  for (int i = 0; i < n - 1; ++i) {
    ans.push_back(make_pair(i + 1, n));
  }
  cerr << "ma: " << ma << endl;
  cerr << "ans size: " << ans.size() << endl;
  int add = ma - k;
  vector< pair<int, int> > edge;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j < i; ++j) {
      edge.push_back(make_pair(i + 1, j + 1));
    }
  }
  for (int i = 0; i < add; ++i) ans.push_back(edge[i]);
  cout << ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); ++i) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}



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


int main(){
    int n_1, n_2, n_3, n_4;cin>>n_1>>n_2>>n_3>>n_4;
    vector<int> nums{n_1, n_2, n_3, n_4};

    sort(nums.begin(), nums.end());
    vector<int> expected{1, 4, 7, 9};
    bool judge = true;

    for (int i=0;i<4;i++){
        if (nums[i] != expected[i]){
            judge = false;
            break;
        }
    }
    if (judge){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
    
}


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

int main()
{
    int n,ans=0;
    long double d,x,y;

    cin>>n>>d;

    while(n--){
        cin>>x>>y;

        if(sqrt(x*x+y*y)<=d){
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3844
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
VV gragh;
ll dfs(ll x){
    if(gragh[x].size()==0){
        return 0;
    }
    ll Max=0;
    ll Min = 1e18;
    rep(i,gragh[x].size()){
        chmax(Max, dfs(gragh[x][i]));
        chmin(Min, dfs(gragh[x][i]));
    }
    return Max + Min + 1;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    if(k%2==1){
        ll f = n / k;
        cout << f * f * f << endl;
    }else{
        ll f = n / k;
        ll g=0;
        if(n>=k/2){
            g=(n-k/2)/k+1;
        }
        cout << f * f * f+g*g*g << endl;
        
    }
}


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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    int n, r; cin >> n >> r;
    int ans = r;
    if (n < 10) ans += 100 * (10 - n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256