akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

//集合を表すデータ構造、根は大きさを負で持ち、子は根を正で持つ
//[0]に全体の集合の数を入れる
//swapを使用するため<utility>をインクルードする
struct UnionFind{
    vector<int>data;
    UnionFind(int size) :   data(size+1, -1){
        data[0] = size;
    }

    //集合のmerge
    //すでに同じならfalse
    bool merge(int x, int y){
        x = root(x);    y = root(y);
        if(x == y)  return false;
        //要素数の少ない方を多い方に繋げる
        if(data[y] < data[x])   swap(x, y);
        data[x] += data[y];
        data[y] = x;
        data[0]--;
        return true;
    }

    //どの集合に属しているか
    int root(int x){
        //根に繋ぎ直す
        return (data[x] < 0) ? x : (data[x] = root(data[x]));
    }

    //ある要素が属する集合の大きさ
    int size(int x){
        return -data[root(x)];
    }

    //集合の数
    int set(){
        return data[0];
    }
};

int main(){
    int n, m;   cin >> n >> m;
    UnionFind uf(n);
    rep(i, m){
        int a, b;   cin >> a >> b;
        uf.merge(a, b);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) ans = max(ans, uf.size(i));
    cout << ans << endl;
}


Measured memory_bytes: 4036
h, w = map(int, input().split())
 
if h == 1 or w == 1:
	print(1)
    
elif h % 2 == 1 and w % 2 == 1:
	print((h - 1) * w // 2 + (w+1) // 2 )
else:
	print(h*w//2)
	

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

#define rep(i, a, b) for(int i = a; i <= (b); ++i)
#define per(i, b, a) for(int i = b; i >= (a); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define F first 
#define S second 
#define boost ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define M (1000*1000*1000+7)
#define inf (2*1000*1000*1000+9)
#define infl ((ll)2*1000*1000*1000*1000*1000*1000+9)
#define debug1(a) cout<<#a<<" = " <<a<<endl; 
#define debug2(a,b) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<endl; 
#define debug3(a,b,c) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<endl; 
#define debug4(a,b,c,d) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<" , "<<#d<<" = " <<d<<endl; 
  
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll; 
typedef vector< pair<int,int> > vpii;

/* -------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------*/


bool cmp(pii a , pii b){
	return a.first+a.second<b.first+b.second; 
}

void solve(){
	int n; cin>>n; 
	vpii v(n); 
	rep(i,0,n-1){
		int h,p; cin>>h>>p; v[i]={h,p}; 
	}
	sort(all(v),cmp);
	vector<vll> dp(n); 
	rep(i,0,n-1){
		dp[i]=vll(i+1,infl); 
		rep(j,0,i){
			if(i==0){ dp[i][j]=v[i].second; }
			else{
				if(j==0){
					dp[i][j]=min(dp[i-1][j],(ll)v[i].second); 
				}
				else{
					if(j<i) dp[i][j]=dp[i-1][j]; 
					if(v[i].first>=dp[i-1][j-1]){
						dp[i][j]=min(dp[i][j],dp[i-1][j-1]+v[i].second); 
					}	
				}
			}
		}
	}
	int ans=0; 
	rep(i,0,n-1){
		if(dp[n-1][i]<infl)
			ans=max(ans,i+1); 
	}
	cout<<ans<<endl ;
}


int main() {
  clock_t beg=clock(); 
  boost;
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
  clock_t end=clock(); 
  fprintf(stderr, "%lf\n", (double)(end-beg)/CLOCKS_PER_SEC);
}


Measured memory_bytes: 98176
A = []
B = []
for i in range(5):
    n = int(input())
    B.append(n)
    tmp = -(-n//10)*10
    A.append(tmp)

C = []
for j in range(5):
    tmp = A[j] - B[j]
    C.append(tmp)
L = max(C)

print(sum(A)-L)

Measured memory_bytes: 3064
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  i64 a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  a = abs(a - b);
  kek(v * t - w * t >= a ? "YES" : "NO");
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>	
using namespace std;
#define anuj ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define ll long long int
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%I64d",&x)
#define ss(s)	scanf("%s",s)
#define all(v)  sort(v.begin(),v.end())
#define rall(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl '\n'
typedef pair<int, int>	pii;
typedef vector<int>		vi;
typedef vector<pii>		vpii;
typedef vector<vi>		vvi;
const int mod = 1000000007;
const int N = 2e5+5;
const int LG = 20;
int a[N];

int32_t main(){
	anuj;
	// #ifndef ONLINE_JUDGE
 //    freopen("inputf.txt", "r", stdin);
 //    freopen("outputf.txt", "w", stdout);
	// #endif

	int n,W;
	cin >> n >> W;

	vi value(n),weight(n);
	fo(i,n){
		cin >> weight[i] >> value[i];
	}

	int dp[n+1][W+1];
	memset(dp,0,sizeof(dp));

	for(int item=1;item<=n;item++){
		for(int C=1;C<=W;C++){
			dp[item][C]=dp[item-1][C];
			if(weight[item-1]<=C) dp[item][C]=max(dp[item][C],dp[item-1][C-weight[item-1]]+value[item-1]);
		}
	}

	cout << dp[n][W];
}

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

#define ll long long

int main(){

    ll a, b;
    cin >> a >> b;

    ll d, r;
    double f;
    
    d = a / b;
    r = a % b;
    f = double(a) / double(b);

    cout << d << " " << r << " ";
    printf("%.5lf\n",f);

    return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>H>>W;
    --H;
    --W;
    cout<<H*W<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	ls         []int
	n, a, b, c int
	ans        = 1 << 60
)

func dfs(i, curA, curB, curC, cost int) {
	if i == n {
		if (curA != 0) && (curB != 0) && (curC != 0) {
			tmp := cost + abs(a-curA) + abs(b-curB) + abs(c-curC)
			ans = min(ans, tmp)
		}
		return
	}

	dfs(i+1, curA, curB, curC, cost)
	dfs(i+1, curA+ls[i], curB, curC, cost+10)
	dfs(i+1, curA, curB+ls[i], curC, cost+10)
	dfs(i+1, curA, curB, curC+ls[i], cost+10)
}

func main() {
	n, a, b, c = getInt(), getInt(), getInt(), getInt()

	ls = make([]int, n)
	for i := range ls {
		ls[i] = getInt()
	}

	dfs(0, 0, 0, 0, -30)

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 640
r=lambda x:x if u[x]<0else r(u[x])
(n,m),_,*e=[map(int,t.split())for t in open(0).readlines()]
u=[-1]*-~n
t=n*~-n//2
a=[t]
for x,y in e[::-1]:
 x,y=sorted((r(x),r(y)))
 if x!=y:t-=u[x]*u[y];u[x]+=u[y];u[y]=x
 a+=[t]
print(*a[::-1],sep='\n')

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

n = int(input())
path = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    path[a].append(b)
    path[b].append(a)
parent = [-1]*n
size = [1]*n
d = [0]*n
def dfs(now):
    for nxt in path[now]:
        if nxt != parent[now]:
            parent[nxt] = now
            d[nxt] = d[now] + 1
            size[now] += dfs(nxt)
    return size[now]
dfs(0)
cnt = 0
now = n-1
for i in range((d[n-1]+1)//2 - 1):
    now = parent[now]
if size[now] >= n - size[now]:
    print('Snuke')
else:
    print('Fennec')


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

using namespace std;

int main(int argc, char const *argv[])
{
    int N, K, t;
    cin >> N >> K;
    vector<int>  v;
    for (int i=0; i<N; i++) {
        cin >> t;
        v.push_back(t);
    }
    sort(v.begin(), v.end(), greater<int>());
    int sum = 0;
    for (int i=0; i<K; i++) {
        sum += v[i];
    }
    cout << sum << endl;
    return 0;
}
	


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int n,m,a[100005];
int Gcd(int a,int b){
	if (a%b==0) return b; else return Gcd(b,a%b);
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	int g,g2;
	cin>>a[0];
	g=a[0];
	for (int i=1;i<n;i++){
		cin>>a[i];
		g2=a[i];
		g=Gcd(g,g2);
	}
	for (int j=0;j<n;j++){
		if ((a[j]-m)>=0 && (a[j]-m)%g==0){
			cout<<"POSSIBLE";
			return 0;
		}
	}
	cout<<"IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    long N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    int ans = 0;
    bool isOdd = false;
    for(int i=0; i<=log2(pow(10,9)); i++){
        for(int j=0; j<N; j++){
            if(A[j]%2!=0) isOdd=true;
        }
        if(isOdd) break;
        for(int j=0; j<N; j++){
            A[j] /= 2;
        }
        ans += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()


using namespace std;

const ll N = 10020;
const ll big = 1e18;
const ll M = 2020;
const ll mod = 998244353;

ll a, b;

int main() {
    speed;
	cin >> a >> b;
	ll otr = max(-a ,0ll);
	ll otrb = max(-(b + 1), 0ll);	
	otr -= otrb;
	if(a < 0 && b > 0)
		cout << "Zero\n";
	else if(otr % 2)
		cout << "Negative\n";
	else
		cout << "Positive\n";
}

/*
*/



Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Feb 22 21:00:01 JST 2020
 **/

signed main() {
    Int n, k;
    cin >> n >> k;
    Int ans = 0;
    while (n) {
        n /= k;
        ans++;
    }
    cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ans;
    ans=abs(a[1]-a[0]);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            ans=max(abs(a[i]-a[j]),ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin >> n;
  map<string,int> memo;
  rep(i,n){
    string s; cin >> s;
    memo[s]+=1;
  }
  int maxv = 0;
  for(auto x:memo){
    int v = x.second;
    maxv = max(v,maxv);
  }

  for(auto it = memo.begin();it!=memo.end();it++){
    if(it->second == maxv) cout << it->first <<endl;
  }

}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-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; }
// ---------------------------------------------------------------------------


bool check(vector<P> s){
    int h = 0;
    for(P p: s){
        if(h+p.first < 0) return false;
        h += p.second;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<P> ls,rs;
    int sum = 0;
    rep(i,N){
        string S;
        cin >> S;
        int h = 0;
        int mn = 0;
        for(auto c: S){
            if(c == '(') h++;
            else h--;
            chmin(mn,h);
        }
        if(h > 0) ls.emplace_back(mn,h);
        else rs.emplace_back(mn-h,-h);
        sum += h;
    }
    sort(ls.rbegin(),ls.rend());
    sort(rs.rbegin(),rs.rend());
    if(check(ls) and check(rs) and sum==0){
        cout << "Yes" << enld;
    }else{
        cout << "No" << enld;
    }
    return 0;
}

Measured memory_bytes: 18896
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll N, ans = 0;
string S;

int main() {
	cin >> N;
	cin >> S;
	rep(i, N - 1) {
		if (S[i] != S[i + 1])ans++;
	}
	cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 512
/*
[abc110] C - String Transformation
*/

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int AZ = 26;

string s, t;
int N;

bool solve() {
    int s2t[AZ], t2s[AZ];
    memset(s2t, -1, sizeof(s2t));
    memset(t2s, -1, sizeof(t2s));

    for (int i = 0; i < N; i++) {
        int sc = s[i] - 'a', tc = t[i] - 'a';
        if (s2t[sc] == -1) {
            s2t[sc] = tc;
        } else if (s2t[sc] != tc) {
            return false;
        }
        if (t2s[tc] == -1) {
            t2s[tc] = sc;
        } else if (t2s[tc] != sc) {
            return false;
        }
    }

    return true;
}

int main() {
    cin >> s;
    cin >> t;
    N = s.size();

    cout << (solve() ? "Yes" : "No") << endl;

    return 0;
}


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

int main()
{
  uint64_t n, k, a, b;
  uint64_t ary[100'000 + 1] {};

  cin >> n >> k;

  for (auto i = 0; i < n; i++) {
    cin >> a >> b;
    ary[a] += b;
  }

  uint64_t ans{0};
  for (auto i = 1; i <= 100'000; i++) {
    if (k <= ary[i]) {
      ans = i;
      break;
    }
    k -= ary[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n - 1):
    if (p[i - 1] < p[i] < p[i + 1]) or (p[i - 1] > p[i] > p[i + 1]):
        ans += 1
print(ans)


Measured memory_bytes: 8988
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;


ll dp[210][MAX];
vector<ll> S;

ll Get(int i, ll x) {
   // cout<<i<<" "<<x<<endl;
   if (dp[i][x]>=0) return dp[i][x];
   if (i==0) dp[i][x] = x%MOD;
   else {
      dp[i][x] = Get(i-1,x) * (i-1);
      dp[i][x]%= MOD;
      dp[i][x] += Get(i-1,x%S[i-1]);
      dp[i][x]%= MOD;
   }
   return dp[i][x];
}


int main(void) {
   ll N,X;
   cin>>N>>X;
   S.resize(N);
   rep(i,0,N) cin>>S[i];
   sort(S.begin(),S.end());
   rep(i,0,210) rep(j,0,MAX) dp[i][j] = -1;
   cout<<Get(N,X)<<endl;



   return 0;
}

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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

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

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int N;
	cin >> N;
	if (N <= 999) {
		cout << "ABC";
	}
	else {
		cout << "ABD";
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a[3],i=0,c7=0,c5=0;
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	
	for(i=0;i<3;i++){
		if(a[i]==7)c7++;
		else if(a[i]==5)c5++;
		else;
	}
	
	if(c7==1 && c5==2) printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**9)

N, M = map(int, input().split())
path = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    path[x].append(y)

dp = [-1] * N
def dfs(v):
    if dp[v] > -1:
        return dp[v] + 1
    ret = 0
    for i in path[v]:
        ret = max(ret, dfs(i))
    dp[v] = ret
    return ret + 1


for i in range(N):
    if dp[i] < 0:
        dfs(i)

print(max(dp))


Measured memory_bytes: 146592
//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = 1e6;
int  main()
{
	int n,m;
	cin >> n >> m;
	vector<int> adj[n];
	for(int i = 0;i < m;i++)
	{
		int x,y;
		cin >> x >> y;
		x--,y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	queue<int> q;
	vector<bool> used(N);
	vector<int> d(N), p(N);
	int ans = 0;
	for(int i = 0;i < n;i++)
	{
		int cnt = 0;
		q.push(i);
		used[i] = true;
		p[i] = -1;
		while (!q.empty()) {
			int v = q.front();
			q.pop();
			for (int u : adj[v]) {
				if (!used[u]) {
					cnt++;
					used[u] = true;
					q.push(u);
					d[u] = d[v] + 1;
					p[u] = v;
				}
			}
			ans = max(ans, cnt + 1);
		}
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

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

  int n,q;cin>>n>>q;
  std::vector<int> arr(n);
  for(int i=0;i<n;i++) arr[i]=0;
  priority_queue<P> que;
  for(int i=0;i<n;i++) que.push(P(0,-i));
  for(int i=0;i<q;i++){
      int a,v;cin>>a>>v;
      a--;
      arr[a]+=v;
      que.push(P(arr[a],-a));
      while(true){
        P p=que.top();
        int v=p.first,a=-(p.second);
        if(v==arr[a]){
            cout<<a+1<<" "<<v<<endl;
            break;
        }
        que.pop();
      }
  }
}

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

using namespace std;

int main() {
	
	int n, k, a, x=0;
	cin>>n>>k;
	for (int i=0; i<n; i++) {
		cin>>a;
		if (a<k-a) x+=a*2;
		else x=x+(k-a)*2;
	}
	cout<<x;
	
}


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

int main(){
    int N,Ai;
    cin >> N;
    int A_cnt[N]={0};
    for(int i=0;i<N-1;i++){
        cin >> Ai;
        A_cnt[Ai-1]++;
    }
    for(int i=0;i<N;i++) cout << A_cnt[i] << endl;
    return 0;
}

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

#define PB push_back
#define MP make_pair
#define MOD 1000000000
#define FOR(i,a,b) for(int i=(a);(i)<(b);(i)++)

typedef unsigned int UI;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<char, int> PCI;
const int mod = 1000000000 + 7;
int n , m;
map<int , int> cnt;
int main()
{
	scanf("%d" , &n);
	for(int i = 0; i < n; i++)
	{
		int x;
		scanf("%d" , &x);
		cnt[x]++;
	}
	scanf("%d" , &m);
	for(int i = 0; i < m; i++)
	{
		int x;
		scanf("%d" , &x);
		cnt[x]--;
		if(cnt[x] < 0)
		{
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
}






Measured memory_bytes: 9600
N = int(input())
a = list(map(int, input().split()))
alice = 0
bob = 0
a = sorted(a, key= lambda x: -x)

for i in range(len(a)):
  if i % 2 == 0:
    alice += a[i]
  else:
    bob += a[i]
print(alice - bob)

Measured memory_bytes: 38256
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define P pair<int, int>
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    int a, b;
    cin >> a >> b;
    for(int i = 1; i < 1011; i++){
        int tmpa = i * 108;
        tmpa /= 100;
        tmpa -= i;
        int tmpb = i * 110;
        tmpb /= 100;
        tmpb -= i;
        if(tmpa == a && tmpb == b){
            cout << i << endl;
            break;
        }
        if(i == 1010){
            cout << -1 << endl;
        }
    }
    solve();
    return 0;
}



Measured memory_bytes: 256
using System;

namespace DefaultNamespace
{
	
	public class Stuck
	{
		
		public  static void Main(string[] args)
		{
			string read=Console.ReadLine();
			string[] dataArray=read.Split();
			Answer ans= new Answer();
			Console.WriteLine(ans.answer(dataArray));
			
		}
		/*public static int answer(string[] s)
		{
		   // ?????????????????????push ???????????????pop ?????????????????????????????\
		   //string?????????s[]????????????????????????????????????????????????????????????????????????????????????????????????
		   for(int i=0;i<s.Length;i++){
		   int number=0;
		   if(int.TryParse(s[i],out number))
		      {
		   	push(number);
		      }
		   else{//???????????????????????????????????????
		   	calc(s[i]);
		   }
		   }
		   return stuck[1];
		}
		public static  void push(int num)
		{
			sPointer++;
			stuck[sPointer]=num;
			
		}
		
		public  static void calc(string ope)
		{//???????????????????????§switch
			int temp=0;
			switch(ope){//????????????????????????????????§????????????
					case "+": temp =stuck[sPointer-1]+stuck[sPointer];
					break;
					case "-": temp =stuck[sPointer-1]-stuck[sPointer];
					break;
					case "*": temp =stuck[sPointer-1]*stuck[sPointer];
					break;
					case "/": temp=stuck[sPointer-1]/stuck[sPointer];
					break;
			}
			sPointer-=2;
			push(temp);
			
		}
		*/
	}
	public class Answer
	{
		private int sPointer=0;
		private int[] stuck=new int[101] ;
	public  int answer(string[] s)
		{
		   // ?????????????????????push ???????????????pop ?????????????????????????????\
		   //string?????????s[]????????????????????????????????????????????????????????????????????????????????????????????????
		   for(int i=0;i<s.Length;i++){
		   int number=0;
		   if(int.TryParse(s[i],out number))
		      {
		   	push(number);
		      }
		   else{//???????????????????????????????????????
		   	calc(s[i]);
		   }
		   }
		   return stuck[1];
		}
		private void push(int num)
		{
			sPointer++;
			stuck[sPointer]=num;
			
		}
		
		private void calc(string ope)
		{//???????????????????????§switch
			int temp=0;
			switch(ope){//????????????????????????????????§????????????
					case "+": temp =stuck[sPointer-1]+stuck[sPointer];
					break;
					case "-": temp =stuck[sPointer-1]-stuck[sPointer];
					break;
					case "*": temp =stuck[sPointer-1]*stuck[sPointer];
					break;
					case "/": temp=stuck[sPointer-1]/stuck[sPointer];
					break;
			}
			sPointer-=2;
			push(temp);
			
		}
	}
}

Measured memory_bytes: 9144
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
long long n, m, a, b, c, dist[2000];
vector<pair<long long, long long>>x[3000];
int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> a >> b >> c;
        a--;
        b--;
        x[a].push_back(make_pair(b, c));
    }
    for (int i = 0; i < n; i++)dist[i] = -(1LL << 60);
    dist[0] = 0;
    long long P = dist[n - 1];
    for (int i = 0; i < 8 * n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (pair<long long, long long> k : x[j])
            {
                dist[k.first] = max(dist[k.first], dist[j] + k.second);
            }
        }
        if (P != dist[n - 1] && i >= 5 * n)
        {
            cout << "inf" << endl;
            return 0;
        }
        P = dist[n - 1];
    }
    cout << dist[n - 1] << endl;
    return 0;
}

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

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int MOD = 1e9+7;
const int MX = 400010;

int f[MX];
int rf[MX];

int C(int l,int k, int md) 
{
    if (k<0||k>l){
        return 0;
    }
    return f[l]*rf[k]%md*rf[l-k]%md;
}

void precfac() {
    f[0]=1;
    for (int i=1;i<MX;i++){
        f[i]=f[i-1]*i%MOD;
    }
    rf[MX-1]=powmod(f[MX-1],MOD-2, MOD);
    for (int i=MX-2;i>=0;i--){
        rf[i]=rf[i+1]*(i+1)%MOD;
    }
}
signed main(void)
{
	IOS;
	precfac();
	int n; cin>>n;
	int ans=0;
	for(int i = 1; n-2*i >= 1; i++) {
		// cout<<n-2*i-1<<" "<<i-1<<" "<< C(n-2*i-1,i-1,MOD)<<endl;
		ans += C(n-2*i-1,i-1,MOD);
		ans %= MOD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9896
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  map<string, int> mp;
  set<string> aux;
  int n;
  cin >> n;
  int biggest = -1;
  for(int i = 0; i < n; i++)
  {
    string str;
    cin >> str;
    mp[str]++;
    biggest = max(biggest, mp[str]);
  }
  for(auto it : mp)
    if(it.second == biggest)
      aux.insert(it.first);
  for(auto x : aux)
    cout << x << endl;

  return 0;
}

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

vector <int> c, v;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	c.resize(n);
	v.resize(n);
	for (int i = 0; i < n; i++){
		cin >> v[i];
	}
	for (int i = 0; i < n; i++){
		cin >> c[i];
	}
	long long ans = 0;
	for (int mask = 0; mask < (1 << n); mask++){
		long long V = 0, C = 0;
		for (int i = 0; i < n; i++){
			if (mask & (1 << i)){
				V += v[i];
				C += c[i];
			}
		}
		ans = max(ans, V - C);
		// cout << V << ' ' << C << '\n';
	}
	cout << ans;
}

Measured memory_bytes: 256
n,w = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(n)]
#dp[i][j]はi番目まででj(価値の合計)になる重さの最小値
sum_value = 0
for i in range(n):
  sum_value += wv[i][1]
dp = [[float("inf")]*(sum_value+1) for j in range(n)]
for k in range(sum_value+1):
  if k == wv[0][1]:
    dp[0][k] = wv[0][0]
for a in range(n-1):
  for b in range(sum_value+1):
    if dp[a][b-wv[a+1][1]] != float("inf"):
      dp[a+1][b] = min(dp[a][b-wv[a+1][1]]+wv[a+1][0],dp[a][b])
    elif b == wv[a+1][1]:
      dp[a+1][b] = min(wv[a+1][0],dp[a][b])
    else:
      dp[a+1][b] = dp[a][b]
ans = 0
for c in range(sum_value+1):
  if dp[-1][c] != float("inf") and w >= dp[-1][c]:
    ans = c
print(ans)

Measured memory_bytes: 192904
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
// void fill(ll n, ll a[n], ll value){ rep(i,0,n) a[i] = value; }
void cin(ll *n){ scanf("%lld",&(*n)); }
void cin2(ll *a, ll *b){ scanf("%lld%lld",&(*a),&(*b)); }
void cin3(ll *a, ll *b, ll *c){ scanf("%lld%lld%lld",&(*a),&(*b),&(*c)); }
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
// int int_sort( const void * a , const void * b ) {
//   return strcmp(( char * )a , ( char * )b );
// }
//     qsort((void*)s,n,sizeof(s[0]),int_sort );

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll n;
    ll ans=0;
    cin(&n);
    // cin2(&,&);
    // cin3(&,&,&);
    // ll [n];
    ll m=100;
    // rep(i,0,n){
    //     if(m>)
    //     cin(&[i]);
    // }
    while(1){
        if(m>=n){
            printf("%lld\n",ans);
            break;
        }
        m*=1.01;
        ans++;
    }

    
    // printf("%lld\n");
    return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef long double ld;

int fpow(int a, int b, int p){
	int res = 1;
	while(b>0){
		if(b&1) res = res * a % p;
		a = a * a % p;
		b>>=1;
	}
	return res;
}

int main(){
	fastio();
	int n, p; string s;
	cin >> n >> p >> s;
	vector<int> have(p, 0);
	have[0] = 1;
	ll ans = 0;
	int ps = 0;
	if (p == 2) for(int i = 0; i<n; i++) ans+= (((s[i]-'0')%2 == 0)?ll(i+1):0);
	else if (p == 5) for(int i = 0; i<n; i++) ans+= (((s[i]-'0')%5 == 0)?ll(i+1):0);
	else for(int i = n-1; i>=0; i--){
		ps+= fpow(10, n-i-1, p)*(s[i]-'0');
		ps %= p;
		ans+= ll(have[ps]);
		have[ps]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 720
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, Y;
    cin >> N >> Y;
    int cnt;
    for (int i = 0; i <= N; i++)
    {
        if (Y < 10000 * i) break;

        for (int j = 0; j <= N - i; j++)
        {
            if (Y < 10000 * i + 5000 * j) break;
            if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y)
            {
                cout << i << ' ' << j << ' ' << (N - i - j) << endl;
                return 0;
            }

        }
        
    }

    cout << "-1 " << "-1 " << "-1" << endl;
    
    return 0;
}

Measured memory_bytes: 888
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val N = scanner.nextInt()

    val points = mutableListOf<Point>()
    for (i in 1..N) {
        points.add(Point(scanner.nextInt(), scanner.nextInt()))
    }

    val distances: List<Double> = listChildDistances(null, 0.0, points)
    println(distances.average())
}

private fun listChildDistances(prevPoint: Point?, distanceToHere: Double, points: List<Point>): List<Double> {
    val distances = mutableListOf<Double>()
    for (point in points) {
        val distance: Double = if (prevPoint == null) {
            0.0
        } else {
            distance(prevPoint, point)
        }
        val nextPoints = points.filter { it != point }
        if (nextPoints.isEmpty()) {
            distances.add(distanceToHere + distance)
        } else {
            distances.addAll(listChildDistances(point, distanceToHere + distance, nextPoints))
        }
    }
    return distances
}

private data class Point(val x: Int, val y: Int)

private fun distance(p1: Point, p2: Point): Double = Math.sqrt((pow2(p1.x - p2.x) + pow2(p1.y - p2.y)).toDouble())

private fun pow2(i: Int): Int = i * i

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

int main() {
  int n;
  cin >> n;
  vector<int> card(n);
  for (int i=0; i<n; i++) {
    cin >> card.at(i);
  }
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  int total = 0;
  for (int i=0; i<n; i++) {
    if (i%2==0)
      total += card.at(i);
    else
      total -= card.at(i);
  }
  cout << total;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
#define forn(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(int i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;


bool comp(pi a, pi b){
    return a.S > b.S;
}

void solve(){
    int n, k;
    cin >> n >> k;
    vpi v(n);
    forn(i,n) cin >> v[i].F >> v[i].S;
    sort(all(v), comp);
    
    map<int,int> cont;
    ll diver = 0;
    ll temp = 0;

    for(int i = 0; i < k; i++){
        temp += v[i].S;
        if(!cont[v[i].F]) diver++;
        cont[v[i].F]++;
    }

    ll ans = temp + diver*diver;
    
    // two pointers
    int l = k-1;
    int r = k;
    while( l >= 0 && r < n ){
        while(l >= 0 && cont[v[l].F] == 1) l--;
        if(l < 0) break;
        cont[v[l].F]--;
        temp -= v[l].S;


        while(r < n && cont[v[r].F] != 0) r++;
        if(r >= n) break;
        
        cont[v[r].F]++;
        diver++;
        temp += v[r].S;
        ll t = temp + (diver*diver);
        ans = max(ans, t);

        l--;
        r++;
    }
    cout << ans << endl;
}

int main(){
    //int t; cin >> t;
    //while(t--) solve();

    solve();
    return 0;
}


Measured memory_bytes: 3968
from collections import deque

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

G = [[] for i in range(n)]
check = [0 for i in range(n)]


def bfs(s, c):
    q = deque()

    check[s] = 1
    q.append(s)

    while len(q) != 0:
        u = q.popleft()
        for v in range(len(G[u])):
            if check[G[u][v]] == 0:
                check[G[u][v]] = 1
                q.append(G[u][v])

        check[u] = c


def main():
    for i in range(m):
        a, b = map(int, input().split())
        G[a].append(b)
        G[b].append(a)

    cnt = 2
    for i in range(n):
        if check[i] == 0:
            bfs(i, cnt)
            cnt += 1

    q = int(input())
    for i in range(q):
        s, t = map(int, input().split())
        if check[s] == check[t]:
            print("yes")
        else:
            print("no")


if __name__ == '__main__':
    main()



Measured memory_bytes: 23552
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; ++i) {
            a[i] = sc.nextInt();
        }

        System.out.println(solve(a));

        sc.close();
    }

    static long solve(int[] a) {
        return Math.min(computeOperationNum(a, false), computeOperationNum(a, true));
    }

    static long computeOperationNum(int[] a, boolean posOrNeg) {
        long result = 0;
        int sum = 0;
        for (int ai : a) {
            sum += ai;
            if (posOrNeg) {
                if (sum <= 0) {
                    result += 1 - sum;
                    sum = 1;
                }
            } else {
                if (sum >= 0) {
                    result += sum + 1;
                    sum = -1;
                }
            }

            posOrNeg = !posOrNeg;
        }

        return result;
    }
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
}

int main()
{
  ll N, A, B;
  cin >> N >> A >> B;
  ll tmp = abs(A-B);
  if (tmp % 2 == 0) {
    print(tmp / 2);
  } else {
    print(min(A-1, N-B) + 1 + (tmp-1)/2);
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define vv vector<lli>
#define vp vector<pair<lli,lli>>
#define vpp vector<pair<lli,pair<lli,lli>>>
#define lims(w) (w).begin(),(w).end()
#define rlims(w) (w).rbegin(),(w).rend()
#define pb push_back
#define mp make_pair
#define f(i,a,b) for(lli i=a;i<b;i++)
#define ff first
#define ss second
#define sz(a) (lli)(a.size())
lli inf = (1e18 + 2);
lli par[200005];
lli sizee[200005];

vv getUniqs(vv vec)
{
        sort(lims(vec));
        auto itr = unique(lims(vec));
        vec.resize(distance(vec.begin(), itr));
        return vec;
}

void Union(lli x,lli y)
{

        if(sizee[x]<sizee[y])
        {

                par[x]=y;
                sizee[y]+=sizee[x];
        }

        else
        {

                par[y]=x;
                sizee[x]+=sizee[y];
        }

}

lli find(lli i)
{

        while(par[i]!=i)
        {
                i=par[i];
                par[i]=par[par[i]];
        }

        return i;
}

int main()
{
	lli n,m,a,b;
	cin>>n>>m;
	lli maxx = -inf;
	vv v;

	f(i,1,n+1)
	{
		par[i] = i;
		sizee[i] = 1;
	}

	f(i,0,m)
	{
		cin>>a>>b;

		if(find(a) != find(b))
		{
			Union(find(a),find(b));
		}
	}

	f(i,1,n+1)
	{
		v.pb(find(i));	
	}

	v = getUniqs(v);

	f(i,0,sz(v))
		maxx = max(sizee[v[i]], maxx);
	cout<<maxx<<endl;
	return 0;
}


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

using namespace std;

int main(){
	int n; cin >> n;
	double a[55];

	for (int i = 1; i <= n; i++){
    	cin >> a[i];
    }
	
 	if (n == 1) {
		cout << a[1];
		return 0;
    }
  
	sort(a + 1, a + n + 1);

  	double x = (a[1] + a[2]) / 2;
	for (int j = 3; j <= n; j++){
		x = (x + a[j]) / 2; 
    }
	cout << x;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
using namespace std;
int p[2],f[2];
int x,n,i;
int main()
{
   // freopen("data.in","r",stdin);
    cin>>n;
    p[1]=1;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        f[(x&1)]=1;
        f[((x&1)^1)]=2;
        p[0]=(p[1]*f[0]+3*p[0]);
        p[1]=(p[1]*f[1]);
    }
    cout<<p[0];
    return 0;
}


Measured memory_bytes: 256
// g++ -std=c++17 -O2 -Wall B.cpp -o B -D _DEBUG

#include <bits/stdc++.h>
using namespace std;

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false); 
    cin.tie(NULL);

    int n;
    cin >> n;
    int cnt = 0;
    while (n--) {
        int a, b;
        cin >> a >> b;
        if (cnt >= 3) continue;
        if (a == b) cnt++;
        else cnt = 0;
    }
    if (cnt >= 3) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(void){
	int visitors[7];
	int n,i;
	int age;
	while(1){
		for(i = 0; i < 7; i++){
			visitors[i] = 0;
		}
		scanf("%d",&n);
		if(n == 0){break;}
		for(i = 0; i < n; i++){
			scanf("%d",&age);
			if(age < 60){
				visitors[age / 10]++;
			}else{
				visitors[6]++;
			}
		}
		for(i = 0; i < 7; i++){
			printf("%d\n",visitors[i]);
		}
	}

	return 0;
}

Measured memory_bytes: 0
s = input()
t = input()
ls = len(s)
lt = len(t)
res = 0
for i in range(ls - lt + 1):
    tmp = 0
    for j in range(lt):
        if s[i + j] == t[j]:
            tmp += 1
    res = max(res, tmp)
print(lt - res)


Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	ll N, M; cin >> N >> M;
	ll ans;
	if (N * 2 <= M) {
		ans = N;
		M -= N * 2;
		if (M > 3) {
			ans += M / 4;
		}
	}
	else {
		ans = M / 2;
	}
	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 256
import sys
import math


N = int(input())

timelis = []
for _ in range(N):
    A,B = map(int, input().split())
    timelis.append([A,B])

timelis = sorted(timelis,key=lambda x: x[1])

sum_time = 0
for i in timelis:
    need = i[0]
    deadline = i[1]

    sum_time = sum_time + need

    if sum_time > deadline:
        print("No")
        sys.exit()

print("Yes")


Measured memory_bytes: 114744
n, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
a.unshift(nil)
cnt = 1
d = [nil, 0]
2.upto(n+1) do |i|
  di = d[i-1] + a[i-1]
  cnt += 1 if di <= x
  d << di
end

puts cnt

Measured memory_bytes: 3836
n,p=map(int,input().split())
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
a=prime_factors(p)
dic={}
for x in a:
    if x in dic:
        dic[x]+=1
    else:
        dic[x]=1
a=sorted(set(a))
ans=1
for y in a:
    z=dic[y]//n
    if dic[y]>=n:
        ans*=y**z
print(ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int a, b, c;

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

	cin >> a >> b >> c;
	if (a < b && a < c && b < c) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}

	return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int x; cin >> x;
  int y = 100;
  for(int i = 1; i < 1e7; i++){
    y += 0.01 * y;
    if(y >= x){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef int64_t ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

const ll mod = 1e9 + 7;

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

  int n;
  cin >> n;
  vector<ll> c(n);
  rep(i, n) cin >> c[i];

  vector<ll> sum(2e5+5, 0);
  vector<ll> dp(n+1, 0);
  dp[0] = 1;

  rep(i, n) {
    ll x = c[i];
    if (i != 0 && c[i] == c[i-1]) {
      dp[i+1] = dp[i];
      continue;  // 同じ値の間には区切りを入れない
    }
    sum[x] = (sum[x] + dp[i]) % mod;
    dp[i+1] = sum[x];
  }

  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 5500
#include<stdio.h>

int main(void){
    int n,a,min=1000000000,i,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        cnt=0;
        scanf("%d",&a);
        while (a%2==0){
            a/=2;
            cnt++;
        }
        if(cnt<min){
            min=cnt;
        }
    }
    printf("%d",min);
    return 0;
}

Measured memory_bytes: 128