akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY (1<<21)

int n,M[MAX][MAX];

int prim(){
  int u,minv;
  int d[MAX],p[MAX],color[MAX];
  int i,v;
  int sum=0;

  for(i=0;i<n;i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }
  
  d[0] = 0;

  while(1){
    u = -1;
    minv = INFTY;
    for(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(v=0;v<n;v++){
      if(color[v] != BLACK && M[u][v] !=-1){
	if(d[v] > M[u][v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i] != -1) sum += M[i][p[i]];
  }
  return sum;
}

int main(){
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&M[i][j]);
    }
  }

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



Measured memory_bytes: 2052
N = int(input())
T, A = map(int, input().split(' '))
H = list(map(int, input().split(' ')))
ans = -1
best_diff = 10 ** 5
for idx, hi in enumerate(H):
    t = T - (hi * 0.006)
    diff = abs(A-t)
    if diff < best_diff:
        best_diff = diff
        ans = idx+1
print(ans)

Measured memory_bytes: 3064
import sys
from collections import deque


n = int(sys.stdin.readline().strip())
A = map(int, sys.stdin.readline().strip().split())

q = deque()
for i, a_i in enumerate(A):
    if i % 2 == 0:
        q.append(a_i)
    else:
        q.appendleft(a_i)

ans = list(map(str, q))
if n % 2 == 1:
    ans = ans[::-1]

print(" ".join(ans))

Measured memory_bytes: 108880
import collections
n= int(input())
g=[]
for _ in range(n):
    v,k,*varray= map(int,input().split())
    g.append(varray)
        

d= [-1]* (n+10)
d[0]=0
q= collections.deque()
q.append(0)
while len(q)>  0:
    cur = q.popleft()
    for next in g[cur]:
        if d[next-1]== -1:
            d[next-1]= d[cur]+1
            q.append(next-1)
            
for i in range(n):
    print(i+1,d[i])
    


Measured memory_bytes: 6032
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>

int s;
std::map<int, int> data;

int f(int n) {
	if (n % 2 == 0)
		return n / 2;
	else
		return 3 * n + 1;
}

int main() {
	std::cin >> s;

	int tmp = s;
	int ans = 1;
	while (data[tmp] == 0) {
		++data[tmp];
		tmp = f(tmp);
		++ans;
	}

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


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n+1);
	for(int i = 2; i <= n; i++) cin >> a.at(i);

	vector<int> children(n+1);
	for(int i = 2; i <= n; i++){
		int parent = a.at(i);
		children.at(parent)++;
	}

	for(int i = 1; i <= n; i++){
		cout << children.at(i) << endl;
	}

	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int sum = 0;
  for (int i = 0; i < S.size(); i++) {
    sum += S.at(i) - 48;
    //cout << i << '.' << sum << endl;
  }
  //cout << sum << endl;
  if (sum % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3752
<?php
  fscanf(STDIN, "%d %d", $H, $W);
  for ($i = 0; $i < $H; $i++) {
    fscanf(STDIN, "%s", $s);
    // $m[$i] = str_split($s);
    $m[$i] = $s . "#";
  }
  $m[$H] = str_repeat("#", $W + 1);
  // var_dump($m);

  for ($y = 0; $y < $H; $y++) {
    $s = 0;
    for ($x = 0; $x <= $W; $x++) {
      $a[$y][$x] = 0;
      if ($m[$y][$x] === ".") {
        $s++;
      } else {
        for ($z = 0; $z < $s; $z++) {
          $a[$y][$x - $z - 1] = $s;
        }
        $s = 0;
      }
    }
  }

  for ($x = 0; $x < $W; $x++) {
    $s = 0;
    for ($y = 0; $y <= $H; $y++) {
      if ($m[$y][$x] === ".") {
        $s++;
      } else {
        for ($z = 0; $z < $s; $z++) {
          $a[$y - $z - 1][$x] += $s;
        }
        $s = 0;
      }
    }
  }

  // for ($y = 0; $y < $H; $y++) {
  //   for ($x = 0; $x < $W; $x++) {
  //     printf("%2d ", $a[$y][$x]);
  //   }
  //   echo PHP_EOL;
  // }
  // echo PHP_EOL;

  $ans = 0;
  for ($y = 0; $y < $H; $y++) {
    $ans = max($ans, max($a[$y]));
    // echo PHP_EOL;
  }
  echo $ans - 1;


Measured memory_bytes: 146040
N = int(input())
S = [input() for _ in range(N)]

count = 0
no = 0
end_A = 0
start_B = 0
AB = 0

for i in range(N):
  count += S[i].count("AB")
  if S[i][0] == "B" and S[i][-1] == "A":
    AB+=1
  elif S[i][0] == "B":
    start_B+=1
  elif S[i][-1] == "A":
    end_A+=1
  else:
    no+=1
if end_A >= start_B:
  count +=start_B
  start_B = 0
  end_A -= start_B
else:
  count += end_A
  end_A = 0
  start_B-=end_A

count += max(0,AB-1)

if AB >= 1 and (end_A>0 or start_B>0):
  count += 1
print(count)

Measured memory_bytes: 3700
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
                         **/
#include<bits/stdc++.h>
using namespace std;
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define fl '\n'
#define vi vector<int>
#define sz size
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 2*1e5+1;
const int mod = 1000000009;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 10000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b;
    int pwur = qpow(b,e>>1);
    return pwur * pwur;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------


int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);

    string a,b,c;
    cin>>a>>b>>c;

    char aux='a',res;

    while(true){
        if(aux=='a'){
            if(a.sz()==0){
                res='A';
                break;
            }
            aux=a[0];
            a.erase(0,1);
        }
        if(aux=='b'){
            if(b.sz()==0){
                res='B';
                break;
            }
            aux=b[0];
            b.erase(0,1);
        }
        if(aux=='c'){
            if(c.sz()==0){
                res='C';
                break;
            }
            aux=c[0];
            c.erase(0,1);
        }
    }

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(6);

  int INF = 1000000;

  string str="";
  while(cin >> str){
    int num[str.size()];
    REP(i,str.size()){
      num[i] = str[i] - '0';
    }

    REP(i, 9){
      int n2[str.size()];
      memcpy(n2,num,sizeof(num));
      
      REP(j, str.size()-i-1){
	num[j] = (n2[j]+n2[j+1]) % 10;
      }
    }

    cout << num[0] << endl;
  }

  return 0;
}

Measured memory_bytes: 1188
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	string s,t;
	cin>>s>>t;
	int c=0;
	for(int i=0;i<3;i++){
		if(s[i]==t[i]){
			c++;
		}
	}
	cout<<c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

ll inv(ll a, ll b){
    return (a > 1 ? b - inv(b%a, a)*b/a : 1);
}

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))

const ld e = 2.71828182845904523536028747;
const ld PI = 3.14159265359;
const ll inf = (1LL<<62);
const int iinf = (1<<30);
//CLOCKS_PER_SEC

int n, ans;

int main(){
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    //ios_base::sync_with_stdio(0); cin.tie(0);
    //ifstream cin ("test.in");
    cin >> n;
    for (int i=1; i<=n; i++){
        int x = i, cnt = 0;
        while (x){
            cnt++; x /= 10;
        }
        if (cnt & 1) ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  REP(i,a,b) for(int i=a;i<b;i++)
typedef long long int lld;
typedef vector<lld> vl;
typedef vector<int> vi;
typedef vector<string> vs;



//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());

int main() {

	string s,t,tmp;
	bool ans=false;
	cin>>s>>t;
	int len;
	len=s.size();
	rep(i,len){
		if(s==t){
			ans=true;
			break;
		}
		s=s.back()+s.substr(0,len-1);
	}
	if(ans){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin >> a >>b;
    if(b%a==0){
        cout << a+b;
    }
    else cout << b-a;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(),(x).end()
#define Graph vector<vector<int>>;
#define iterG(next_v, G, v) for(auto next_v : G[v]
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int s, w;
    cin >> s >> w;
    
    if(w >= s){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
string O,E;
  cin>>O>>E;
  int N=O.size()+E.size();
  string S="";
  for(int i=0;i<N;i++){
  if(i%2==0)
    S+=O.at(i/2);
    else
      S+=E.at((i-1)/2);
  
  }cout<<S<<endl;
  
  
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        1e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}

int fact[2000005] , inv_fact[2000005];

int raise(int a,int b)
{
    int an = 1;
    while(b>0)
    {
        if(b%2!=0) an = (an%M  * a%M)%M;
        b/=2;
        a = (a%M *a%M)%M;
    }
    return an;
}

int inv(int a)
{
    return raise(a,M-2);
}
int ncr(int n,int r)
{
    if(r>n) return 0;
    int an = fact[n];
    an = (an%M * inv_fact[r]%M)%M;
    an = (an%M * inv_fact[n-r]%M)%M;

    return an;
}
void solve()
{
  
 int r1,c1,r2,c2;
 cin >> r1 >> c1 >> r2 >> c2;
 
 fact[0] = fact[1] = 1;
 inv_fact[0] = inv_fact[1] =1;

 for(int i=2;i<=2000004;i++)
 {
    fact[i] = (fact[i-1]%M * i%M)%M;
    inv_fact[i] = (inv_fact[i-1]%M * inv(i)%M)%M;
 }
 int an  =0;
 for(int i=c1 ; i<=c2 ;i++)
 {
   an += (ncr(r2+i+1 ,i+1) - ncr(r1+i,i+1) + M)%M;
   an %= M ;

 }

 cout<<an<<endl;
}


int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

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

int main() {
 int N,K;
 cin >> N >> K;
 int x[N];
 int ans = 0;

 for(int i =0; i<N;i++){
   cin >> x[i];
   ans += min(x[i],abs(K-x[i]));
 }

 cout << 2*ans <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define int long long
long double dpp[305][305][305];
long double dp(int n,int a, int b, int c)
{
	if(dpp[a][b][c]!=-1)
		return dpp[a][b][c];
	else
	{
		dpp[a][b][c] = (1.0*n)/(1.00*(a+b+c));
		if(a!=0)
			dpp[a][b][c] +=  ((1.0*a)/(1.0*(a+b+c))*(1.0*dp(n,a-1,b,c)));
		if(b!=0)
			dpp[a][b][c] += ((1.0*b)/(1.0*(a+b+c))*(1.0*dp(n,a+1,b-1,c)));
		if(c!=0)
			dpp[a][b][c] += ((1.0*c)/(1.0*(a+b+c))*1.0*dp(n,a,b+1,c-1));
		return dpp[a][b][c];
	}
}	 
int main(void)
{
	int n;
	scanf("%lld",&n);
	int a=0,b=0,c=0;
	int A[n];
	for(int i = 0;i<n;i++)
	{
		scanf("%lld",A+i);
		if(A[i] == 1) a++;
		if(A[i] == 2) b++;
		if(A[i] == 3) c++;
	}
	long double ans;
	for(int i = 0;i<305;i++)
		for(int j = 0;j<305;j++)
			for(int k = 0;k<305;k++)
				dpp[i][j][k] = -1.0;
	dpp[0][0][0] = 0.0;
	dpp[1][0][0] = 1.0*n;
	ans = dp(n,a,b,c);
	printf("%.14llf\n",ans);
	return 0;
}


Measured memory_bytes: 443520
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define vvl vector<vl>
#define fill(a,p) memset(a,p,sizeof(a))
#define pb push_back
#define mod 1000000007
#define N 100005
#define all(a) a.begin(),a.end()
#define point pair<ll,ll>
#define endl "\n"

const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM =2005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}
inline ll ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
inline ll mo(ll a,ll b){if(b<0){b=abs(b)%mod;b=a-b;return (b<0)?b+mod:b;}else{return (a+b)%mod;}}
inline ll pow(ll a,ll b){if(b==0){return 1;}else{if(b%2==0){ll temp=pow(a,b/2);return temp*temp;}
else{return a*pow(a,b-1);}}}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int main()
{
    ll x,y;cin>>x>>y;
    for(ll i=0;i<=x;i++){
        for(ll j=0;j<=x;j++){
            if((i+j)==x && (2*i+4*j)==y){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string a;
  for(int i = -2; i < W; i++) {
    a += "#";
  }

  cout << a << endl;
  for(int i = 0; i < H; i++) {
    string line;
    cin >> line;
    cout << '#' << line << '#' << endl;
  }
  
  cout << a << endl;
}

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

using namespace std;

typedef long long lli;

const lli MAX_V = 1000;
const lli M = 1000000007;

lli V, E;
vector<lli> G[MAX_V];
vector<lli> rG[MAX_V];
vector<lli> vs;
bool used[MAX_V];
lli cmp[MAX_V];

void add_edge(lli from, lli to){
  G[from].push_back(to);
  rG[to].push_back(from);
}

void dfs(lli v){
  used[v] = true;
  for(lli i=0;i<G[v].size();i++){
    if(!used[G[v][i]]) dfs(G[v][i]);
  }
  vs.push_back(v);
}

void rdfs(lli v, lli k){
  used[v] = true;
  cmp[v] = k;
  for(lli i=0;i<rG[v].size();i++){
    if(!used[rG[v][i]]) rdfs(rG[v][i], k);
  }
}

lli scc(){
  fill(used, used+V, false);
  vs.clear();
  for(lli v = 0;v<V;v++){
    if(!used[v]) dfs(v);
  }
  fill(used, used+V, false);
  lli k = 0;
  for(lli i=vs.size()-1;i>=0;i--){
    if(!used[vs[i]]) rdfs(vs[i], k++);
  }
  return k;
}

lli V2;
vector<lli> G2[MAX_V];
lli dp[MAX_V];

void make_graph(lli v){
  used[v] = true;
  for(lli i=0;i<G[v].size();i++){
    lli to = G[v][i];
    if(cmp[v] != cmp[to]) G2[cmp[v]].push_back(cmp[to]);
    if(!used[to]) make_graph(to);
  }
}

lli rec(lli v){
  used[v] = true;
  lli res = 1;
  for(lli i=0;i<G2[v].size();i++){
    lli to = G2[v][i];
    //prllif("v = %d, to = %d\n", v, to);
    if(!used[to]){
      if(dp[to] != -1) res = (res * dp[to]) % M;
      else res = (res * rec(to)) % M;
    }
  }
  res = (res + 1) % M;
  dp[v] = res;
  return res;
}

main(){
  cin >> V >> E;
  for(lli i=0;i<E;i++){
    lli a, b;
    cin >> a >> b;
    add_edge(b-1, a-1);
  }
  V2 = scc();
  //for(lli i=0;i<V;i++) prllif("%d ", cmp[i]); puts("");
  for(lli i=0;i<V;i++) rG[i].clear();
  fill(used, used+V, false);
  for(lli i=0;i<V;i++) make_graph(i);
  /*for(lli i=0;i<V2;i++){
    prllif("i=%d:", i);
    for(lli j=0;j<G2[i].size();j++){
      prllif("%d ", G2[i][j]);
    }
    puts("");
    }*/
  fill(used, used+V, false);
  fill(dp, dp+V2, -1);
  lli ans = 1;
  for(lli i=0;i<V2;i++){
    if(!used[i]){
      //prllif("i = %d\n", i);
      ans = (ans * rec(i)) % M;
    }
  }
  //for(lli i=0;i<V2;i++) prllif("%d ", dp[i]); puts("");
  cout << ans << endl;
}

Measured memory_bytes: 1388
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int main(){
	// sengen
	int n,h;
	// nyuryoku
	cin >> h >> n;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i];
	}
	// keisan
	LL dp[h+1];
	for(int i=0;i<=h;i++){
		dp[i] = 200000000;
	}
	dp[0] = 0;
	for(int i=0;i<h;i++){
		for(int j=0;j<n;j++){
			dp[min(i+a[j],h)] = min(dp[min(i+a[j],h)],dp[i]+b[j]);
		}
	}
	// syutsuryoku
	cout << dp[h] << endl;
}

Measured memory_bytes: 3652
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
//using Graph = vector<vector<int>>;
typedef long long ll;
using Graph = vector<vector<pair<ll,ll>>>;
const int mod =1e+9+7;

const int dy[4]={0,1,0,-1};
const int dx[4]={1,0,-1,0};
const ll INF=1e10;

int main(){
    ll n; cin>>n;
    ll cnt=0;
    bool ans=false;
    rep(i,n){
        ll a,b; cin>>a>>b;
        if(a==b)cnt++;
        else cnt=0;
        if(cnt>=3){
            ans=true;
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}











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

#include <cstdio>
#include <cmath>
using namespace std;

typedef double D;
const D EPS = 1e-8;
const D INF = 1e10;
const D PI = M_PI;

struct P {
    D x, y;
    P(D xs, D ys) : x(xs), y(ys) { }
    P() { }
};

P operator +(P a, P b) { return P(a.x + b.x, a.y + b.y); }
P operator -(P a, P b) { return P(a.x - b.x, a.y - b.y); }
P operator *(P p, D s) { return P(p.x * s, p.y * s); }

D inp(P a, P b) { return a.x*b.x + a.y*b.y; }
D outp(P a, P b) { return a.x*b.y - a.y*b.x; }

D norm(P p) { return inp(p, p); }
D abs(P p) { return sqrt(norm(p)); }

bool eq(P a, P b) { return abs(a - b) < EPS; }

D arg(P p) { return atan2(p.y, p.x); }

P rot90(P p) {
    return P(-p.y, p.x);
}

P rot(P p, D radian) {
    P q;
    q.x = cos(radian)*p.x - sin(radian)*p.y;
    q.y = sin(radian)*p.x + cos(radian)*p.y;
    return q;
}

struct L : vector<P> {
    L(P a, P b) { push_back(a); push_back(b); }
    L() { this->resize(2); }
};

struct C {
    P p; D r;
    C(P ps, D rs) : p(ps), r(rs) { }
    C() { }
};

// ??卒???l???????????????p?????????
// (l??????p??????????????????????????即????????????????賊???????)
// norm??則?????贈?????????(abs??則??????????????????)
P projection(L l, P p) {
    P a = l[1] - l[0];
    P b = p - l[0];
    D t = inp(b, a) / norm(a);
    return l[0] + a * t;
}

// ??卒???l???????????????p???????属?
// (l????????????????則属???p??????)
P reflection(L l, P p) {
    return p + (projection(l, p) - p) * 2;
}

int ccw(P a, P b, P c) {
    b = b - a; c = c - a;

    // a - b - c ????????????????????即???
    if(outp(b, c) > EPS)  return +1; // ???????即???????
    if(outp(b, c) < -EPS) return -1; // ????即???????

    // a - b - c ??卒??????????????其??即???
    if(inp(b, c) < 0)     return +2; // c - a - b
    if(norm(b) < norm(c)) return -2; // a - b - c
    return 0;                        // a - c - b
}

/* intersect Segment Segment */
bool iSS(L s, L t) {
    return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
        ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}

/* intersect Segment Point */
bool iSP(L s, P p) {
    return ccw(s[0], s[1], p) == 0;
}

/* crosspoint Line Line */
/* ?????????????????即??????iSS(s,t)????蔵???????????????即 */
P cLL(L l, L m) {
    D d = outp(m[1] - m[0], l[1] - l[0]);
    if(abs(d) < EPS) throw "s // t !";
    return l[0] + (l[1] - l[0]) * outp(m[1] - m[0], m[1] - l[0]) * (1.0 / d);
}

/* distance Segment Point */
D dSP(L s, P p) {
    P r = projection(s, p);
    if(iSP(s, r)) return abs(r - p);
    return min(abs(s[0] - p), abs(s[1] - p));
}

/* distance Segment Segment */
D dSS(L s, L t) {
    if(iSS(s, t)) return 0;
    return min(min(dSP(s, t[0]), dSP(s, t[1])),
            min(dSP(t, s[0]), dSP(t, s[1])));
}

int main() {
    int Q; cin >> Q;
    while(Q--) {
        D x[4], y[4];
        for(int i = 0; i < 4; i++) {
            cin >> x[i] >> y[i];
        }

        L s(P(x[0], y[0]), P(x[1], y[1])), t(P(x[2], y[2]), P(x[3], y[3]));

        P p = cLL(s, t);
        printf("%.9f %.9f\n", p.x, p.y);
    }
}

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

#define int long long
#define pb emplace_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int n,d;
	cin >> n >> d;
	int ans = ceil(n/(2.0 *d + 1));
	cout << ans;
}







Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		Scanner scan = new Scanner(System.in);
		
		int H = scan.nextInt();
		int W = scan.nextInt();
		
		
		String [][] C = new String[H][W];//*or.
		String[]scanline = new String[H];
		
		for(int i = 0;i<H;i++){
			scanline[i] = scan.next();
		}
		
		
		for(int i = 0;i<H;i++){
			for(int j = 0;j<W;j++){
				C[i][j] = scanline[i].substring(j, j+1);
			}
		}
		
		//String[][]X = new String[2*H][W];
		
		for(int i = 0;i<H;i++){
			for(int j = 0;j<W;j++){
				System.out.print(C[i][j]);
			}
			System.out.println();
			
			for(int k = 0;k<W;k++){
				System.out.print(C[i][k]);
			}
			System.out.println();
		}
		
		
		
		
		
		
	}

}

Measured memory_bytes: 28608
n = int(input())

cnt =[0]*(n+1)

a = list(map(int,input().split()))

for i in range(n):
    cnt[a[i]]+=1

pairs = 0

b = []
for i in range(n+1):
    c = cnt[i]*(cnt[i]-1)/2
    b.append(c)
    pairs += c

for i in a:
    print(int(pairs - b[i] +(cnt[i]-1)*(cnt[i]-2)/2))



Measured memory_bytes: 27804
N=int(input())
numlist=list(map(int,(input() for _ in range(N))))
numdict={y:x for x,y in enumerate(numlist)}
sorted_list=sorted(numdict.items(),reverse=True)

amount_of_child=[1]*N
sum_of_distance_of_child=[0]*N
branch_list=[]

for S,num in sorted_list:
  nS=S+2*amount_of_child[num]-N
  if nS in numdict:
    nextnum=numdict[nS]
    branch_list.append([num+1,nextnum+1])
    amount_of_child[nextnum]+=amount_of_child[num]
    sum_of_distance_of_child[nextnum]+=(sum_of_distance_of_child[num]+amount_of_child[num])
    if amount_of_child[nextnum]==N:
      break
  else:
    print (-1)
    exit()

if sorted_list[-1][0]==sum_of_distance_of_child[sorted_list[-1][1]]:
  for _ in range(N-1):
    x,y=branch_list.pop()
    print(x,y)
else:
  print (-1)
exit()


Measured memory_bytes: 50308
/*input
5 6
1 4 5 9 8
3 1
3 2
5 4
1 5
2 4 5
1 2 9
2 3 4
1 5 1
2 2 1
2 5 5


*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin >> n;
  int v;
  vector <int> vec;
  for (int i = 0; i < n; i++) {
    cin >> v;
    vec.pb(v);
  }
  int ans = 0, c = 0;
  for (int i = n - 2; i >= 0; i--) {
    if (vec[i] >= vec[i + 1]) {
      c++;
      ans = max(ans, c);
    } else {
      c = 0;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

//abcabc
    cin>>s;
    rrrep(i,Size(s)-2,0LL){
        string co="";
        rep(j,i+1)co+=s[j];
        if(Size(co)%2==1)continue;
        int ok=1;
        rep(i,Size(co)/2){
            if(s[i]!=s[i+(Size(co)/2)]){
                ok=0;
                break;
            }
        }
        if(ok){
            Cout(Size(co));
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

#define ll long long

int main(){
  int n, w;
  cin >> n >> w;
  
  vector<vector<ll>> con(n + 1, vector<ll>(w + 1, 0));
  for(int i = 0; i < n; i++){
    int u, v;
    cin >> u >> v;
    for(int j = 0; j <= w; j++){
      if(j >= u) con[i + 1][j] = max(con[i][j - u] + (ll)v, con[i][j]);
      else con[i + 1][j] = con[i][j];
    }
  }
  
  cout << con[n][w] << endl;
  
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF INT_MAX/3
#define mod 1000000007

int h,w;
char s[1001][1001];
int d[1001][1001];
int dd[]={-1,0,1,0,-1};

int main(){
  scanf("%d%d",&h,&w);
  rep(i,h)scanf("%s",s[i]);

  rep(i,h)rep(j,w)d[i][j]=INF;
  queue<P> que;
  rep(i,h)rep(j,w){
    if(s[i][j]=='#'){
      d[i][j]=0;
      que.push(P(i,j));
    }
  }

  int res=0;
  while(que.size()){
    P p=que.front(); que.pop();
    maxch(res,d[p.fi][p.se]);

    rep(dir,4){
      int ni=p.fi+dd[dir],nj=p.se+dd[dir+1];
      if(ni<0||ni>=h||nj<0||nj>=w)continue;
      if(d[ni][nj]==INF){
        d[ni][nj]=d[p.fi][p.se]+1;
        que.push(P(ni,nj));
      }
    }
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 21556
#include <cstdint>
#include <iostream>
using i8 = std::int_fast8_t;
using u8 = std::uint_fast8_t;
using i16 = std::int_fast16_t;
using u16 = std::uint_fast16_t;
using i32 = std::int_fast32_t;
using u32 = std::uint_fast32_t;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;
inline void fast_io() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
template <class T>
inline void in(T &now) {
    std::cin >> now;
}
template <class T, class... Args>
void in(T &head, Args &... tail) {
    in(head);
    in(tail...);
}
template <class T>
inline void out(T now) {
    std::cout << now;
}
template <class T, class... Args>
void out(T head, Args... tail) {
    out(head);
    out(tail...);
}
template <class T>
inline void up(T &a, const T &b) noexcept {
    if (a < b) {
        a = b;
    }
}
template <class T, class... Args>
void up(T &a, const T &head, const Args &... tail) noexcept {
    up(a, head);
    up(a, tail...);
}
template <class T>
inline void down(T &a, const T &b) noexcept {
    if (b < a) {
        a = b;
    }
}
template <class T, class... Args>
void down(T &a, const T &head, const Args &... tail) noexcept {
    down(a, head);
    down(a, tail...);
}
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main(int argc, char *argv[]) {
    fast_io();

    i64 n, k, cnt{};
    in(n, k);
    while (n) {
        ++cnt;
        n /= k;
    }
    out(cnt);

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int ans=0;
    for(int i=0;i<N;i++){
        ans += i+1;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<limits.h>
#define SENTINEL INT_MAX
using namespace std;
typedef long l;
int n;

void Merge(char idID[],char ID[],long S[],int left,int mid,int right){
  int n1 = mid-left+1;
  int n2 = right-mid;
  l L[n1+3];
  l R[n2+3];
  char CL[n1+3];
  char CR[n2+3];

  for(int i=1;i<=n1;i++){
    L[i] = S[left+i-1];
    CL[i] = idID[left+i-1];
  }
  for(int j=1;j<=n2;j++){
    R[j]=S[mid+j];
    CR[j]=idID[mid+j];
  }
  L[n1+1]=R[n2+1]=SENTINEL;
  int i=1;
  int j=1;
  for(int k=left;k<=right;k++){
    if(L[i]<=R[j]){
      S[k]=L[i];
      idID[k] = CL[i];
      i=i+1;
    }
    else{
      S[k]=R[j];
      idID[k] = CR[j];
      j=j+1;
    }
  }
}

void Merge_Sort(char idID[],char ID[],long S[],int left,int right){
  if(left<right){
    int mid = (left+right)/2;
    Merge_Sort(idID,ID,S,left,mid);
    Merge_Sort(idID,ID,S,mid+1,right);
    Merge(idID,ID,S,left,mid,right);
  }
}




int Partition(char ID[],l A[],l p,l r){
  l x = A[r];
  l i = p-1;
  for(int j=p;j<r;j++){
    if(A[j] <= x){
      i = i+1;
      char ch = ID[i];
      ID[i] = ID[j];
      ID[j] = ch;
      l h=A[i];
      A[i] = A[j];
      A[j] = h;
    }
  }
  char ch = ID[i+1];
  ID[i+1] = ID[r];
  ID[r] = ch;
  l h = A[i+1];
  A[i+1] = A[r];
  A[r] = h;
  return i+1;
}

void Quicksort(char ID[],l A[],l p,l r){
  if(p<r){
    l q = Partition(ID,A,p,r);
    Quicksort(ID,A,p,q-1);
    Quicksort(ID,A,q+1,r);
  }
}


int main(){
  
  while(scanf("%d",&n) != EOF){
    char *ID = new char[n+2];
    l *A = new l[n+2];
    l *idA = new l[n+2];
    char *idID = new char[n+2];
    l k=0;
    
    for(int i=1;i<=n;i++){
      cin >> ID[i] >> A[i];
      idID[i] = ID[i];
      idA[i] = A[i];
      if(k<A[i])k=A[i];
    }
   
    Merge_Sort(idID,ID,idA,1,n);
    
    
    /*
    cout << "--------------------------" << endl;
    for(int i=1;i<=n;i++){
      // printf("%c %d\n",idID[i],idA[i]);
      cout << idID[i] << " " << idA[i] << endl;
    }
    cout << "---------------------------" << endl;
    */

    Quicksort(ID,A,1,n);
    bool stable = true;
    for(int i=1;i<=n;i++){
      if(idID[i] != ID[i])stable = false;
    }

    if(stable)printf("Stable\n");
    else printf("Not stable\n");
    for(int i=1;i<=n;i++){
      printf("%c %ld\n",ID[i],A[i]);
    }
    
    delete [] ID;
    delete [] A;
    delete [] idID;
    delete [] idA;
  }
  return 0;
}

Measured memory_bytes: 2420
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int f[211];int gf(int x){return x==f[x]?x:f[x]=gf(f[x]);}
int n,d[211][211];
char s[211][211];

vector<int> vs[211];

int main()
{
	get1(n);
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)f[i]=i;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
	{
		if(s[i][j]=='1')
		{
			d[i][j]=1;
			f[gf(i)]=gf(j);
		}
		else d[i][j]=(i==j?0:inf);
	}
	for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	
	int ans=0;
	for(int i=1;i<=n;i++)vs[gf(i)].pb(i);
	for(int i=1;i<=n;i++)if(f[i]==i)
	{
		int mx=0;
		for(auto v:vs[i])for(auto v2:vs[i])
		{
			if(s[v][v2]=='1'&&d[i][v]==d[i][v2])
			{
				puts("-1");
				return 0;
			}
			else mx=max(mx,d[v][v2]);
		}
		ans+=mx+1;
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 512
# Square869120Contest #4 B - Buildings are Colorful!　
# 全探探索　ver

import sys

N, K = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))

ans = float('inf')
for i in range(2 ** (N - 1)):
    bit = [(i >> j) & 1 for j in range(N - 1)]  # 左から2番目以降で見えるようにするビルを選択

    can_see = 0
    cost = 0
    height = a[0]
    for j, b in enumerate(bit):
        if (b == 1) & (height >= a[j + 1]):
            cost += height - a[j + 1] + 1
            height = height + 1
            can_see += 1
        elif (b == 1) & (height < a[j + 1]):
            height = a[j + 1]
            can_see += 1
        elif height < a[j + 1]:
            can_see += 1
            height = a[j + 1]

    if can_see >= K - 1:
        ans = min(ans, cost)

print(ans)







Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p (int)(1e9 + 7)
#define inf (int)(1e18)

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(MOD(a * a), N / 2);
	}
	else{
		return MOD(a * power(a, N - 1));
	}
}

signed compare(const void *a, const void *b){
	int sub = *(int *)a - *(int *)b;
	if(sub < 0){
		return -1;
	}
	else if(sub == 0){
		return 0;
	}
	else{
		return 1;
	}
}

int h_to_sec(int x, int *hsub, int H){
	int l = -1, h, r = H;
	while(r - l > 1){
		h = (l + r) / 2;
		if(hsub[h] < x){
			l = h;
		}
		else{
			r = h;
		}
	}
	return r;
}

signed main(){
	int N, H, i, j;
	scanf("%lld", &N);
	int *h = (int *)malloc(sizeof(int) * N);
	int *hsub = (int *)malloc(sizeof(int) * (N + 1));
	for(i = 0; i < N; i++){
		scanf("%lld", &h[i]);
		h[i]--;
		hsub[i] = h[i];
	}
	qsort(hsub, N, sizeof(int), compare);
	hsub[N] = inf;
	for(H = 0, i = 0; i < N; H++){
		hsub[H] = hsub[i];
		while(hsub[H] == hsub[i]){
			i++;
		}
	}
	int *left = (int *)malloc(sizeof(int) * H);
	int *right = (int *)malloc(sizeof(int) * H);
	for(i = 0; i < H; i++){
		right[i] = hsub[i];
	}
	left[0] = 0;
	for(i = 1; i < H; i++){
		left[i] = hsub[i - 1];
	}
/*	for(i = 0; i < H; i++){
		printf("section[%lld] = [%lld, %lld)\n", i, left[i], right[i]);
	}
	printf("\n");
*/	int *dp = (int *)malloc(sizeof(int) * N);
	int **dp2 = (int **)malloc(sizeof(int *) * N);
	int *sec = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		sec[i] = h_to_sec(h[i], hsub, H);
//		printf("sec[%lld] = %lld\n", i, sec[i]);
		dp2[i] = (int *)malloc(sizeof(int) * (sec[i] + 1));
	}
//	printf("\n");
	for(j = 0; j <= sec[0]; j++){
		dp2[0][j] = MOD(power(2, h[0] - left[j] + 1) - power(2, h[0] - right[j] + 1));
	}
	dp[0] = 2;
/*	printf("dp[0] = %lld\n", dp[0]);
	for(j = 0; j <= sec[0]; j++){
		printf("dp2[0][%lld] = %lld\n", j, dp2[0][j]);
	}
	printf("\n");
*/	for(i = 1; i < N; i++){
//		printf("i = %lld\n", i);
		if(h[i] >= h[i - 1]){
//			printf("test3\n");
			dp[i] = MOD(2 * dp[i - 1]);
			for(j = 0; j <= sec[i - 1]; j++){
				dp2[i][j] = MOD(dp2[i - 1][j] * power(2, h[i] - h[i - 1]));
			}
			for(j = j; j <= sec[i]; j++){
				dp2[i][j] = MOD(dp[i - 1] * MOD(power(2, h[i] - left[j] + 1) - power(2, h[i] - right[j] + 1)));
			}
		}
		else{
//			printf("tesst4\n");
			dp[i] = dp[i - 1];
			for(j = sec[i] + 1; j <= sec[i - 1]; j++){
				dp[i] = MOD(dp[i] + dp2[i - 1][j]);
			}
			dp[i] = MOD(2 * dp[i]);
			for(j = 0; j <= sec[i]; j++){
				dp2[i][j] = dp2[i - 1][j];
			}
		}
/*		printf("dp[%lld] = %lld\n", i, dp[i]);
		for(j = 0; j <= sec[i]; j++){
			printf("dp2[%lld][%lld] = %lld\n", i, j, dp2[i][j]);
		}
		printf("\n");
*/	}
	int ans = dp[N - 1];
	for(j = 0; j <= sec[N - 1]; j++){
		ans = MOD(ans + dp2[N - 1][j]);
	}
	printf("%lld\n", ans);
	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

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

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int N;
vector<vector<Pl>> G(100005);
vint ans(100005);
void dfs(ll u, ll prev, ll c) {
	ans[u] = c&1;
	for (auto &v : G[u]) {
		if (v.first == prev) continue;
		dfs(v.first, u, c + v.second);
	}
};

void Main() {
	cin >> N;
	for (int i = 0; i < N-1; i++) {
		ll u, v, w; cin >> u >> v >> w; --u, --v;
		G[u].emplace_back(v, w);
		G[v].emplace_back(u, w);
	}

	dfs(0, -1, 0);
	for (int i = 0; i < N; i++) {
		cout << ans[i] << el;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 9856
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <functional>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF 100000000000000005LL
#define INF (int)1e9+1
#define endl '\n'
#define pb push_back

// debug 도구

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto& x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}\n";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)

// debug 도구 end

using llong = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VPII = vector<pair<int, int>>;
using VLL = vector<long long>;
using PII = pair<int, int>;

int main() {
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 3624