akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int A;
  cin >>A;
  vector<int> vec(A);
  rep(i,A) {
cin >>vec.at(i);
  }
  vector<int>vect(A);
  rep(i,A) {
vect.at(i)=i+1;
  }
  int count=0;
  rep(i,A) {
if(vec.at(i)!=vect.at(i)) {
count++;
}
  }

  if((count==2)||(count==0)) {
cout <<"YES" << endl;
  }
else {
cout <<"NO" << endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAX = 3000;
const int INF = 1e8;
#define gcd(a,b) __gcd(a,b)

struct edge{ 
  int to, cap, rev;
};

vector<edge> G[MAX];
bool used[MAX];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to ,cap ,G[to].size()});
  G[to].push_back((edge){from ,0 ,G[from].size()-1});
}

int dfs(int v,int t,int f){
  if(v == t) return f;
  used[v] = true;
  for(int i = 0 ; i < G[v].size() ; i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow = 0;

  for(;;){
    memset(used,false,sizeof(used));
    int f = dfs(s,t,INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int main(){
  int m,n,b,r;
  
  while(cin >> m >> n , m + n){
    vector<int> B,R;
    int s = m+n,t = s+1;
    memset(G,0,sizeof(G));
    for(int i = 0 ; i < m ; i++){
      cin >> b;
      B.push_back(b);
      add_edge(s,i,1);
    }

    for(int j = 0 ; j < n ; j++){
      cin >> r;
      R.push_back(r);
      add_edge(m+j,t,1);
    }
 
    for(int i = 0 ; i < m ; i++){
      for(int j = 0 ; j < n ; j++){
	if(gcd(B[i],R[j]) != 1){
	  add_edge(i,m+j,1);
	}
      }
    }
    cout << max_flow(s,t) << endl;
  }

  return 0;
}

Measured memory_bytes: 61356
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

vvl to;
vl deg;

void dfs(int v, int p) {
    for (auto nv : to[v]) {
        if (p == nv) continue;
        dfs(nv, v);
    }
    if (p == -1) return;
    if (deg[v] % 2) {
        cout<<v + 1<<" "<<p + 1<<endl;
    }
    else {
        deg[p]++;
        cout<<p + 1<<" "<<v + 1<<endl;
    }
}

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

    ll n, m;
    cin>>n>>m;
    if (m % 2) {
        cout<<-1<<endl;
        return 0;
    }

    to = vvl(n);
    deg = vl(n);
    UnionFind ds(n);
    rep(i, m) {
        ll v1, v2;
        cin>>v1>>v2; v1--; v2--;
        if (ds.issame(v1, v2)) {
            deg[v1]++;
            cout<<v1 + 1<<" "<<v2 + 1<<endl;
            continue;
        }
        to[v1].push_back(v2);
        to[v2].push_back(v1);
        ds.merge(v1, v2);
    }

    dfs(0, -1);
}

Measured memory_bytes: 13696
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string str;
    cin>>str;
    int cnt[256]={0};
    for(int i=0;i<str.length();i++)cnt[str[i]]++;
    cout<<min(min(cnt['K'],cnt['U']),min(cnt['P'],cnt['C']))<<endl;
}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))


int main()
{
    ll i,j,k,l,m,n;

    cin >> n;

    ll ar[n+10];

    for(i=0;i<n;i++)cin>>ar[i];
    sort(ar,ar+n);

    cout<<ar[n/2]-ar[n/2-1]<<endl;
}


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

int main() {
    long a, b;
    cin >> a >> b;

    long negativeCount=0;
    for (long i=a; i<b+1; ++i) {
        if (i==0) {
            cout << "Zero" << endl;
            return 0;
        } else if (i<0) {
            ++negativeCount;
        }
    }

    if (negativeCount%2 == 1) {
        cout << "Negative" << endl;
        return 0;
    } else {
        cout << "Positive" << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;

int main() {
	
	int cnt=0;
	string s;
	cin>>s;
	
	for(int i=0; i<2; ++i) {
		if(s[i]==s[i+1] && s[i]=='R') ++cnt;
	}
	
	if(cnt==0 && count(s.begin(),s.end(),'R')==0) cout<<0<<"\n";
	else if(cnt==1) cout<<2<<"\n";
	else if (cnt==2) cout<<3<<"\n";
	else cout<<1<<"\n";
	
	return 0;
	
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(int i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(int i=(a);i<(n);i++)cout<<(arr)[i]<<' ';

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

int main(){
    fast;
    ll n;
    cin>>n;
    ll a[n+2], ans = 0;
    scan(a, 1, n+1);
    forn(i, 1, n+1){
        if(a[i] == i){
            if(i < n){
                swap(a[i], a[i+1]);
                
            } else {
                swap(a[i], a[i-1]);
            }
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4284
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 

int main(void){  
  int a,b,n,m;
  while(cin>>a>>b, a){
    int count = 0;
    n = max(a,b);
    m = min(a,b);
    while(m){
      int tmp = m;
      m = n % m;
      n = tmp;
      count++;
    }
  cout << n <<" " << count << endl;
  }

}

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
//#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define tcase int _; cin>> _; for( ; _; --_)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

void solve(){
	int k;
	cin>> k >> n;

	vi v(n);

	for(int i = 0; i<n; ++i) cin>> v[i];

	int mx = 0;

	for(int i = 0; i<n; ++i){
		if(i < n-1) mx = max(mx, v[i+1] - v[i]);
		else mx = max(mx, k - v[n-1] + v[0]);
	}

	cout<< k - mx<< endl;
}

int32_t main(){
	fastio;
	solve();
	return 0;
}

Measured memory_bytes: 3992
//by Judge
#define HGS_AK_IOI true
#include<cstdio>
#include<cstring>
#include<iostream>
#define Rg register
#define ll long long
using namespace std;
const int inf=1e9+7;
const int M=1e5+3;
typedef int arr[M];
ll n,flg,now,ans;
int main(){
	cin>>n,flg=1;
	while(n){
		now=n%10,n/=10;
		if(n){
			ans+=9;
			flg&=(now==9);
		}
	} ans+=now-(!flg);
	return !printf("%lld\n",ans);
}

Measured memory_bytes: 256
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var NXT = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NXT[0]; var X = NXT[1]; var T = NXT[2];

            Console.WriteLine(((N + X - 1) / X) * T);
        }
    }
}


Measured memory_bytes: 27528
import sys

def solve(a,b):
    if a == 0 and b<=99:
        return(b)
    elif a == 1 and b<=99:
        return(100*b)
    elif a == 2 and b<=99:
        return(10000*b)
    elif a == 0:
        return(101)
    elif a == 1:
        return(10100)
    else:
        return(1010000)

def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b] = line.split(' ')
    return (int(str_a), int(str_b))

def main():
    a, b = readQuestion()
    answer = solve(a, b)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

class UnionFind{
public:
    vector<ll> par,num;

    int find(ll v){
        return (par[v]==v)? v: (par[v]=find(par[v]));
    }
    explicit UnionFind(ll N):par(N),num(N,1){
        iota(par.begin(),par.end(),0);
    }
    void unite(ll u,ll v){
        u=find(u),v=find(v);
        if(u==v)return ;
        if(num[u]<num[v])swap(u,v);
        num[u] += num[v];
        par[v] = u;
    }
    bool same(ll u,ll v){
        return find(u) == find(v);
    }
    bool ispar(ll v){
        return v=find(v);
    }
    ll size(ll v){
        return num[find(v)];
    }
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    UnionFind G(n);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        G.unite(a,b);
    }
    ll ans=0;
    rep(i,n){
        chmax(ans,(ll)G.size(i));
    }
    out(ans);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 6344
package main
 
import (
    "fmt"
)
 
func main() {
 
    var a, b int
    ans := "Odd"
 
    fmt.Scan(&a, &b)
 
  if (a * b) % 2 == 0 {
        ans = "Even"
    }
    fmt.Println(ans)
}

Measured memory_bytes: 512
<?php

fscanf(STDIN, "%s", $s);
$n = strlen($s);

$ans = array_fill(0, $n, 0);

// R
$cnt = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($s[$i] === 'R') {
        ++$cnt;
    } else {
        $ans[$i - 1] += ceil($cnt / 2);
        $ans[$i] += floor($cnt / 2);

        $cnt = 0;
    }
}

// L
$cnt = 0;
for ($i = $n - 1; $i >= 0; --$i) {
    if ($s[$i] === 'L') {
        ++$cnt;
    } else {
        $ans[$i + 1] += ceil($cnt / 2);
        $ans[$i] += floor($cnt / 2);
        $cnt = 0;
    }
}

echo implode(' ', $ans);


Measured memory_bytes: 35576
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Christmas Eve Eve Eve
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int d;
  scanf("%d", &d);

  printf("Christmas");
  while (d++ < 25) printf(" Eve");
  putchar('\n');

  return 0;
}


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

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

    map<string, int> day;
    day["SUN"] = 0;
    day["MON"] = 1;
    day["TUE"] = 2;
    day["WED"] = 3;
    day["THU"] = 4;
    day["FRI"] = 5;
    day["SAT"] = 6;

    int ans = 7 - day[S];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
const int mod=1000000007;
int N,M,K;
struct edge{int to;edge*next;}E[210],*ne=E,*fir[110];
void link(int u,int v){*ne=(edge){v,fir[u]};fir[u]=ne++;}
long long inv(int a,int p=mod){return a==1?1:(1+p*(a-inv(p%a,a)))/a%p;}
int dfn[110],low[110],now,stk[110],top,bcc[110],bcnt,vs[110],es[110];
void dfs(int i){
	dfn[i]=low[i]=++now;
	stk[top++]=i;
	for(edge*e=fir[i];e;e=e->next){
		if(!dfn[e->to]){
			dfs(e->to);
			if(low[e->to]>=dfn[i]){
				vs[++bcnt]=1;
				do bcc[stk[--top]]=bcnt,vs[bcnt]++;
				while(stk[top]!=e->to);
			}
			if(low[e->to]<low[i])low[i]=low[e->to];
		}
		else if(dfn[e->to]<low[i])low[i]=dfn[e->to];
	}
}
int pr[110],phi[110],pc,pw[110];
bool com[110];
int fac[210],ifac[210];
int main(){
	scanf("%d%d%d",&N,&M,&K);
	for(int i=0,a,b;i<M;i++)scanf("%d%d",&a,&b),link(a,b),link(b,a);
	phi[1]=1;
	for(int i=2;i<=M;i++){
		if(!com[i])pr[pc++]=i,phi[i]=i-1;
		for(int j=0;j<pc&&i*pr[j]<=M;j++){
			com[i*pr[j]]=1;
			if(i%pr[j]==0){
				phi[i*pr[j]]=phi[i]*pr[j];
				break;
			}
			phi[i*pr[j]]=phi[i]*(pr[j]-1);
		}
	}
	for(int i=*pw=1;i<=M;i++)pw[i]=1ll*pw[i-1]*K%mod;
	for(int i=*fac=1;i<=M+K;i++)fac[i]=1ll*fac[i-1]*i%mod;
	ifac[M+K]=inv(fac[M+K]);
	for(int i=M+K;i;i--)ifac[i-1]=1ll*ifac[i]*i%mod;
	int ans=1;
	for(int i=1;i<=N;i++)if(!dfn[i])dfs(i);
	for(int i=1;i<=N;i++)
		for(edge*e=fir[i];e;e=e->next)
			es[dfn[e->to]>dfn[i]?bcc[e->to]:bcc[i]]++;
	for(int i=1;i<=bcnt;i++){
		int m=es[i]/2;
		if(m==vs[i]){
			int s=0;
			for(int i=1;i<=m;i++)if(m%i==0)s=(s+1ll*pw[i]*phi[m/i])%mod;
			ans=(1ll*ans*s%mod*fac[m-1]%mod*ifac[m])%mod;
		}
		else ans=(1ll*ans*fac[m+K-1]%mod*ifac[m]%mod*ifac[K-1])%mod;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	vector<long long int> a(m);
	for (int i = 0; i < m; ++i)
	{
		cin >> a.at(i);
	}
	long long int sum=0;

	for (int i = 0; i < m; ++i)
	{
		sum = sum+a.at(i);
	}

	if(n<sum){
		cout << -1 << endl;
	}
	else{
		cout << n-sum << endl;
	}
}

Measured memory_bytes: 3712
N, M = map(int, input().split())
es = []
for i in range(M):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    es.append((a,b))
 
parent = None

def root(a):
    if parent[a] == a:
        return a
    else:
        parent[a] = root(parent[a])
        return parent[a]

def is_same(a,b):
    return root(a) == root(b)

def unite(a,b):
    ra = root(a)
    rb = root(b)
    if ra == rb: return
    parent[ra] = rb;
 
ans = 0
for i in range(M):
    parent = [k for k in range(N)]
    for j,e in enumerate(es):
        if j == i: continue
        a,b = e
        unite(a,b)
    a,b = es[i]
    if not is_same(a,b):
        ans += 1
print(ans)

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

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,i,j,temp1,temp2,y,sum=0,o,n,m,k;
    cin >> n >> m;
    m >= n ? cout << "unsafe" : cout << "safe";

}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define rep(j, n) for(int j = 0; j < (n); j++)
typedef long long ll;
typedef long double ld;
using namespace std;


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

  int a, b, c;
  cin >> a >> b >> c;

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

  return 0;
}

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

using namespace std;

int main()
{
   int n;
   cin >> n;
   if(n%2==1){
    cout << 0<< endl;
   }
   else {
   vector<int > d(n);
   for(int i=0;i<n;i++){
    cin >> d[i];
   }
   sort(d.begin(),d.end());
   int tmp=n/2;
   int k=d[tmp]-d[tmp-1];
   cout << k<< endl;

   }

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long INF = 1e6;
const long long N = 1e3 + 7;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;

ll T = 1, n, m, b, ans, y, x, c, a, used[INF], u[1001], cnt, mn = 1e18;
string s;
vector < ll > v, v1;
set< ll > st;
int main(){
    TIME
    cin >> n;
    for( int i = 1;i <= n;i ++ ){
        s = to_string(i);
        if( s.size() % 2 )
            cnt ++;
    }
    cout << cnt;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)
    cout<<k;
    else
    {
        ll ans=0;
        ans+=a;
        k-=a;
        k-=b;
        if(k<0)
        cout<<ans;
        else
        {
            ans-=k;
            cout<<ans;
        }  
    }
    
  }  
  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <sstream>
#include <math.h>
#include<string>
using namespace std;

int main(){
    int n,x,y;
    cin >> n >> x >> y;
    int ans[n-1];
    for (int i = 0; i < n-1 ; i ++){
        ans[i] = 0;
    }
    for (int i = 0; i < n - 1; i ++){
        for (int j = i + 1; j < n ; j ++){
            int dist1,dist2,dist3;
            dist1 = j - i;
            dist2 = abs(x - 1 - i) + abs(y -1 - j) + 1;
            dist3 = abs(x - 1 - j) + abs(y -1 - i) + 1;
            dist2 = min(dist2,dist3);
            dist1 = min(dist1,dist2);
            ans[dist1 - 1] ++;
        }
    }
    for (int i = 0; i < n-1 ; i ++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
program example
    implicit none

    integer(8) i,N
    integer(8),allocatable :: A(:),B(:)

    read(*,*) N

    allocate(A(1:N-1),B(N))

    read(*,*) A

    B=0

    do i=1,N-1

    B(A(i))=B(A(i))+1

    end do

    do i=1,N
        write(*,*) B(i)
    end do


end program example


Measured memory_bytes: 8984
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)

x4 = x3 - (x2 - x1)
y4 = y3 - (y2 - y1)

print(x3, y3, x4, y4)

Measured memory_bytes: 3060
#include <iostream>
int h,n;
int a[100100];
using namespace std;
int main(){
  cin>>h>>n;
  for(int i=0;i<n;++i){
    cin>>a[i];
  }
  int sum=0;
  for(int i=0;i<n;++i){
    sum+=a[i];
    if(h<=sum){
      cout<<"Yes";
      break;
    }
    if(i==n-1&&h>sum){
       cout<<"No";
    }
  }
  
 
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define debug(x) cout<<#x<<"="<<x<<endl;
#define LL long long
#define INF 9e8+7
using namespace std;
const int N=202;
int G[N][N];
int nv[10];
int mn=INF;
int main(void)
{
	int n,m,r;
	scanf("%d%d%d",&n,&m,&r);
	rep(i,0,n+1)
	{
		rep(j,0,n+1)
		{
			 G[i][j]=INF;
		}
	}
	rep(i,0,r)scanf("%d",&nv[i]);
	rep(i,0,m)
	{
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		G[u][v]=w;
		G[v][u]=w;
	}
	rep(k,1,n+1)
	{
		rep(u,1,n+1)
		{
			rep(v,1,n+1)
			{
				G[u][v]=min(G[u][v],G[u][k]+G[k][v]);
			}
		}
	}
	sort(nv,nv+r);
	mn=INF;
	do{
        int res=0;
        int u=0;
        //rep(i,0,r)printf("%d ",nv[i]);cout<<endl;
		rep(i,1,r)
		{
			res+=G[nv[u]][nv[i]];
			u=i;
		}
		mn=min(mn,res);
	}while(next_permutation(nv,nv+r));
	printf("%d",mn);
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void){
  long N,K;
  scanf("%ld %ld",&N,&K);

  if(N < K){
    if(K/2 < N){
      printf("%ld",K-N);
    }else{
      printf("%ld",N);
    }
  }else{
    long z = N%K;
    long x = N - N%K;
    long y = (N/K + 1)*K - N;

    if(z < y && z < x){
      printf("%ld",z);
    }else if(x < y){
      printf("%ld",x);
    }else{
      printf("%ld",y);
    }
  }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main() {
	ll n, k;
	cin >> n >> k;

	ll ans = 0;
	ll dw = k * (k-1) / 2;
	ll up = n * (n+1) / 2 - (n-k) * (n-k+1) / 2;
	ans += up - dw + 1;
	ans %= MOD;
	
	for (int i = k + 1; i <= n + 1; i++) {
		up += n - i + 1;
		dw += i - 1;
		ans += up - dw + 1;
		ans %= MOD;
	}

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

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;
char A[808][808];
int d[808][808];
int H,W,K,sx,sy;
int dx[4] = {0,-1,0,1};
int dy[4] = {-1,0,1,0};

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> H >> W >> K;
    // i == 0 || i == H-1 || j == 0 || j == W-1 
    // で脱出できる
    rep(i,H)rep(j,W){
        cin >> A[i][j];
        if(A[i][j]=='S'){
            sx = i;
            sy = j;
            d[sx][sy] = 1;
        }
    }
    queue<pair<int,int>> q;
    q.push({sx,sy});
    // 現在地からいける座標を全て書き出す
    while(!q.empty()){
        auto now = q.front();q.pop();
        int x = now.first;
        int y = now.second;
        rep(i,4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || ny < 0 || nx >= H || ny >= W)continue;
            if(d[nx][ny])continue;
            if(A[nx][ny]=='#')continue;
            d[nx][ny] = d[x][y] + 1;
            q.push({nx,ny});
        }
    }
    vector<pair<int,int>> can;
    rep(i,H)rep(j,W){
        if(d[i][j]!=0 && d[i][j] <= K+1)can.push_back({i,j});
    }
    int ans = 1e9 + 7 ;
    for(auto now:can){
        int x = now.first;
        int y = now.second;
        int t = 1;
        int can1 = (abs(0-y)+K-1)/K;
        int can2 = (abs(W-1-y)+K-1)/K;
        int can3 = (abs(0-x)+K-1)/K;
        int can4 = (abs(H-1-x)+K-1)/K;
        t += min({can1,can2,can3,can4});
        ans = min(ans,t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 13676
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

#define REP(idx, end) for(int idx = 0; idx < end; ++idx)

using namespace std;
typedef long long lint;
const int MOD = 1000000007;

int main() {

	cin.tie(0);

	int X;
	cin >> X;

	if (X >= 1200)cout << "ARC";
	else cout << "ABC";

	return 0;
}

Measured memory_bytes: 256
min2 = lambda x,y: x if x < y else y

def solve(H,W,h,w):

    if h == 1 and w == 1:
        return None

    res = [[0]*W for _ in range(H)]



    for i in range(0,W,w):
        for j in range(0,H,h):
            res[j][i] = 10**9-1
            if i+w-1 < W and j+h-1 < H:
                res[j+h-1][i+w-1] = -10**9

    s = sum(sum(l) for l in res)
    if s <= 0:
        return None
    else:
        return res




if __name__ == '__main__':
    H,W,h,w = map(int,input().split())
    res = solve(H,W,h,w)

    if res:
        print('Yes')
        print('\n'.join(' '.join(map(str,l)) for l in res))
    else:
        print('No')

Measured memory_bytes: 88728
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){

    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<endl;


    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
using System;

    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            int cou = 0;
            string[] num = Console.ReadLine().Split(' ');
            a = int.Parse(num[0]);
            b = int.Parse(num[1]);
            c = int.Parse(num[2]);

            while (a <= b)
            {
                if (c % a == 0)
                {
                    cou++;
                }    
                a++;
            }
            Console.WriteLine(cou);
        }
    }



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

int main() {

  /* input Red card data */
  int N;
  cin >> N;
  string Red[N];
  for(int i=0;i<N;i++){
    cin >> Red[i];
  }
  
  /* input data Blue card*/
  int M;
  cin >> M;
  string Blue[M];
  for(int i=0;i<M;i++){
    cin >> Blue[i];
  }
    
  /* card counting */
  vector<int> count(N+M);
  for(int i=0;i<N;i++){
    for(int j=i;j<N;j++){
      if(Red[i]==Red[j]){
          count.at(i)++;
      }
    }
    for(int k=0;k<M;k++){
      if(Red[i]==Blue[k])
        count.at(i)--;
    }
  }
    
  /* output data */
  int output =0;
  for(int i=0;i<N;i++)
  {
    output=max(output,count.at(i));
  }
  
  cout << output << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *pre;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer S = nil->next;
  while( S != nil && S->key != key ){
    S = S->next;
  }
  return S;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil -> next = nil;
  nil -> pre = nil;
}

void printList(){
  NodePointer S = nil->next;
  int s = 1;
  while(1){
    if ( S == nil ) break;
    if ( s == 0)  printf(" ");
    printf("%d", S -> key);

    S = S -> next;
    s = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t -> pre ->next = t->next;
  t -> next ->pre = t->pre;
  
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil -> pre;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t = listSearch(key);
  if ( t == nil ) return;
  deleteNode(t);
}


void insert(int key){
  NodePointer a;
  a = malloc(sizeof(struct node));
  a -> key = key;
  a -> next = nil->next;
  nil -> next->pre = a;
  nil -> next = a;
  a -> pre = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char S[20];
  int p = 0, d = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", S, &key);
    if(!( 0 <= key && key <= 2000000000)){printf("error") ;}
    if ( S[0] == 'i' ) {insert(key); p++; size++;}
    else if ( S[0] == 'd' ) {
      if (strlen(S) > 6){
	if ( S[6] == 'F' ) deleteFirst();
	else if ( S[6] == 'L' ) deleteLast();
      } else {
	delete(key); d++; 
      }
      size--;
    }
    if ( size > 1000000000 ) { printf("error"); }
  }

  
  if(!( p+d <= 2000000)){printf("error") ;}
  if(!( d <= 20)){printf("error") ;}
  printList();


  return 0;
}

Measured memory_bytes: 34976
int main(void){
	
	int S,h,m,s,hh,mm,ss;
	
	scanf("%d",&S);
	
	h=S/3600;
	
	hh=S%3600;
	
	S=hh;
	
	
	m=S/60;
	
	mm=S%60;
	
	S=mm;
	
	
	s=S;
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}


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

int main() { //b
    int64_t n;
    cin >> n;
    int64_t a = (1 + n)*n / 2;
    int64_t m3 = n / 3;
    int64_t m5 = n / 5;
    int64_t m15 = n / 15;
    int64_t b = m3*(2*3 + (m3-1)*3)/2;
    int64_t c = m5*(2*5 + (m5-1)*5)/2;
    int64_t d = m15*(2*15 + (m15-1)*15)/2;
    int64_t ans = a - b - c + d;
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <bitset>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, m;

main(){
	while(cin >> n, n){
		vector< bitset<100> > have(n);
		REP(i, n){
			cin >> m;
			REP(j, m){
				int t;
				cin >> t;
				have[i].set(t-1);
			}
		}
		bitset<100> l;
		cin >> m;
		REP(j, m){
			int t;
			cin >> t;
			l.set(t-1);
		}
		int ans = -2;
		REP(i, n){
			if((have[i] & l) == l){
				if(ans == -2) ans = i+1;
				else ans = -1;
			}
		}
		if(ans == -2) ans = -1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#n=int(input())
#h1,m1,h2,m2,k=map(int,input().split())
#a=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
#l=[list(input().split()) for i in range(n)]

t=list(input())
n=len(t)
m=""
for i in range(n):
    if t[i]=="?":
        m+="D"
    else:
        m+=t[i]
print(m)


Measured memory_bytes: 10880
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize
#define ini ll_MAX
#define inl LLONG_MAX
#define MOD 1000000007
#define sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define F0R(i, a) for (ll i = 0; i < (a); i++)
#define FORR(i, a, b) for (ll i = a; i >= (b); i--)
#define F0RR(i, a) for (ll i = a; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define pbds tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
 
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
 
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
 
ll mod(ll a,ll b)
{
    return (b+a%b)%b;
}
 
ll gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ll po(ll a,ll b)
{
    ll ans = 1;
    while(b--)
        ans*=a;
    return ans;
}
ll pom(ll a,ll b,ll mod)
{
    if(b==0)return 1;
    ll k = pom(a,b/2,mod);
    if(b%2==0)return (k*k)%mod;
    else return ((k*k)*mod*a)%mod;
}
 
double sqdist(double a,double b,double c,double d)
{
    return (a-c)*(a-c)+(b-d)*(b-d);
}
ll fact(ll n)
{
    if(n==0)return 1;
    ll ans = 1;
    FOR(i,1,n+1)ans*=i;
    return ans;
}
 

void solve()
{
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    h+=m/60;
    double thetah = 2 * M_PI / 12 * h;
    double thetam = 2 * M_PI / 60 * m;



    double hx = sin(thetah)*a, hy = cos(thetah)*a, mx = sin(thetam)*b,my = cos(thetam)*b;
    // cout<<hx<<' '<<hy<<' '<<mx<<' '<<my<<endl;
    printf("%0.10f",sqrt(sqdist(hx,hy,mx,my)));
}   
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    solve();
}

Measured memory_bytes: 4020
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author indy256
 */

#include <bits/stdc++.h>

using namespace std;

struct edge {
    int v, col, index;

    edge(int v, int col, int index) : v{v}, col{col}, index{index} {}
};

void dfs(vector<vector<edge>> &t, int u, int p, int pcol) {
    int col = 0;
    for (edge &e:t[u]) {
        if (e.v == p)continue;
        ++col;
        if (col == pcol)++col;
        e.col = col;
        dfs(t, e.v, u, col);
    }
}

void solve(istream &in, ostream &out) {
    int n;
    in >> n;

    vector<vector<edge>> t(n);

    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        in >> a >> b;
        --a;
        --b;
        t[a].emplace_back(b, 0, i);
        t[b].emplace_back(a, 0, i);
    }

    dfs(t, 0, -1, -1);
    int mx = 0;
    vector<int> res(n - 1);
    for (int i = 0; i < n; ++i) {
        for (edge e:t[i]) {
            mx = max(mx, e.col);
            if (e.col)
                res[e.index] = e.col;
        }
    }

    out << mx << '\n';
    for (int i = 0; i < n - 1; ++i) {
        out << res[i] << '\n';
    }
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solve(in, out);
}


Measured memory_bytes: 8320
#include <iostream>
#include <string>
using namespace std;
#define MOD 1000000007

long n, dp[2][100010];
string s;

int main(){
	cin >> s;
	n = s.size();
	dp[0][0] = 1;
	dp[1][0] = 0;
	for (int i = 1; i <= n; ++i){
		if (s[i-1] == '1'){
			dp[0][i] = (2*dp[0][i-1]) % MOD;
			dp[1][i] = ((3*dp[1][i-1]) % MOD + dp[0][i-1]) % MOD;
		}
		else{
			dp[0][i] = dp[0][i-1];
			dp[1][i] = (3*dp[1][i-1]) % MOD;
		}
	}
	printf("%ld\n", (dp[0][n] + dp[1][n]) % MOD);
}

Measured memory_bytes: 2048
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	string S;
	cin >> S;

	string T;
	cin >> T;

	int result = T.size();
	for (int i = 0; i <= (S.size() - T.size()); i++)
	{
		int check_max_diff = 0;
		for (int j = 0; j < T.size(); j++)
		{
			if (S[i + j] != T[j])
			{
				check_max_diff++;
			}
		}

		result = min(result, check_max_diff);
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 3640
#include <cstdio>
const int MAXM = 10;
int P[MAXM], S[MAXM];
int M, N;

int bitcount_mod2(int n) {
    return n ? __builtin_popcount(n) & 1 : 0;
}

bool good(int mask) {
    for (int i = 0; i < M; ++i) {
        if (bitcount_mod2(mask & S[i]) != P[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    scanf(" %d%d", &N, &M);
    for (int i = 0; i < M; ++i) {
        int K, s;
        S[i] = 0;
        scanf("%d", &K);
        for (int j = 0; j < K; ++j) {
            scanf("%d", &s);
            S[i] |= 1 << (s-1);
        }
    }
    for (int i = 0; i < M; ++i) {
        scanf("%d", &P[i]);
        P[i] &= 1;
    }
    int L = 1 << N;
    int ret = 0;
    for (int mask = 0; mask < L; ++mask) {
        if (good(mask)) {
            ++ret;
        }
    }
    printf("%d\n", ret);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  string a, b, c;
  cin >> a;
  cin >> b;
  cin >> c;
  cout << a.at(0) << b.at(1) << c.at(2) << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[110],aa,bb,max,s;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int j=0;j<n;j++)
	{
		max=0;
		for(int k=0;k<n;k++)
		{
			if(a[k]>max)
			{
				max=a[k];
				s=k;
			}
		}
		a[s]=0;
		if((j+2)%2==0)
		{
			aa+=max;
		}
		else
		{
			bb+=max;
		}
	} 
	cout<<aa-bb;
	return 0;
}

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



long long n, k, a[200005], f[200005];


bool possible(long long val) {
	long long kk = k;
	for (int i = 0; i < n; ++i) {
		if (a[i] * f[i] <= val) continue;
		//cerr << "a : " << a[i] << ", f : " << f[i] << ", a*F: " << a[i] * f[i] << ",,,, k used : " << (a[i] - val / f[i]) <<  endl;
		kk -= (a[i] - val / f[i]);
		if (kk < 0) return false;
	}
	return true;
}



int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> k;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) cin >> f[i];
	sort (a, a + n);
	sort (f, f + n, greater<long long>());


	// for (int i = 0; i < n; ++i) cout << a[i]  << " ";
	// cout << endl;
	// for (int i = 0; i < n; ++i) cout << f[i] << " ";
	// cout << endl;


	long long l = 0, r = 1e18, m;
	
	while (true) {
//		cerr << l << ",  " << r << endl;
		if (possible(l)) {
//			cerr << l << " is possible. ";
			cout << l << endl;
			return 0;
		}
		m = (l + r) >> 1;
//		cerr << "possible " << m << endl;
		if (possible(m)) {
			r = m;
		} else {
			l = m + 1;
		}
	}
	


	return 0;
}

Measured memory_bytes: 3328
n=int(input())
d=[list(input()) for i in range(n)]
count=0
ans=0
for i in range(n):
  d[i].sort()
d.sort()

for i in range(n-1):
  if d[i]==d[i+1]:
    count+=1
  elif d[i]!=d[i+1]:
    x=count+1
    count=0
    ans+=(x*(x-1))/2
  if i==(n-2):
    x=count+1
    count=0
    ans+=(x*(x-1))/2
  
print(int(ans))

Measured memory_bytes: 24652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

int w, h;
int c[50][50];

void dfs(int cx, int cy) {
    for (int dx = -1; dx <= 1; dx++) {
        for (int dy = -1; dy <= 1; dy++) {
            int nx = cx + dx, ny = cy + dy;
            if (0 <= nx && nx < h && 0 <= ny && ny < w && c[nx][ny] != 0) {
                c[nx][ny] = 0;
                dfs(nx, ny);
            }
        }
    }
}

int main() {
    while (cin >> w >> h && w && h) {
        for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> c[i][j];
        int ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (c[i][j] == 0) continue;
                dfs(i, j);
                ans++;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3184
N = int(input())
H = [int(x) for x in input().split()]

dp = [0 for x in range(N + 1)]
dp[2] = abs(H[1] - H[0])

for i in range(3, N + 1):
  dp[i] = min(dp[i - 1] + abs(H[i - 1] - H[i - 2]), dp[i - 2] + abs(H[i - 1] - H[i - 3]))

print(dp[N])


Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
#define rep(it,st,en) for(int it=(st);it<(int)(en);++it)
#define all(c) (c).begin(), (c).end()
#define debug(x) cerr << #x << " = " << x << endl
#define eb emplace_back
#define X first
#define Y second
typedef long double ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<int,int> pii;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, X;
    cin >> n >> X;
    vi x(n), pre(n+1,0);
    rep(i,0,n) cin>>x[i];
    rep(i,0,n) pre[i+1] = x[i] + pre[i];
    ll best = 1/.0;
    rep(k,1,n+1) {
      ll cost = n*X + X*k;
      ll r = n;
      for(int s = 0; r; ++s) {
        ll l = max(ll(0),r-k);
        ll coeff = s ? 2*s+3 : 5;
        cost += (pre[r] - pre[l])*coeff;
        r = l;
      }
      //cerr << k << " " << cur << endl;
      best = min(best, cost);
    }
    cout << ((long long)best) << endl;
    return 0;
}


Measured memory_bytes: 6528