akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 100100;
int a[maxn];
int res = 0;
vector<int> g[maxn];
int k;

int dfs(int u) {
    int h = 0;
    for (int v: g[u]) {
        int cur = dfs(v) + 1;
        assert(cur <= k);
        if (cur == k && u != 0)
            ++res;
        else
            h = max(h, cur);
    }
    return h;
}

int main() {
    #ifdef LOCAL
    assert(freopen("d.in", "r", stdin));
    #else
    #endif
    int n;
    cin >> n >> k;
    forn (i, n) {
        cin >> a[i];
        --a[i];
    }
    if (a[0] != 0) {
        ++res;
        a[0] = 0;
    }
    forn (i, n) {
        if (i == 0)
            continue;
        g[a[i]].push_back(i);
    }
    dfs(0);
    cout << res << '\n';
}

Measured memory_bytes: 10752
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Queue<int>[] Q = new Queue<int>[N];
		for(int i=0;i<N;i++){
			Q[i] = new Queue<int>();
			for(int j=0;j<M;j++) Q[i].Enqueue(A[i][j]);
		}
		int min = N;
		HashSet<int> H = new HashSet<int>();
		for(int i=0;i<M;i++) H.Add(i);
		
		while(H.Count>0){
		//for(int t=0;t<M;t++){
			bool chk = true;
			for(int i=0;i<N;i++){
				while(Q[i].Count>0 && !H.Contains(Q[i].Peek())) Q[i].Dequeue();
				if(Q[i].Count == 0) chk = false;
			}
			if(!chk) break;
			
			int[] cnt = new int[M];
			for(int i=0;i<N;i++){
				var n = Q[i].Peek();
				cnt[n]++;
			}
			int mx = 0;
			for(int i=0;i<M;i++) mx = Math.Max(cnt[i],mx);
			min = Math.Min(min,mx);
			
			HashSet<int> hs = new HashSet<int>();
			for(int j=0;j<M;j++) if(cnt[j] == mx) hs.Add(j);
			
			for(int i=0;i<N;i++){
				if(hs.Contains(Q[i].Peek())) Q[i].Dequeue();
			}
			for(int j=0;j<M;j++){
				if(cnt[j] == mx)H.Remove(j);
			}
			
			chk = true;
			for(int i=0;i<N;i++){
				while(Q[i].Count>0 && !H.Contains(Q[i].Peek())) Q[i].Dequeue();
				if(Q[i].Count == 0) chk = false;
			}
			if(!chk) break;
			//Console.WriteLine(String.Join(" ",H.ToArray()));
		}
		
		Console.WriteLine(min);
		
	}
	int N,M;
	int[][] A;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		A = new int[N][];
		for(int i=0;i<N;i++){
			A[i] = ria();
			for(int j=0;j<M;j++) A[i][j]--;
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 18648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> data(6);
  int result=0;
  for (int i = 0; i < 2; i++) {
    cin >> data.at(i);
  }
  for (int i = 0; i < 2; i++) {
  
    if(data.at(0) >= data.at(1)){
    result += data.at(0);
    data.at(0)--;
    }
    else
    {
    result += data.at(1);
    data.at(1)--;
    }
    /* code */
  }
  
     
     
  
  
 
      cout << result << endl;
  
  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <set>

int main(void) {
	int n, m; std::cin >> n >> m;
	std::vector<int> numbers(n); for (auto& a : numbers) std::cin >> a;
	std::priority_queue<int> greater, less;
	for (auto i = 0; i < n; ++i) {
		if (i > numbers[i]) {
			greater.push(-i);
			less.push(numbers[i]);
		}
		else {
			greater.push(-numbers[i]);
			less.push(i);
		}
	}
	for (auto i = 0; i < m; ++i) {
		if (less.top() + greater.top() > 0) {
			const auto l = less.top(); less.pop();
			const auto g = greater.top(); greater.pop();
			less.push(-g);
			greater.push(-l);
		}
		else break;
	}
	long long int result = 0;
	for (auto i = 0; i < n; ++i) {
		result += -less.top() + -greater.top();
		less.pop(); greater.pop();
	}
	std::cout << result << std::endl;
}



Measured memory_bytes: 4400
D = int(input())
C = list(map(int, input().split()))
S = []
con= 0
for _ in range(D):
    S.append(list(map(int, input().split())))
t = [-1]*D
best = [0]*D
last = [0]*26

for i in range(D-2):#1日ごと
    
    score = [-1]*26
    
    for x in range(26):#どの問題を選ぶか
        if i==0:
            con = 0
        else:
            con = best[i-1]
        
        con += S[i][x]
        #last[x] = i+1
        for j in range(26): #減少量の計算 #問題ごと
            if not j==x:
                con -= C[j]*(i-last[j]+1)

        score[x]=con
    m = -100000
    ii = 0
    for k in range(26):
        if m<score[k]:
            m=score[k]
            ii=k
    
    last[ii]=i+1
    best[i]=score[ii]
    t[i]=ii+1

p2 = [0]*(26**2)


for i in range(26):
    for j in range(26):
        #print(i*26+j)
        p2[i*26+j]+=S[D-2][i]
        p2[i*26+j]+=S[D-1][j]
        for k in range(26):
            if not k==i:
                p2[i*26+j] -= C[k]*(25-last[k])
        for k in range(26):
            if not k==j:
                if k==i:
                    p2[i*26+j] -= C[k]*2
ma = 0
ind = 0
for h in range(26**2):
    if p2[h]>ma:
        ma=p2[h]
        ind = h
t[D-2]= h//26
t[D-1]=h%26
        
    
    
    
    
for i in range(D):
    print(t[i])
#print(best)



Measured memory_bytes: 68720
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}


int a[200005];

void solve(){
   string s;
   cin >> s;

   int n = s.size();
   int cur = 0;

   int lef = 0, rig = 0, l, r;

   for(int i = 0;i<n;i++){
        lef = 0;
        rig = 0;

        while(s[i]=='R'){
            lef++;
            i++;
        }

        l = i-1;
        r = i;

        while(s[i]=='L'){
            rig++;
            i++;
        }
        //cout << lef << " " << rig << endl;
        if((lef+rig)%2==0){
            a[l] = (lef+rig)/2;
            a[r] = a[l];
        }
        else{
            a[l] = (lef+rig)/2;
            a[r] = a[l];

            if(lef%2){
                a[l]++;
            }
            else
                a[r]++;
        }
        i--;
   }



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

} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 1488
#include<bits/stdc++.h>
using namespace std;
int n,m,x[100],y[100],i=0,j,k;
double ans,d[205],P=acos(-1);
main(){
	cin>>n;m=n;
	while(m--)cin>>x[n-m-1]>>y[n-m-1];
	for(i=0;i<n;i++){
		k=ans=0;
		for(j=0;j<n;j++)if(i-j)d[k++]=atan2(y[j]-y[i],x[j]-x[i]);
		sort(d,d+k);
		for(j=0;j<k;j++)d[j+k]=d[j]+2*P;
		for(j=0;j<k;j++)ans=max(ans,P-d[j+k-1]+d[j]);
		cout<<ans/2./P<<'\n';
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int H,N;
	cin>>H>>N;
	vector<pair<int,int>> a(N);
	fore(a,&p) cin>>p.first>>p.second;

	vector<int> best(H+1,(int)1e9);
	rep(i,1,H+1) {
		fore(a,&p) {
			if (i>p.first) best[i]=min(best[i],best[i-p.first]+p.second);
			else best[i]=min(best[i],p.second);
		}
	}
	cout<<best[H]<<'\n';
}


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

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
#define MP make_pair
#define FF first
#define SS second

const int MAX = 370;
const int INF = 1e9;
int dp[2][MAX][MAX];
int main(){
  int N;
  while(cin>>N,N){
	vector<pair<PII,int>> xs(N);
	for(int i=0;i<N;++i)
	  cin >> xs[i].FF.FF >> xs[i].FF.SS >> xs[i].SS;
	sort(xs.begin(), xs.end());

	fill((int*)dp, (int*)dp+2*MAX*MAX, -INF);
	int crt = 0, nxt = 1;
	dp[crt][0][0] = 0;
	for(int i=0;i<N;++i){
	  for(int k=0;k<MAX;++k)
		for(int j=0;j<MAX;++j)
		  dp[nxt][k][j] = dp[crt][k][j];

	  for(int b=0;b<MAX;++b)
		for(int j=0;j<xs[i].FF.FF;++j)
		  dp[nxt][xs[i].FF.SS][b] = max(dp[nxt][xs[i].FF.SS][b], dp[crt][j][b]+xs[i].SS);
	  for(int a=0;a<MAX;++a)
		for(int j=0;j<xs[i].FF.FF;++j)
		  dp[nxt][a][xs[i].FF.SS] = max(dp[nxt][a][xs[i].FF.SS], dp[crt][a][j]+xs[i].SS);
	  swap(crt, nxt);
	}

	int ans = 0;
	for(int i=0;i<MAX;++i)
	  for(int j=0;j<MAX;++j)
		ans = max(ans, dp[crt][i][j]);
	cout << ans << endl;
	/*
	for(int i=0;i<10;++i){
	  for(int j=0;j<10;++j)cout<<dp[i][j]<<" ";
	  cout<<endl;
	}
	*/
  }
  
  return 0;
}

Measured memory_bytes: 2276
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>

#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)

using namespace std;


int main() {
  ios::sync_with_stdio(false);
  int W, a, b, a1, a2, b1, b2;
  while (cin >> W >> a >> b) {
    a1 = a; a2 = a + W;
    b1 = b; b2 = b + W;
    if ((a1 <= b1 && b1 <= a2) || (b1 <= a1 && a1 <= b2)) cout << 0 << endl;
      else if (a2 < b1) cout << (b1 - a2) << endl;
       else cout << (a1 - b2) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX =100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
int n,M[MAX][MAX];
int prim(){
  int u,minv;
  int d[MAX],p[MAX],color[MAX];
  for(int i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    minv = INFTY;
    u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(int v=0;v<n;v++){
      if(color[v]!=BLACK&&M[u][v]!=INFTY){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  int sum=0;
  for(int i=0;i<n;i++){
    if(p[i]!=-1)sum+=M[i][p[i]];
  }
  return sum;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int e; cin>>e;
      M[i][j]=(e==-1)?INFTY:e;
    }
  }
  cout<<prim()<<endl;
  return 0;
}
  



Measured memory_bytes: 3128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if ( (a + b) % 2 == 0 ) {
                System.out.println((a + b) / 2);
            } else {
                System.out.println((a + b) / 2 + 1);
            }
        }
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

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

Measured memory_bytes: 1152
n = int(input())
for i in range(n):
    xa,ya,ra,xb,yb,rb = map(float,input().split())
    dis = (xa - xb)**2 + (ya - yb)**2
    if dis > (ra + rb)**2:
        print(0)
    elif rb > ra and dis < (rb - ra)**2:
        print(-2)
    elif ra > rb and dis < (ra - rb)**2:
        print(2)
    else:
        print(1)

Measured memory_bytes: 7656
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    print(int(n**0.5)**2)
    return


if __name__ == "__main__":
    main()


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

using namespace std;

long long n,q,m,k,t,l;


int main(){
    vector<int>v(3,0);
    cin>>v[0]>>v[1]>>v[2];
    sort(v.begin(), v.end());
    if (v[0]==5 and v[1]==5 and v[2]==7){
        cout<<"YES";
        return 0;
    }
    cout<<"NO";
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    vector<int>p(N);
    rep(i,N)cin >> p[i];
    int ans=0;
    rep(i,N){
        if(i<N-1){
            if(p[i]==i+1){
                ans++;
                swap(p[i],p[i+1]);
            }
        }
        else{
            if(p[i]==i+1){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
const int N = 1e2+5;

ll n , a[N] , cost[N][15] , ans=-1e18;

void solve(int bt , int cur)
{
    if (bt == 10)
    {
        ll sum=0 , tmp , c;
        c = __builtin_popcount(cur);
        if (c == 0) return;

        for(int i=1; i<=n; i++)
        {
            tmp = cur&a[i];
            c = __builtin_popcount(tmp);
            sum += cost[i][c];
        }
        ans = max(ans , sum);
        return;
    }

    solve(bt+1 , cur);
    solve(bt+1 , cur|(1<<bt));
}

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

    cin >> n;
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<10; j++)
        {
            int x;
            cin >> x;
            if (x) a[i] |= (1<<j);
        }
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<11; j++)
            cin >> cost[i][j];
    }

    solve(0,0);
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

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

  double res = 0;
  for (int i = 1; i <= n; i++)
  {
    if (i < k)
    {
      res += pow(0.5, ceil(log2((double)k / i)));
    }
    else
    {
      res++;
    }
  }

  cout << std::fixed << std::setprecision(11) << res / n << endl;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, X, Y;
  cin >> N >> X >> Y;
  X--, Y--;
  vector<int> ans(N);
  for (int i = 0; i < N; i++)
  {
    for (int j = i + 1; j < N; j++)
    {
      if (i == j)
        continue;
      else
      {
        ans[min({j - i, abs(X - i) + abs(j - Y) + 1, abs(Y - i) + abs(X - j) + 1})]++;
      }
    }
  }
  for (int i = 1; i < N; i++)
  {
    cout << ans[i] << endl;
  }
  return 0;
}

// iとjが重ならないように
// i < j, X + 1 < Yとなるからiとjの最短距離はj - i, iとX，jとY，がつながっている場合を考えてmin(j - i, abs(i - X) + abs(j - Y) + 1)となる
// 頂点iとY，頂点jとXが繋がっている場合も考えてabs(i - Y) + abs(j - X) + 1も加える
// 何も考えずにBFS，アドホックに求める


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));

    // b[i] = (a[i]-1,i)のWL
    vector<ll> b(n);
    REP(i, n) {
        if(i>=1 && a[i]==a[i-1]) b[i] = 1-b[i-1];
        else b[i] = 0;
    }
    // 左上に斜め移動
    ll x=n-1, y=0;
    while(x>=1 && y+1<a[x-1]) x--, y++;

    // 左に行く
    ll cnt = 0, xx = x, yy = y;
    while(xx-1 >= 0 && yy != a[xx]-1) {
        xx--;
        cnt++;
    }
    cnt += b[xx];
    ll left = cnt % 2;
    // 上に行く
    cnt = 0, xx = x, yy = y;
    while(yy < a[xx]-1) {
        yy++;
        cnt++;
    }
    cnt += b[xx];
    ll up = cnt % 2;

    if(left || up) cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    ll n , a, b; cin >> n >> a >>b;

    ll ans = n % (a+b);
    if(ans<=a) cout << n/(a+b) * a + ans<< endl;
    else cout << n/(a+b) * a + a << endl;
    return 0;
}


Measured memory_bytes: 256
loop do
  catch :a do
    s = gets.chomp
    exit if s == "."

    stack = []
    s.chars.each do |ch|
      if ((ch == ")" || ch == "]") && stack.empty?) || (ch == ")" && stack.last == "[") || (ch == "]" && stack.last == "(")
        puts "no"
        throw :a
      end
      stack.push ch if ch == "("
      stack.pop if ch == ")" && stack.last == "("
      stack.push ch if ch == "["
      stack.pop if ch == "]" && stack.last == "["
    end

    puts stack.empty? ? "yes" : "no"
  end
end

Measured memory_bytes: 8748
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    IOS
    int h, w;
    cin >> h >> w;
    char s[h][w];
    for (int i = 0; i < h; i++)for (int j = 0; j < w; j++) cin >> s[i][j];
    bool flag = true, check;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                check = false;
                if ((j+1 < w && s[i][j+1] == '#') || (j-1 >= 0 && s[i][j-1] == '#') || (i+1 < h && s[i+1][j] == '#') || (i-1 >= 0 && s[i-1][j] == '#')) {
                    check = true;
                }
                if (!check) flag = false;
            }
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

struct node{
  struct node *parent;
  struct node *left;
  struct node *right;
  int key;
};

typedef struct node Node;
Node *root,*NIL;

void Insert(int id){
  Node *x,*y,*z;
  y = NIL;
  x = root;

  z = (Node *)malloc(sizeof(Node));
  z->key = id;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
  
};
void Inorder(Node *id){
  if(id==NIL)return;

  Inorder(id->left);
  printf(" %d",id->key);

  Inorder(id->right);
};
void Preorder(Node *id){
  if(id==NIL)return;

  printf(" %d",id->key);
  
  Preorder(id->left);
  Preorder(id->right);
};

int main(){

  int i,n,id;
  char order[MAX];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){ //parent
    scanf("%s",order);
    if(strcmp(order,"insert")==0){
      scanf("%d",&id);
      Insert(id);
    }
    else{
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
  }

  return 0;
}

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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    int ans = 0;

    vector<int> ak(m+1);

    for (int i = 0; i < n; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int a; cin >> a;
            ak[a]++;
        }
    }

    for (int i = 1; i <= m; i++) {
        if (ak[i] == n) ans++;
    }

    cout << ans;
    return 0;
} 


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF (1<<30)

int cnt(int a){
	int ans=0;
	while(a%2==0){
		ans++;
		a /= 2;
	}
	return ans;
}

int main(void){
	int n,a,i,ans=INF;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> a;
		ans = min(ans,cnt(a));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()
	numN := strings.Count(s, "N")
	numS := strings.Count(s, "S")
	numW := strings.Count(s, "W")
	numE := strings.Count(s, "E")

	if numN == 0 && numS != 0 {
		fmt.Println("No")
		return
	}
	if numN != 0 && numS == 0 {
		fmt.Println("No")
		return
	}
	if numW == 0 && numE != 0 {
		fmt.Println("No")
		return
	}
	if numW != 0 && numE == 0 {
		fmt.Println("No")
		return
	}
	fmt.Println("Yes")
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int find_(int x,vector<int> &v){
    if(v[x]<0) return x;
    v[x]=find_(v[x],v);
    return v[x];
}

int same_(int a,int b,vector<int> &v){
    if(find_(a,v)==find_(b,v)) return 1;
    return 0;
}

void union_(int a,int b,vector<int> &v){
    if(same_(a,b,v)) return;
    int a_p=find_(a,v),b_p=find_(b,v);
    if(a_p>b_p) swap(a_p,b_p);
    v[a_p]+=v[b_p]; v[b_p]=a_p;
}

void print_v(vector<int> v){
    rep(i,v.size()) cout<<v[i]<<" ";
    cout<<endl;
}

int main() {
    int n,m,ans=0; cin>>n>>m;
    vector<int> p(n,0),v(n,-1);
    rep(i,n){
        cin>>p[i]; p[i]--;
    }
    rep(i,m){
        int x,y; cin>>x>>y;
        union_(x-1,y-1,v);
    }
    rep(i,n) if(same_(i,p[i],v)) ans++;
    cout<<ans<<endl;
}

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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
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; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

int _runtimeTerror_()
{
    string s,t;
    cin>>s>>t;
    int n = s.size(),m=t.size();
    ll ans = INF;
    for(int i=0;i<n-m+1;++i)
    {
        int cnt = 0;
        for(int j=0;j<m;++j)
            cnt+=s[i+j]!=t[j];
        amin(ans,cnt);
    }
    cout<<ans<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

Measured memory_bytes: 3644
def abc052_b():
    n = int(input())
    s = str(input())
    now, ans = 0, 0
    for char in s:
        if char == 'I':
            now += 1

            if now >= ans:
                ans = now
        else:
            now -= 1

    return ans


if __name__ == '__main__':
    print(abc052_b())


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n, m, c, ans;
struct node {
	int x, y;
}e[maxn];
il bool cmp(node a, node b) {
	return a.x < b.x;
}
int main() {
	n = read();
	rep(i, 1, n) e[i].x = read(), e[i].y = read();
	rep(i, 1, n) {
		int pax = e[i].y;
		e[i].y = e[i].x + pax, e[i].x = e[i].x - pax + 1;
	}
	sort(e + 1, e + n + 1, cmp);
	//rep(i, 1, n) cout << e[i].x << ' ' << e[i].y << endl;
	ans = 1, c = e[1].y;
	rep(i, 2, n) {
		if(e[i].x <= c) c = min(c, e[i].y);
		else c = e[i].y, ++ ans;
	} 
	printf("%d", ans);
	return 0;
}


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

using namespace std;
typedef long long ll;

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

  int ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = i; j < s.size(); ++j) {
      bool is_valid = true;
      for (int k = i; k <= j; ++k) {
	if (s[k] != 'A' && s[k] != 'C' && s[k] != 'G' && s[k] != 'T') is_valid = false;
      }
      if (is_valid) ans = max(ans, j - i + 1);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n, ans = 0;
    cin >> n;
    int upper = (int)pow(n, 0.5);
    for(int a = 1; a < n + 1; ++a){
        for(int i = 1; i < upper; ++i){
            for(int j = 1; j < i + 1; ++j){
                for(int k = 1; k < j + 1; ++k){
                    if(i*i+j*j+k*k+i*j+j*k+k*i == a){
                        ans++;
                        if(i == j && j == k) continue;
                        else if(i != j && j != k && k != i) ans += 5;
                        else ans += 2;
                    }
                }
            }
        }
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}

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

int main(){
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	cout << (char)(s1[0] - ('a' - 'A')) << (char)(s2[0] - ('a' - 'A')) << (char)(s3[0] - ('a' - 'A'));
	return 0;
}



Measured memory_bytes: 256
//
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    ll n, m;
    cin >> n >> m;
    vl a(n);
    ll total = 0;
    rep(i, n) cin >> a[i], total += a[i];
    vl rui(n + 1);
    sort(all(a));
    rep(i, n){
        rui[i + 1] = rui[i] + a[i];
    }
    ll l = 0, r = 2 * a[n - 1] + 1;
    while(r - l > 1){
        ll mid = (l + r) / 2;
        ll tmp = 0;
        rep(i, n){
            int idx = lower_bound(all(a), mid - a[i]) - a.begin();
            tmp += n - idx;
        }
        if(tmp >= m){
            l = mid;
        }else{
            r = mid;
        }
    }
    ll ans = 0;
    ll tmp = 0;
    rep(i, n){
        int idx = lower_bound(all(a), l - a[i]) - a.begin();
        tmp += n - idx;
        ans += total - rui[idx] + a[i] * (n - idx);
    }
    cout << ans-(tmp-m)*l << endl;
    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<stdio.h>
#include<string>
#include<deque>
using namespace std;
int x;
long long n,a,b,c,tmp,flg,t[4001],u[4001],v[4001];
deque<int>deq;
int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		for(int i=0;i<4001;i++){v[i]=t[i]=0;u[i]=9999;}
		flg=x=0;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			t[a]+=(b*c);
			
			if(v[a]==0){
				u[x]=a;
				v[a]=1;
				x++;
			}
		}

		for(int i=0;i<n;i++){
			if(u[i]==9999){
				break;
			}
			if(t[u[i]]>=1000000){
				flg=1;
				cout<<u[i]<<endl;
			}
		}
		if(flg==0)cout<<"NA"<<endl;
		


	}

	return 0;
}

Measured memory_bytes: 1288
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll x,y;
    cin >> x >> y;
    ll tmpX = x;ll tmpY = y;
    ll m = 1ll << 50;
    if(tmpX <= tmpY){
        m=min(m,tmpY-tmpX);
    }
    tmpX=-x;
    tmpY=y;
    if(tmpX <= tmpY){
        m=min(m,tmpY-tmpX+1);
    }
    tmpX=x;
    tmpY=-y;
    if(tmpX <= tmpY){
        m=min(m,tmpY-tmpX+1);
    }
    tmpX=-x;
    tmpY=-y;
    if(tmpX <= tmpY){
        m=min(m,tmpY-tmpX+2);
    }
    cout << m << endl;
}


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

using namespace std;

typedef long long ll;
const int Inf = 1e9 + 5;

bool cmp(pair<int, int> &a, pair<int, int> &b){
    return a.second > b.second;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<pair<int, int>> queries(m + 1);
    for (int i = 0; i < m; i++){
        int b, c;
        cin >> b >> c;
        queries.push_back({b, c});
    }
    sort(queries.begin(), queries.end(), cmp);
    int j = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++){
        if (j < m && queries[j].second > a[i]){
            queries[j].first--;
            ans += queries[j].second;
        } else {
            ans += a[i];
        }
        if (j < m && queries[j].first == 0){
            j++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
const int N=2005,mod=924844033;
int n,dp[N][N],ans,k,fac[N];
inline void add(int &a,int b){
	a=a+b>=mod?a+b-mod:a+b;
}
vector<int> v[N<<1];
signed main(){
	n=read(); k=read();
	for(int i=1;i<=n;i++)v[i%(2*k)].push_back(i);
	dp[0][0]=1;
	for(int i=0;i<2*k;i++){
		for(unsigned j=0;j<v[i].size();j++){
			int t=v[i][j];
			for(int o=n-1;o>=0;o--){
				if(t>k)add(dp[o+1][0],dp[o][0]);
				if(t+k<=n){add(dp[o+1][1],dp[o][0]); add(dp[o+1][1],dp[o][1]);}
				add(dp[o][0],dp[o][1]); dp[o][1]=0;
			}
		}
		for(int j=0;j<=n;j++){add(dp[j][0],dp[j][1]); dp[j][1]=0;}
	}
	//cout<<dp[1][0]<<" "<<dp[2][0]<<endl;
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=(ll)fac[i-1]*i%mod;
	for(int i=0;i<=n;i++){
		ans=(ans+(ll)dp[i][0]*fac[n-i]*((i&1)?-1:1))%mod;
	}
	cout<<(ans+mod)%mod<<endl;
}

Measured memory_bytes: 14464
from collections import Counter
N = int(input(""))
A = list(map(int,input().split()))
X = 0

A_e = list(set(A))

x = Counter(A)

for i in A_e:
    if x[i] >= 2:
        xc2 = x[i]*(x[i]-1)/2
        X = X + xc2

for k in A:
    print(int(X-x[k]+1))


Measured memory_bytes: 89420
#include<stdio.h>
#include<stdlib.h>

int main()
{
	long long int a, b, c;
	scanf("%lld %lld %lld", &a, &b, &c);
	long long int d = c-a-b;
	if(d <= 0)
	{
		printf("No");
	}
	else if(4*a*b < d * d)
	{
		printf("Yes");
	}
	else printf("No");
}

Measured memory_bytes: 128
#include <stdio.h>
#define N 130
#include <limits.h>
#define WHITE 0
#define BLACK 1
#define GRAY 2


int f[N],d[N],f[N],e[N];
int color[N];
int time,n;
int a[N],b[N],c[N];
int B[N][N];


int Q[N];
int head,tail;

void enqueue(int x){
  
  Q[tail] = x;
  
  if(tail + 1 == N){
    tail = 0;
  }
  else {
    tail = tail + 1;
  }
  
}

int dequeue(){
  
  int x;
  
  x = Q[head];
  if(head + 1 == N){
    head = 0;
  }
  else {
    head = head + 1;
  }
  return x;
  
}

main()
{
  
  
  int i,j,u;
  int A[N][N];
  
  
  
  scanf("%d",&n);
  
  for(i = 1; i <= n; i++){
    scanf("%d%d",&a[i],&b[i]);
    for(j = 1; j <= b[i]; j++){
      scanf("%d",&c[j]);
      A[a[i]][c[j]] = BLACK;
      B[a[i]][j] = c[j];
    }  
  }
  for(i = 0; i < N; i++){
    d[i] = -1;
  }
  bfs(1);
 
  return 0;
}

int bfs(int s)
{
  
  int i,j,v,u=a[s];
  
  for(i = 1; i <= n ; i++){
    color[u] = WHITE;
    d[u] = INT_MAX;
    color[s] = GRAY;
  }
  d[s] = 0;
  
  for(i =1; i <N; i++){
    Q[i] = 0;
  }
  head=1;
  tail=1;
  
  enqueue(s);
  
  for(j=1;Q[j] != 0;j++){
    u = dequeue();
    for(i = 1; i <= b[u]; i++){
      v = B[u][i];
      if(color[v] == WHITE){
	color[v] = GRAY;
	d[v] = d[u] + 1;
	enqueue(v);
      }
    }
    color[u] = BLACK;
  }
for(i = 1; i <= n; i++){
  printf("%d %d\n",i,d[i]);
 }
}

Measured memory_bytes: 652
#include <iostream>
#include <map>
using namespace std;
int main()
{
 int N,M;
 cin >>N >> M;
 multimap<long int,long int>A;
 long int a;
 long int  b;

 for(int l=0;l<N;l++){
cin >> a >> b;
 A.insert(make_pair(a,b));
}
long long sumMoney=0;
  for(auto i=A.begin();i!=A.end();++i){
        if(M>i->second){
        sumMoney+=i->first*i->second;
        M-=i->second;
        }
        else
        {
        sumMoney+=i->first*M;  
        break;
        }
    
  }

  cout << sumMoney << endl;
return 0;

}

Measured memory_bytes: 6528
#include<cstdio>
#define LL long long
using namespace std;
int n,m,d;
double ans;
int main(){
	scanf("%d%d%d",&n,&m,&d);
	ans=(LL)(n-d)*(m-1);
	if (d) ans*=2;
	ans=ans/n/n;
	printf("%.10lf",ans);
	return 0;
}

Measured memory_bytes: 128
// C - Maximal Value
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)

int main(){
	int N; cin>>N;
	vi B(N-1), A(N);
	rp(i,N-1) cin>>B[i];

	A[0] = B[0];
	A[N-1] = B[N-2];
	for(int i=0; i<N-2; ++i){
		int mini = min(B[i], B[i+1]);
		A[i+1] = mini;
	}

	ll ans = 0; rp(i,N) ans += A[i];
	cout<< ans <<endl;
}

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

int main() {
    int n, d, x;
    cin >> n >> d >> x;

    int ans = 0;
    rep(i, n) {
        int a;
        cin >> a;
        ans += d / a;
        if (d % a != 0) ans++;
    }

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


Measured memory_bytes: 256
#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 max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#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 mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;
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(){
    ll n,m;
    cin>>n>>m;
    ll ans=0;
    if(2*n>=m){
        cout<<m/2;
    }else{
        ans+=n;
        m-=2*n;
        ans+=m/4;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<complex>
using namespace std;
typedef complex<double> qua;
qua solve(qua a,qua b,qua c)
{
    b-=a,c-=a;
    return a+b*real(c/b);
}
int main()
{
    int m;
    double x1,y1,x2,y2,x3,y3;
    scanf("%lf%lf%lf%lf%d",&x1,&y1,&x2,&y2,&m);
    while(m--)
    {
        scanf("%lf%lf",&x3,&y3);
        qua ans=solve(qua(x1,y1),qua(x2,y2),qua(x3,y3));
        printf("%.8f %.8f\n",ans.real(),ans.imag());
    }
}



Measured memory_bytes: 2764
A = list(map(int, input().split()))
A1,A2,A3 = A[0],A[1],A[2]

def f(A1,A2,A3):
    bj = A1 + A2 + A3
    if bj >= 22:
        return 'bust'
    else:
        return 'win'

print(f(A1,A2,A3))

Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	string s;

	cin>>s;

	vi a(26, 0);

	rep(i, s.size()){
		a[s[i]-'a']++;
	}
	int flag=true;
	rep(i, 26){
		if(a[i]>=2) flag=false;
	}
	if(flag){
		cout<<"yes"<<endl;
	}else{
		cout<<"no"<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=300005;
int n,a[N],b[N];
bool check(int l,int r){
	int t1=0,t2=0;
	for (int i=l;i<=r;i++)
		if (a[i]<i){
			if (t1>a[i]||a[i]<l||a[i]>r)return 0;
			t1=a[i];
		}
		else if (a[i]>i){
			if (t2>a[i]||a[i]<l||a[i]>r)return 0;
			t2=a[i];
		}
	return 1;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]),b[i]=a[i]==i;
	for (int i=3;i<=n;i++)
		if (!b[i-2]&&!b[i-1]&&!b[i]){
			puts("No");
			return 0;
		}
	for (int i=1,j=1;i<=n;i=j+1)
		if (!b[i]){
			j=i;int flag=0;
			while (j<n&&(b[j+1]^flag))flag^=1,j++;
			if (!check(i,j)){
				puts("No");
				return 0;
			}
		}
		else j=i;
	puts("Yes");
	return 0;
}


Measured memory_bytes: 2560
//rakeba_asrafe
//ug02-47-18-024
#include<stdio.h>
int main()
{ int A_1,A_2,A_3,x;
scanf("%d %d %d",&A_1,&A_2,&A_3);
x=A_1+A_2+A_3;
if(x>=22)
{
    printf("bust");
}
else
{
    printf("win");
}



    return 0;
}


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

#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector < ll >
#define vvll vector < vll >
#define vld vector < ld >
#define pll pair < ll,ll > 
#define ppll pair < ll, pll>
#define pld pair < ld,ld > 
#define vpll vector < pll >
#define vpld vector < pld >
#define all(X) X.begin(),X.end()
#define endl "\n"
#define sz(x) ((ll)((x).size()))
vll emptyVector;
const ll MAX = 2e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll binaryExpo(ll x, ll n)
{
	if(n == 0)
		return 1;
	if(n % 2 == 0)
		return binaryExpo((x*x), n/2);
	return (x*binaryExpo((x*x), n/2));
}
const double pi = 3.141592653589793238462643383279502884197169399375105;
/*-------------------------------------------		CODE STARTS FROM HERE		------------------------------------------*/



void solve(void)
{
	int n;
	cin >> n;
	int x = n % 10;
	if(x == 2 or x == 4 or x == 5 or x == 7 or x == 9)
		cout << "hon" << endl;
	else if(x == 3)
		cout << "bon" << endl;
	else
		cout << "pon" << endl;

}


int main(void)
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

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




	return 0;
}

Measured memory_bytes: 3612