akhauriyash/Code-Regression huggingface dataset:
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define vi vector<ll>
#define pii pair<ll,ll>
#define bc __builtin_popcountll
#define vvi vector<vi> 
#define vpii vector<pair<ll,ll>>
#define mll unordered_map<ll,ll>
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define fo(i,a,b) for(i=a;i<=b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0.00, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()-->returns an iterator to the k-th largest element (counting from zero)
//X.order_of_key()-->the number of items in a set that are strictly smaller than our item.
struct cmp
{
	bool operator() (ll a,ll b){
		return (a>b);
	}
};
ll ceil(const ll &a, const ll &b)
{
    if(a%b == 0)
        return a/b;
    return a/b +1;
}
ll mod=1000000007;
const ll N=100005;
int main()
{
fast;
    ll n;
    cin>>n;
    long double p[n];
    f(i,n)
    {
        cin>>p[i];
    }
    long double dp[n+1][n+1];//dp[i][j]=probablity of getting j heads till ith index our ans=dp[n][i](i=n/2+1 to n)
    clr(dp);
    dp[0][0]=1.00;
    f1(i,n)
    {
        f(j,i+1)
        {
            if(j==0)//0 heads
            {
                dp[i][j]=dp[i-1][j]*(1.0-p[i-1]);
                continue;
            }
            dp[i][j]=(dp[i-1][j-1]*p[i-1])+(dp[i-1][j]*(1.00-p[i-1]));
        }
    }
    //more heads then tail start from n/2+1
    long double ans=0.0;
    for(ll i=(n/2)+1;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}

Measured memory_bytes: 144396
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;

int main() {
  ll a = 0,b = 0;
  cin >> a >> b;
  a = a - b*2;
  if(a < 0){
    cout << 0;
  }
  else{
    cout << a;
  }
}

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

int main() {
	int x,y,z,k,i,j;
	cin >> x >> y >> z >> k;

	vector<long> a(x),b(y),c(z);
	for(i=0; i<x; i++){
		cin >> a[i];
	}
	for(i=0; i<y; i++){
		cin >> b[i];
	}
	for(i=0; i<z; i++){
		cin >> c[i];
	}
	
	vector<long> t(x*y,0);
	for(i=0; i<x; i++){
		for(j=0; j<y; j++){
			t[i*y+j]=a[i]+b[j];
		}
	}
	
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());
	
	vector<long> ans(min(k,x*y)*z,0);
	
	for(i=0; i<min(k,x*y); i++){
		for(j=0; j<z; j++){
			ans[i*z+j]=t[i]+c[j];
		}
	}
	
	sort(ans.begin(),ans.end());
	reverse(ans.begin(),ans.end());
	for(i=0; i<k; i++){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 31616
def main():
    import math
    N, K = map(int, input().split())
    #syo = int(N / K)    # 桁の件
    #syo = math.floor(N / K)    # 桁の件
    amari = N % K
    #tmp = K * (syo + 1) - N
    tmp = K - amari

    if amari <= tmp:
        print(amari)
    else:
        print(tmp)

main()

Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , 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; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    ll q;
    cin>>q;
    rep(_,q){
        ll a,b;
        cin>>a>>b;
        ll n=a*b-1;
        if(a==b){
            cout<<(a-1)*2<<endl;
            continue;
        }
        ll left=1,right=1LL<<31;
        while(right-left>1){
            ll mid=(left+right)/2;
            ll c=(mid+1)/2*(mid+1-(mid+1)/2);
            if(c>n) right=mid;
            else left=mid;
        }
        cout<<left-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int k; cin >> k;
  queue<ll> q;
  rep(i,9) q.push(i+1);
  int cnt=1;
  vector<int> d = {-1, 0, 1};
  while(k > cnt) {
    ll x = q.front(); q.pop();
    for (auto dn : d) {
      int rn = x % 10 + dn;
      if (0 <= rn && rn < 10) q.push(10*x+rn);
    }
    cnt++;
  }
  cout << q.front() << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>
#define rep(i,n) for(int i = 0; i < (n); i++) 
using namespace std;

int main() {
	long long int a,b,c,k,ans=0;
        vector<int> data;
        string str;	
	cin >> a >> b >> c >> k;
	
	if (a > k) {
		ans += k;
	} else {
		ans += a;
	}
	k = k - (a + b);
	
	if (k > 0) {
		if (c > k) {
			ans += k * (-1);
		} else {
			ans += c * (-1);
		}
		cout << ans << endl;
	} else {
		cout << ans << endl;
	}	

	return 0;
}


Measured memory_bytes: 3628
import math
import collections

def main():
    x, y = input_list()
    if x < 2 or y < 2:
        print(abs(x-2) * abs(y-2))
    else:
        print((x-2) * (y-2))


def yogen(a, b, angle):
    coss = math.cos((angle/180)*math.pi)
    return math.sqrt(a**2 + b**2 - 2*a*b*coss)


def get_angle(hour, minute):
    h = (hour * 360) / 12 + (minute * 360) / (12 * 60)
    m = (minute * 360) / 60
    angle = abs(h-m)
    return min(angle, 360-angle)

def has(v, l):
    for vl in l:
        if v == vl:
            return True
    return False

def input_list():
    return list(map(int, input().split()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	int N,A[300000],i;
	ll sum=0;

	cin>>N;
	REP(i,3*N) cin>>A[i];
	SORT(A,3*N);

	for(i=N;i<=3*N;i+=2) sum+=A[i];
	print(sum);

	return 0;
}




Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(void){
   // Your code here!
   double r;
   cin >> r;
   double x=r*r*M_PI;
   double y=2*r*M_PI;
   cout << fixed << setprecision(5) <<x;
   cout << " ";
   cout << fixed << setprecision(5) <<y;
   cout << endl;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

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

    ll X, Y; cin >> X >> Y;
    if (X > Y) swap(X, Y);

    string P[2] = {"Brown", "Alice"};
    cout << P[(Y-X > 1)] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int p[10][10];

void drop(int x,int y){
	if(-1<x && x<10 && -1<y && y<10)p[x][y]++;
}

int main(void){

	int i,j,x,y,size;
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			p[i][j]=0;
		}
	}

	while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
		switch(size){
		case 3:
			drop(x+2,y);
			drop(x,y+2);
			drop(x-2,y);
			drop(x,y-2);
		case 2:
			drop(x+1,y+1);
			drop(x+1,y-1);
			drop(x-1,y+1);
			drop(x-1,y-1);
		case 1:
			drop(x+1,y);
			drop(x,y+1);
			drop(x-1,y);
			drop(x,y-1);
		default:
			drop(x,y);
		}
	}

	x=0;y=0;
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			if(p[i][j]==0)x++;
			else if(p[i][j]>y)y=p[i][j];
		}
	}

	printf("%d\n%d\n",x,y);
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define     ll              long long
#define     MAX             100000
#define     FI              freopen("input.txt","r",stdin)
#define     FO              freopen("output.txt","w",stdout)
#define     fast            ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define     sc(a)           scanf("%d",&a)
#define     sc2(a,b)        scanf("%d %d",&a,&b)


int main()
{
    int test;
    cin>>test;
    deque<int>deq;
    while(test--)
    {
        int choice,a,b,c;
        cin>>choice;
        switch(choice)
        {
        case 0:
            cin>>a>>b;
            if(a==0)
                deq.push_front(b);
            else
                deq.push_back(b);
            break;
        case 1:
            cin>>a;
            cout<<deq[a]<<"\n";
            break;
        default:
            cin>>a;
            if(a==0)
                deq.pop_front();
            else
                deq.pop_back();
            break;
        }
    }
    return 0;
}




Measured memory_bytes: 4516
#include <stdio.h>

#define REP(i,n,m) for(i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

int h,w;
int mt[26][4]; //[i][0]:左端 [1]:右端 [2]:上端 [3]:下端
int used[26];
char t[54][54];

//(a+'A') の文字が (b+'B') の文字より前にあるかの判定
//その判定と同時に, a が長方形であるかも判定する
int isFront(int a,int b){
    int i,j;
    REP(i,mt[a][2],mt[a][3]+1){
        REP(j,mt[a][0],mt[a][1]+1){
            if(t[i][j] == b + 'A' || t[i][j] == '.'){
                return 0;
            }
        }
    }
    return 1;
}

//Safeであるかどうかの判定
int isSafe(int idx,int rem){
    int i,j;
    int okFlg;
    
    if(rem == 0){
        //最後の記号が長方形か判定するためにisFrontを使う
        return isFront(idx,-1);
    }
    
    used[idx] = 1;
    rep(i,26){
        if(mt[i][1]!=-1 && !used[i]){
            
            //今まで使用した記号全てより後ろにあるか判定
            okFlg = 1;
            rep(j,26) if(used[j] && !isFront(j,i)){
                okFlg = 0;
                break;
            }
            
            if(okFlg && isSafe(i,rem-1)) return 1;
        }
    }
    used[idx] = 0;
    
    return 0;
}

int main(void){
    int i,j;
    int n,idx,count;
    
    scanf("%d",&n);
    while(n--){
        scanf("%d%d",&h,&w);
        
        rep(i,26){
            mt[i][0] = w+1;
            mt[i][1] = -1;
            mt[i][2] = h+1;
            mt[i][3] = -1;
        }
        
        count = 0;
        rep(i,h){
            scanf("%s",t[i]);
            rep(j,w) if(t[i][j] != '.') {
                idx = t[i][j] - 'A';
                
                //記号の種類カウント
                if(mt[idx][1] == -1) count++;
                
                //記号の左端,右端,上端,下端を更新
                if(mt[idx][0] > j) mt[idx][0] = j;
                if(mt[idx][1] < j) mt[idx][1] = j;
                if(mt[idx][2] > i) mt[idx][2] = i;
                if(mt[idx][3] < i) mt[idx][3] = i;
            }
        }
        
        rep(i,26) used[i] = 0;
        rep(i,26) if(mt[i][1] != -1 && isSafe(i,count-1)) break;
        
        printf("%s\n",count!=0 && i==26 ? "SUSPICIOUS" : "SAFE");
    }
    
    return 0;
}



Measured memory_bytes: 2036
#include<stdio.h>

int main(void){
	int count=0;
	int a,b,c,d;
	int x;
	while(scanf("%d",&x)!=EOF){
		for(a=0;a<10;a++){
			for(b=0;b<10;b++){
				for(c=0;c<10;c++){
					for(d=0;d<10;d++){
						if(a+b+c+d==x)count++;
					}
				}
			}
		}
		printf("%d\n",count);
		count=0;
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x, i, r, d;
    cin>>r>>d>>x;
    i=10;
    while(i--)
    {
    	x=(r*x)-d;
    	cout<<x<<endl;
    }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
    
    cin >> n >> k;
  	int nos[n];
  	for(int i=0;i<n;i++)
    {
      nos[i]=0;
    }
    for(int i=0;i<k;i++)
    {
    	int d;
        cin >> d;
        for(int j=0;j<d;j++)
        {
        	int a;
       		cin >> a;
            nos[a-1]++;
        }
    }
    int ans = 0;
    for(int i=0;i<n;i++)
    {
    	if(nos[i]==0)ans++;
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)

int main(){
    int n; cin >> n;
    vector<int> T(n);
    int sum = 0;
    rep(i,n){
        cin >> T[i];
        sum += T[i];
    }
    int m; cin >> m;
    int p,x;
    rep(i,m){
        cin >> p >> x;
        cout << sum - T[p-1] + x << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<set>
#include<map> 
using namespace std;

const int N=1e5+10;
priority_queue<int> q;
int a[N],b[N],u,ans,n,num;
bool bj;

int find(int x)
{
	int l,r,mid;
	l=1;r=ans;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(b[mid]<x) r=mid-1;
		else l=mid+1;
	}
	return l;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	b[1]=a[1];ans=1;
	for(int i=2;i<=n;i++)
	{
		if(b[ans]>=a[i])
		{
			b[++ans]=a[i];
		}
		else
		{
			u=find(a[i]);
			b[u]=a[i];
		}
	}
	printf("%d",ans);
	
	return 0;	
} 

Measured memory_bytes: 4552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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; }

long long GCD(long long A, long long B) {
    if (B == 0) return A;
    else return GCD(B, A % B);
}

int main() {
    ll K; cin >> K;
    ll sum = 0;
    reps(i, K) {
        reps(j, K) {
            ll mem = 0;
            mem += GCD(i, j);
            reps(k, K) sum += GCD(mem, k);
        }
    }
    cout << sum << endl;
}

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

N,M = map(int,input().split())
edges = []
to = [[] for i in range(N)]
rto = [[] for i in range(N)]
for i in range(M) :
    u,v,cost = map(int,input().split())
    u -= 1
    v -= 1
    cost *= -1
    edges.append([u,v,cost])
    to[u].append(v)
    rto[v].append(u)

canVisitFromS = [False]*N
canVisitFromG = [False]*N

def dfs(u) :
    if canVisitFromS[u] : return
    canVisitFromS[u] = True
    for v in to[u] :
        dfs(v)

def rdfs(v) :
    if canVisitFromG[v] : return
    canVisitFromG[v] = True
    for u in rto[v] :
        rdfs(u)

dfs(0)
rdfs(N-1)

OK = [canVisitFromS[i] * canVisitFromG[i] for i in range(N)]

dist = [float("inf")]*N
dist[0] = 0

update = True
step = 0
ans = 0

while update :
    update = False
    for i in range(M) :
        u,v,cost = edges[i]
        if OK[u] * OK[v] == 0 : continue
        if dist[v] > dist[u] + cost :
            dist[v] = dist[u] + cost
            update = True
    step += 1
    if step > N :
        ans = "inf"
        break
if ans != "inf" :
    ans = dist[N-1] * (-1)
print(ans)


Measured memory_bytes: 48616
N = int(input())
A = [int(s) for s in input().split()]
count = 0
flag = True

while flag:
  for i in range(N):
    if A[i] % 2 != 0:
      flag = False
      break
  if flag == False:
    print(count)
  count += 1
  for i in range(N):
    A[i] = A[i] / 2


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

int main(){
    int n,m;
    int P[1010],Q[1000000];

    while(true){
	cin >> n >> m;
	if(n==0&&m==0) break;
	
	P[0]=0;
	for(int i=1;i<=n;i++) scanf("%d",&P[i]);

	int num=0;
	for(int i=0;i<=n;i++){
	    for(int j=i;j<=n;j++){
		Q[num++]=P[i]+P[j];
	    }
	}

	sort(Q,Q+num);

	int key,index,ans=0;
	int *pos;
	for(int i=0;i<num;i++){
	    key=m-Q[i];
	    if(key<0) break;

	    pos=lower_bound(Q,Q+num,key);
	    index=distance(Q,pos)-1;

	    ans=max(ans,Q[i]+Q[index]);
	}
 	cout << ans << endl;
	
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<bool> pushed(n, false);
    vector<int> a(n);
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int now_on = 1;
    while (true)
    {
        count++;
        pushed[now_on - 1] = true;
        now_on = a[now_on - 1];
        if (now_on == 2) break;
        if (pushed[now_on - 1] == true)
        {
            count = -1;
            break;
        }
    }
    cout << count << endl;
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  if ((N*A)>B) {
    cout << B << endl;
  }
  else if ((N*A)<B) {
    cout << N*A << endl;
  }
  else {
    cout << B << endl;
  }
  
  }

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

int main () {
    string s;
    cin >> s;
    bool flag = true;
    int i = 0;
    int count = 0;

    while (flag == true && i < s.size()){
        if (i % 2 == 0){
            if (s.at(i) == 'R' || s.at(i) == 'U' || s.at(i) == 'D'){
                count++;
            }
            else
                flag = false;
        }
        else if (i % 2 == 1){
            if (s.at(i) == 'L' || s.at(i) == 'U' || s.at(i) == 'D'){
                count++;
            }
            else
                flag = false;
        }
        i++;
    }

    if (count == s.size()){
        cout << "Yes" << endl;
    }

    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
S = input()

#01010...
bw = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '1':
            bw += 1
    else:
        if S[i] == '0':
            bw += 1

#10101...
wb = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            wb += 1
    else:
        if S[i] == '1':
            wb += 1

print(min(bw,wb))

Measured memory_bytes: 3316
n = int(input())
a = list(map(int,input().split()))
lst = [0]*(max(a)+1)

for i in a:
    lst[i] += 1

num_lst = [0]*(max(a)+1)
for i in range(1,max(a)+1):
    if not lst[i] in [0,1]:
        num_lst[i] = lst[i]*(lst[i]-1)//2
ans = sum(num_lst)

for i in a:
    if lst[i] in [0,1]:
        print(ans)
    else:
        print(ans-num_lst[i]+((lst[i]-1)*(lst[i]-2)//2))

Measured memory_bytes: 32160
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1<<30;
const long long LINF = 1LL << 60;
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    cin.tie(nullptr) ;
    ios::sync_with_stdio(false) ;

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll res = -LINF;
    chmax(res, a*c);
    chmax(res, a*d);
    chmax(res, b*c);
    chmax(res, b*d);
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <set>
#include <functional>
#include <list>
#include <bitset>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>

#define INF 1e9
#define MOD 1000000007
#define ll long long
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef unsigned long long ull;
typedef pair<ll, ll> pr;
//ll t[100004],d[100004];
//vector<int>t[100004];
ll num[100004];
pr p[100004];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k,ti;
    ll d;
    cin>>n>>k;
    for(ll i=0;i<n;i++){
        cin>>ti>>d;
        p[i]=make_pair(d,ti-1);
    //    t[ti-1].push_back(d);
    }
    fill(num,num+n,0LL);
    sort(p,p+n,greater<pr>());
    // for(int i=0;i<n;i++){
    //     sort(t[i].begin(),t[i].end(),greater<ll>());
    // }
    // for(int i=0;i<n;i++){
    //     cout<<p[i].first<<" "<<p[i].second<<endl;
    // }
    ll tmp=0;
    for(ll i=0;i<k;i++){
        tmp+=p[i].first;
        num[p[i].second]++;
    }
    ll s=0;
    for(ll i=0;i<n;i++){
        if(num[i]!=0){
            s++;
        }
    }
    tmp+=s*s;
    ll l=k-1;
    ll r=k;
    ll ans=tmp;
    for(ll i=s+1;i<=k;i++){
        if(l==0){
            exit(1);
        }
    //    cout<<tmp<<endl;
        while(num[p[l].second]==1&&l>0){
            l--;
        }
        if(num[p[l].second]>1){
            while(num[p[r].second]!=0&&r<n-1){
                r++;
            }
        }
        if(num[p[r].second]==0){
            num[p[r].second]++;
            num[p[l].second]--;
            tmp=tmp+p[r].first-p[l].first+2*i-1LL;
            if(tmp>ans){
                ans=tmp;
            }
            l--; r++;
        }
    }
    //cout<<tmp<<endl;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  var left = 0L
  for (_ ← 0 until readLine.trim.toInt){
    val Array(_, direction, length) = readLine.trim.split(' ')
    direction match {
      case "(" ⇒ left += length.toInt
      case _ ⇒ left -= length.toInt
    }
    println(
      if (left == 0) "Yes"
      else "No"
    )
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 64508
#include <iostream>

using namespace std;

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

int main()
{
	for(int n;cin>>n;){
		int res=0;
		rep(i,10) rep(j,10) rep(k,10) rep(l,10){
			if(i+j+k+l==n)
				res++;
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>

double helon(double a,double b,double c)
{
	double p=(a+b+c)/2;
	return sqrt(p*(p-a)*(p-b)*(p-c));
}

int main()
{
	int i,n,m;
	double a,l,x; 
	for(;~scanf("%d%d%d",&i,&n,&m);)
	{
		a=i;l=n;x=m;
		printf("%lf\n",helon(a,l,l)+2*helon(l,(l+x)/2,(l+x)/2));
	}
	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = 1e9+7;
ll A[1005];

int main()
{
	int N;
	cin >> N;
	for (int i = 1; i <= N; ++i)
	{
		int temp = i;
		for (int j = 2; j <= N; ++j)
		{
			while(temp % j == 0)
			{
				temp /= j;
				A[j]++;
			}
		}
	}
	ll ans = 1;
	for (int i = 1; i <= N; ++i)
	{
		//cout << A[i] << endl;
		ans = (ans * (A[i]+1)) % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A, V = lr()
B, W = lr()
if A == B:
    print('YES'); exit()
T = ir()
speed = V - W
if speed <= 0:
    print('NO'); exit()

bl = abs(A-B) / speed <= T
print('YES' if bl else 'NO')


Measured memory_bytes: 9076
$s1 = gets.chomp.split('')
$s2 = gets.chomp.split('')

s1_length = $s1.length

s2_length = $s2.length

$table = Array.new(s1_length + 1).map { Array.new(s2_length + 1, 0) }

def max(a, b)
  a < b ? b : a
end

def min(a, b)
  a > b ? b : a
end

max_common = -1000

(s1_length + 1).times do |i|
  (s2_length + 1).times do |j|
    if i == 0
      $table[i][j] = j
      next
    end
    if j == 0
      $table[i][j] = i
      next
    end

    $table[i][j] = if $s1[i - 1] == $s2[j - 1]
                     $table[i - 1][j - 1]
                   else
                     min(min($table[i - 1][j], $table[i][j - 1]), $table[i - 1][j - 1]) + 1
                  end
  end
end
puts $table.last.last



Measured memory_bytes: 14744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n;
int h[N];
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> h[i];
    h[0] = h[1];
    for(int i = 1; i <= n; i++) {
        if(h[i] > h[i - 1]) h[i]--;
        else if(h[i] < h[i - 1]) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<limits>
#include<algorithm>
#include<numeric>

int main(){
    int A, B;
    std::cin >> A >> B;

    if(A>=13) std::cout << B << std::endl;
    else if(A>=6&&A<13) std::cout << B/2 << std::endl;
    else std::cout << 0 << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<functional>
    #include<vector>
     
    using namespace std;
     
    int main()
    {
    	int a,b,c,d;
    	cin>>a>>b>>c>>d;
     
    	int start=max(a,c);
    	int end=min(b,d);
    	if(end-start>=0)cout<<end-start<<endl;
    	else cout<<0<<endl;
     
    	return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int i = 1;

    // method 1
    // do
    // {
    //     int x = i;
    //     if (x%3 == 0)
    //     {
    //         cout << ' ' << i;
    //         continue;
    //     }

    //     do
    //     {
    //         if (x%10 == 3)
    //         {
    //             cout << ' ' << i;
    //             break;
    //         }
    //         x /= 10;
    //     } while(x);
    // } while (++i <= n);

    //method 2 
    do
    {
        int x = i;
        if (x%3 == 0)
        {
            cout << ' ' << i;
        }
        else
        {
            do
            {
                if (x%10 == 3)
                {
                    cout << ' ' << i;
                    x = 0;
                }
                else
                {
                    x /= 10;                    
                }
            } while(x);            
        }
    } while (++i <= n);
    
    cout << endl;
}


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

int main() {
  string s;
  cin >> s;
  int q;
  scanf("%d", &q);
  
  bool reversed = false;
  string str1 = "", str2 = "";
  for (int i = 0; i < q; i++) {
    int t;
    scanf("%d", &t);

    if (t == 1)
      reversed = !reversed;
    else {
      int f;
      char c;
      scanf("%d %c", &f, &c);
      
      if (f == 1) {
        if (reversed)
          str2 += c;
        else
          str1 += c;
      }
      else {
        if (reversed)
          str1 += c;
        else
          str2 += c;
      }
    }
  }

  string ans = "";
  for (auto it = str1.rbegin(); it != str1.rend(); it++)
    ans += *it;
  ans += s + str2;
  if (reversed) {
    for (auto it = ans.rbegin(); it != ans.rend(); it++)
      printf("%c", *it);
    printf("\n");
  }
  else
    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1476
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(b-a)<=d&&abs(c-b)<=d)
	{
		cout<<"Yes"<<endl;
	}
	else if(abs(c-a)<=d)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
	
}

Measured memory_bytes: 256
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    string s;
    cin >> s;

    int ans{1000};

    for (int i = 0; i <= s.size() - 3; ++i)
    {
        auto substr = s.substr(i, 3);

        ans = min(ans,  abs (stoi(substr) - 753));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int maxx,n,t;
int a[2100000];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	maxx=0;
	for (int i=1;i<n;i++)
		if (min(a[i],a[n]-a[i])>maxx) maxx=min(a[i],a[n]-a[i]),t=i;
	printf("%d %d\n",a[n],a[t]);
}

Measured memory_bytes: 512
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] l = new int[n];
    int sum = 0;
    for(int i = 0; i < n; i++){l[i] = sc.nextInt();}
    Arrays.sort(l);
    for(int i = n-1; i > n-1-k; i--){
      sum += l[i];
    }
    System.out.println(sum);
  }
}

/*
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String blank = sc.nextLine();
String s = sc.nextLine();
System.out.println();
System.exit(0)
*/


Measured memory_bytes: 23252
a=input()
for i in range(0,len(a)-1):
	if a[i]==a[i+1]:
		print(i+1,i+2)
		exit()
	elif i<len(a)-2:
		if a[i]==a[i+2]:
			print(i+1,i+3)
			exit()
print(-1,-1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    // int y = 1000, m = 0;
    // int min, max;
    // rep(i, n-1) {
    //     if (a[i] < a[i+1]) {
    //         min = a[i];
    //         while (i < n-1 && a[i] < a[i+1]) {
    //             max = a[i+1];
    //             i++;
    //         }
    //         m = y / min;
    //         y -= m * min;
    //         y += m * max;
    //         m = 0;
    //     }
    // }
    long y = 1000, m = 0;
    rep(i, n-1) {
        if (a[i] < a[i+1]) {
            m = y / a[i];
            y += m * (a[i+1] - a[i]);
            m = 0;
        }
    }
    cout << y << endl;
}

Measured memory_bytes: 3628
#include <stdlib.h>
#include <iostream>
#include <algorithm>


using namespace std;

bool graph[60][60];
bool visit[60];
int N;

void dfs(int x){
    if(visit[x]){return;}
    visit[x] = true;
    for(int i=1;i<=N;i++){
        if(graph[x][i]){
            dfs(i);
        }
    }
}

int main(void){
    int M;
    cin >> N >> M;

    int a[M], b[M];
    int count=0;
    bool tmp=true;

    for(int i=0;i<M;i++){
        cin >> a[i] >> b[i];
        graph[a[i]][b[i]] = true;
        graph[b[i]][a[i]] = true;
    }

    for(int i=0;i<M;i++){
        for(int ii=1;ii<=N;ii++){
            visit[ii] = false;
        }
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        dfs(1);
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
        tmp = true;
        for(int ii=1;ii<=N;ii++){
            if(!visit[ii]){
                tmp = false;
            }
        }
        if(!tmp){
            count++;
        }
    }
    cout << count << endl;
    return 0;

}

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

using namespace std;

long long n, a, b;

int main() {
	scanf("%lld%lld%lld", &n, &a, &b);
	if ((b - a) % 2)
		printf("%lld\n", min((a + b - 1) / 2, ((n - a) + (n - b) + 1) / 2));
	else
		printf("%lld\n", (b - a) / 2);
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

String input = sc.next();

String letter3 = input.substring(2, 3);
String letter4 =  input.substring(3, 4);
String letter5 = input.substring(4, 5);
String letter6 =  input.substring(5, 6);

if(letter3.equals(letter4) && letter5.equals(letter6)) {
	System.out.println("Yes");
}else {
	System.out.println("No");
}
}
}


Measured memory_bytes: 22740
let solve n w d =
  let t = Array.make_matrix (n + 1) (w + 1) 0 in
  let rec doit = function
    | (i, _) when i > n -> t.(n).(w)
    | (i, x) when x > w -> doit (i + 1, 1)
    | (i, x) ->
      let (vi, wi) = d.(i-1) in
      t.(i).(x) <-
        if wi <= x && t.(i-1).(x-wi) + vi > t.(i-1).(x) then t.(i-1).(x-wi) + vi
        else t.(i-1).(x);
      doit (i, x + 1) in
  doit (1, 1)

let read () = Scanf.scanf "%d %d\n" (fun x y -> (x, y))

let () =
  let (n, w) = read () in
  let d = Array.init n (fun _ -> read ()) in
  Printf.printf "%d\n" (solve n w d)

Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


int main() {
    ll n; cin >> n;
    ll i = n;
    while(true){
        if(i % 2 == 0 && i % n == 0) break;
        i += n;
    }
    cout << i;
}


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

int main(int argc, char const *argv[]) {
    int k, n;
    cin >> k >> n;
    vector<int> A(n);
    for (size_t i = 0; i < n; i++) cin >> A[i];

    int ans = 1e9;
    for (size_t i = 0; i < n; i++) {
        int work;
        if (i == 0) work = A[n-1] - A[i];
        else work = k - A[i] + A[i-1];

        ans = min(ans, work);
    }

    cout << ans << endl;
    return 0;
}


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

l = [0]*(10**5+1)
for i in a:
    l[i] += 1
ans = 0
for i in range(10**5-1):
    ans = max(ans, l[i]+l[i+1]+l[i+2])
print(ans)

Measured memory_bytes: 20728
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long 


int main(){
    int N;
    int D[214514];
    int M;
    int T[214514];
    map<int,int>mpa={};
    map<int,int>mpb={};
    cin >> N;
    REP(i,N){cin >> D[i];mpa[D[i]]++;}
    cin >> M;
    REP(i,M){cin >> T[i];mpb[T[i]]++;}
    REP(i,M){
        if(mpa[T[i]]<mpb[T[i]]){
            cout << "NO"<<endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 20608
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
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 stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

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

  ll n, x;
  cin >> n >> x;
  vector<ll> a(n);
  for(ll i = 0; i < n; i++) cin >> a[i];

  ll ans = 0;
  for(ll i = 0; i < n; i++){
    if(a[i] > x){
      ans += a[i] - x;
      a[i] = x;
    }
  }

  for(ll i = 0; i < n - 1; i++){
    if(a[i] + a[i+1] > x){
      ans += a[i] + a[i+1] - x;
      a[i+1] -= a[i] + a[i+1] - x;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
a=[0]*(n+1)
if m>0:
  for _ in range(m):
    a[int(input())]+=1
dp=[0]*(n+1)
dp[0]=1
if a[1]!=1:
  dp[1]=1
if n==1:
  if a[1]==0:
    print(1)
    exit()
  else:
    print(0)
    exit()
for i in range(2,n+1):
  if a[i-2]==0 and a[i-1]==0:
    dp[i]=dp[i-2]+dp[i-1]
  elif a[i-1]!=0 and a[i-2]==0:
    dp[i]=dp[i-2]
  elif a[i-2]!=0 and a[i-1]==0:
    dp[i]=dp[i-1]
  else:
    dp[i]=0
print(dp[n]%(10**9+7))    


Measured memory_bytes: 504980
#include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0);   cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define mod 1000000007
 
const int mxN = 1e5;
vt<ll> adj[mxN];
vt<ll> dp;
vt<bool> vis(mxN, 0);
ll n, m;

void dfs(int u)
{
    vis[u] = 1;
    for(int v: adj[u])
    {
        if(!vis[v])
            dfs(v);
        dp[u] = max(dp[u], dp[v] + 1);
    }
}
 
 
int main()
{
FIO
 
    cin >> n >> m;
    dp = vt<ll>(n, 0);
    ll u, v;
    For(m)
    {
        cin >> u >> v;
        u--, v--;
        adj[u].pb(v);
    }
    For(n) if(!vis[i]) dfs(i);
    cout << *max_element(dp.begin(), dp.end()) << endl;
}

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

typedef long long ll;
ll x;

int main(){
	cin >> x;

	ll lo = 1, hi = 1e7, mid;

	while(lo < hi){
		mid = (lo + hi) / 2;

		if(mid * (mid + 1) / 2.0 >= x){
			hi = mid;
		}else{
			lo = mid + 1;
		}
	}

	cout << lo << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
using namespace std;
int check(int t,int n,int* a){
    int i,j;
    for(i=0;i<n;i++){
        if(a[i]==t){
            return 0;
        }
    }
    
    if(i==n) { return 87; }
    return 12;
}
int main(){
   int x,n;
   cin>>x>>n;
   int a[n],pmin=x,nmin=x;
   int i,j;
   for(i=0;i<n;i++) cin>>a[i];
   if(n==0) { cout<<x; return 0; }
   
   
   for(i=0;;i++){
       if(check(x+i,n,a)==87){
           pmin=x+i;
           break;
       }
   }
   
   for(i=0;;i--){
       if(check(x+i,n,a)==87){
           nmin=x+i;
           break;
       }
   }
   
   int ndiff=abs(nmin-x);
   int pdiff=abs(pmin-x);
   if(ndiff<=pdiff) cout<<nmin;
   else cout<<pmin;
    
    return 0;
    
}

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

using namespace std;

const int MAXN = 6e5 + 7;
const int MOD = 924844033; 

inline int read() {
	char in = getchar();
	int res = 0, flag = 1;
	while(!isdigit(in)) { if(in == '-') flag = -1; in = getchar(); }
	while(isdigit(in)) { res = (res << 1) + (res << 3) + in - '0'; in = getchar(); }
	return res * flag;
}

int n, Lim = 1, Log;
int cnt[MAXN], siz[MAXN], P, a[MAXN << 1], b[MAXN << 1];
int fac[MAXN + 7], rev[MAXN], ifac[MAXN + 7];
int dex, head[MAXN], nxt[MAXN << 1], to[MAXN << 1];

inline void Link(int x, int y) { ++dex; nxt[dex] = head[x]; to[dex] = y; head[x] = dex; }

inline int fpm(int x, int y) {
	int res = 1;
	while(y) {
		if(y & 1) res = 1ll * x * res % MOD;
		x = 1ll * x * x % MOD;
		y >>= 1;
	}
	return res;
}

void dfs(int u, int fa) {
	siz[u] = 1;
	for(int i = head[u]; i; i = nxt[i]) {
		int v = to[i];
		if(v == fa) continue;
		dfs(v, u);
		siz[u] += siz[v];
	}
	--cnt[siz[u]]; --cnt[n - siz[u]];
}

inline void Transform(int *A, int type) {
	for(int i = 1; i < Lim; ++i) if(i < rev[i]) 
		swap(A[i], A[rev[i]]);
	for(int mid = 1; mid < Lim; mid <<= 1) {
		int Wn = fpm(5, ((MOD - 1) / mid) >> 1);
		if(type == -1) Wn = fpm(Wn, MOD - 2);
		for(int r = (mid << 1), j = 0; j < Lim; j += r) {
			for(int l = 0, k = 1; l < mid; ++l, k = 1ll * Wn * k % MOD) {
				int x = A[j + l];
				int y = 1ll * A[j + l + mid] * k % MOD;
				A[j + l] = (x + y) % MOD;
				A[j + l + mid] = (1ll * x - y + MOD) % MOD;
			}
		}
	}
	int C = fpm(Lim, MOD - 2);
	if(type == -1) for(int i = 0; i < Lim; ++i) A[i] = 1ll * A[i] * C % MOD;
}

inline void init() {
	n = read();
	for(int i = 1; i < n; ++i) {
		int x = read();
		int y = read();
		Link(x, y); Link(y, x);
	}
	dfs(1, 0); cnt[n] = n;
	fac[0] = 1; n <<= 1; n += 2;
	while(Lim < n) Lim <<= 1, ++Log;
	n -= 2; n >>= 1;

	for(int i = 1; i < Lim; ++i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (Log - 1));
	for(int i = 1; i <= MAXN; ++i) fac[i] = 1ll * fac[i - 1] * i % MOD;
	ifac[MAXN] = fpm(fac[MAXN], MOD - 2);
	for(int i = MAXN - 1; i >= 0; --i) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % MOD;

	for(int i = 1; i <= n; ++i) a[i] = 1ll * cnt[i] * fac[i] % MOD;
	for(int i = 0; i <= n; ++i) b[i] = ifac[n - i];
}

inline void solve() {
	Transform(a, 1); Transform(b, 1);
	for(int i = 0; i < Lim; ++i) a[i] = 1ll * a[i] * b[i] % MOD;
	Transform(a, -1);
	for(int i = 1; i <= n; ++i) printf("%lld\n", (1ll * a[n + i] * ifac[i] % MOD + MOD) % MOD);
}

int main() {
	init();
	solve();
	return 0;
}


Measured memory_bytes: 40320
#!/usr/bin/env python
from collections import deque

def main():
    n, m = map(int, input().split())
    rw_lst = [[] for _ in range(n+1)]
    for _ in range(m):
        a, b = map(int, input().split())
        rw_lst[a].append(b)
        rw_lst[b].append(a)

    sign_lst = [-1 for _ in range(n+1)]
    sign_lst[1] = 0
    check_lst = [False for _ in range(n+1)]
    check_lst[1] = True

    queue = deque([1])
    while queue:
        room = queue.popleft()
        for way in rw_lst[room]:
            if not check_lst[way]:
                check_lst[way] = True
                sign_lst[way] = room
                queue.append(way)

    check = True
    for i in range(1, n+1):
        check = check and check_lst[i]

    if check:
        print("Yes")
        for i in range(2, n+1):
            print(sign_lst[i])
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 35016
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <queue>
 
using namespace std;
 
int s[1000];
 
int main(void){
    while (true){
        int n;
        double ave, temp = 0, ans = 0, sum = 0;
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++){
            scanf("%d", &s[i]);
            sum = sum + s[i];
        }
        ave = sum / n;
        for (int i = 0; i < n; i++){
            temp += (s[i] - ave)*(s[i] - ave);
        }
        ans = sqrt(temp / n);
        printf("%f\n", ans);
    }
}

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

#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#define mp make_pair
#define se second
#define fi first

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)

using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()

ll power(ll x, ll y, ll p) {
    ll res = 1;    x = x % p;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y = y>>1;    x = (x*x) % p;
    } return res;
}

int main()
{
    Imposter

    ll d,t,s;
    cin>>d>>t>>s;
    if(s*t>=d)
    cout<<"Yes"<<endl;
    else
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3644
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long former = 0;
        long latter = 0;
        long formerStep = 0;
        List<Long> actualList = new ArrayList<>();
        List<Long> stepList = new ArrayList<>();
        stepList.add(0l);

        for(int i = 0; i < n; i++){
            actualList.add(sc.nextLong());
        }
        sc.close();

        for(int i = 1; i < n ; i++){
            former = actualList.get(i - 1);
            latter = actualList.get(i);
            formerStep = stepList.get(i - 1);

            if((former + formerStep) <= latter){
                stepList.add(0l);
            }
            else{
                stepList.add(former + formerStep - latter);
            }
        }

        System.out.println(stepList.stream().mapToLong(e -> e).sum());
        
    }
}

Measured memory_bytes: 69172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String str = reader.readLine();
        int n = Integer.parseInt(str);

        long sum = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 3 == 0 || i % 5 == 0)
                continue;
            sum += i;
        }

        System.out.print(sum);
    }
}


Measured memory_bytes: 32576
#include <bits/stdc++.h>
using namespace std;
#define mid(x,y) (x+y)/2
#define pb push_back
#define lint long long
#define mp make_pair
#define st first
#define nd second 
#define N 3000009
#define girdi freopen("in.txt","r",stdin);
#define cikti freopen("out.txt","w",stdout);

long long n;

vector < long long > v;
int main(){
    //girdi 
    //cikti
    cin >> n;

    for(int i = 1; i <= sqrt(n); i++){
        if(n%i == 0){
            v.pb(i+(n/i)-2);
            //cout << i+(n/2) << i <<  endl;
        }
    }
    sort(v.begin(),v.end());
    cout << v[0];

    return 0;
}

Measured memory_bytes: 256