akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int x;cin>>x;
  cout<<3*x*x<<endl;
}

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

int main()
{
    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int> dp(n,INT_MAX);
    vector<int>h(n,0);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);

    for(int i=2;i<n;i++)
    {
        for(int j=1;j<=k && i-j>=0;j++){
        dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
        }
        
    }

cout<<dp[n-1];
return 0;

}

Measured memory_bytes: 4048
// ------------------------------------
// Date:2018/ 3/ 7
// Problem:ABC 077 AroundSquare b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

  int N;
  cin >> N;

  ll ans;
  REP(i, 10101010) {
    if (i * i > N) {
      ans = (i - 1) * (i - 1);
      break;
    }
  }

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
 
signed main(){
int a;
while(cin>>a,a){
    multimap<int,int>s;
    for(int b=0;b<a;b++){
	int c,d,e,f;
	scanf("%lld%lld%lld%lld",&c,&d,&e,&f);
	s.insert(pair<int,int>(-e*10000000000+f*10000-c,d));
	}
	map<int,int>k;
	int sum=0;
	for(auto u=s.begin();u!=s.end()&&sum<26;u++){
	    if(sum<10){
		if(k[u->second]<3){printf("%lld\n",abs((u->first)%10000));k[u->second]++;sum++;}
		}
		else if(sum<20){if(k[u->second]<2){printf("%lld\n",abs(u->first%10000));k[u->second]++;sum++;}}
		else if(k[u->second]==0){printf("%lld\n",abs(u->first%10000));k[u->second]++;sum++;}
	    }
    }
}

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

string divide[4] = { "dream", "dreamer", "erase", "eraser" };

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

	reverse(S.begin(), S.end());	// Sをreverse
	for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end()); // divideをそれぞれreverse

	bool can = true;
	for (int i = 0; i < S.size();) {
		bool can2 = false;
		for (int j = 0; j < 4; ++j) {
			string d = divide[j];
			if (S.substr(i, d.size()) == d) {	// i番目からd.size()番目までとdが一致するか
				can2 = true;
				i += d.size();
			}
		}
		if (!can2) {
			can = false;
			break;
		}
	}

	if (can) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define maxn 10010
using namespace std;
int cnt, p[maxn], n, a[maxn], b[maxn];
int gcd(int a, int b)
{
	if (a == 0) return b;
	if (b == 0) return a;
	int y = a % b;
	while (y)
	{
		a = b;
		b = y;
		y = a % b;
	}
	return b;
}
bool prime(int x)
{
	if (x == 1) return false;
	for (int i = 2; i <= sqrt(x); i++)
		if (x % i == 0) return false;
	return true;
}
bool check(int x)
{
	if (x > n + 1) return true;
	for (int i = 0; i <= n; i++)
		b[i] = (a[i] % x + x) % x;
	for (int i = n; i >= x; i--)
	{
		int tmp = b[i], pos;
		pos = i - x + 1;
		b[pos] = (b[pos] + tmp) % x;
	}
	for (int i = x - 1; i >= 0; i--)
		if (b[i] % x) return false;
	return true;
}
int main()
{
	int g = 0;
	scanf("%d", &n);
	for (int i = 2; i <= n; i++)
		if (prime(i)) p[++cnt] = i;
	for (int i = n; i >= 0; i--)
	{
		scanf("%d", &a[i]);
		g = gcd(abs(a[i]), g);
	}
	for (int i = 2; i * i <= g; i++)
		if (g % i == 0)
		{
			p[++cnt] = i;
			while (g % i == 0) g /= i;
		}
	if (g != 1) p[++cnt] = g;
	sort(p + 1, p + cnt + 1);
	for (int i = 1; i <= cnt; i++)
		if (p[i] != p[i - 1] && check(p[i])) printf("%d\n", p[i]);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;


int Input[55];
int Temp[55];

int main() {
  int N; cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> Input[i];
    Temp[i] = Input[i];
  }
  
  sort(Temp, Temp+N);
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (Temp[i] - Input[i] != 0) {
      ans++;
    }
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>

typedef long long int llint;

int main(void){
  int k, a, b;
  std::cin >> k >> a >> b;

  for(int i=a; i<=b; i++){
    if(i%k==0){
      std::cout << "OK" << std::endl;
      return 0;
    }
  }

  std::cout << "NG" << std::endl;
  
  return 0;
}


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

int main() {
    int n;cin>>n;
    ll a[n],t[n];
    rep(i,n){
        cin>>a[i]>>t[i];
        if(i!=0){
            ll a1=1;
            ll t1=1;
            if(a[i]<a[i-1]){
                a1=a[i-1]/a[i];
                if(a[i-1]%a[i]!=0)++a1;
            }
            if(t[i]<t[i-1]){
                t1=t[i-1]/t[i];
                if(t[i-1]%t[i]!=0)++t1;
            }
            a[i]*=max(a1,t1);
            t[i]*=max(a1,t1);                
            }
    }
    cout<<a[n-1]+t[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    string S;
    cin >> S;

    int ans = 0;
    int curr = 0;
    for (int i = 0; i < 3; ++i) {
        if (S[i] == 'R') {
            ++curr;
        } else {
            ans = max(ans, curr);
            curr = 0;
        }
    }
    ans = max(ans, curr);

    cout << ans << endl;

    return 0;
}


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

int main() {
  string s;
  getline(cin, s);
  if((s[1] == s[2]) && ((s[0] == s[1]) || (s[2] == s[3])))
    cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
// Convex Hull
// 問題URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_A&lang=jp
// 中央*右
// 
// 参考文献[3]を参考にしつつ実装しましたが全然分からず、3時間以上かかりました...
// 点を加えたら凸性が崩れる場合があるというのと、一直線になる場合に気づかずハマりました。

#include <iostream>
#include <vector>
#include <complex>
#include <algorithm>

using namespace std;

#define pdd pair<double, double> 
typedef complex<double> xy_t;

int N;
vector<pdd> vec, ansU, ansL;
double X[100000+5], Y[100000+5];

double cross_product(xy_t a, xy_t b) {return (conj(a)*b).imag();}

bool convex(pdd p1, pdd p2, pdd p3){ //左向きに並んでいるか?
    xy_t a(p1.first, p1.second);
    xy_t b(p2.first, p2.second);
    xy_t c(p3.first, p3.second);

    xy_t e1 = b - a;
    xy_t e2 = c - b;
    
    // cout << "Area by a:" << a << " b:" << b << " c:" << c << " is " << cross_product(e1, e2) << endl;

    if (cross_product(e1, e2) >= 0)
        return true; //符号付面積が正または0なら左向き ※一直線になる場合もあることに注意
    else 
        return false; //右向き
}

bool check(vector<pdd> ans_buff, pdd p){
    if(ans_buff.size() < 2) return true;

    pdd p_buff1 = ans_buff.back(); ans_buff.pop_back(); //p1に相当
    pdd p_buff2 = ans_buff.back(); //p0に相当

    if(convex(p_buff2, p_buff1, p)) return true; //点の順番に注意する
    
    return false;
}

int main(){
    cin >> N;

    for(int i = 0; i < N; i++){
        cin >> X[i] >> Y[i];
        vec.push_back(make_pair(X[i], Y[i]));
    }

    //下側の計算
    sort(vec.begin(), vec.end());

    ansL.push_back(vec[0]);ansL.push_back(vec[1]); //最初の2点を格納

    for(int i = 2; i < N; i++){ //下側の点列を生成
        pdd p3 = vec[i];
        // cout << "Cuurent: (" << p3.first << ", " << p3.second << ")"<< endl;
        pdd p2 = ansL.back(); ansL.pop_back();
        pdd p1 = ansL.back();

        if(convex(p1, p2, p3)){ //p2をansに戻す
            ansL.push_back(p2);
        }
        else{
            while(!check(ansL, p3)) //p3を加えるに際しp2より前の点も取り除く必要がないか確認
                ansL.pop_back();
        }   
        ansL.push_back(p3); //p3を追加
    }
    ansL.pop_back(); //終点を削除

    //上側の計算
    reverse(vec.begin(), vec.end()); //x座標を昇順に並べる
    ansU.push_back(vec[0]); ansU.push_back(vec[1]); //最初の2点を格納

    for(int i = 2; i < N; i++){ //上側の点列を生成
        pdd p3 = vec[i];
        // cout << "Cuurent: (" << p3.first << ", " << p3.second << ")"<< endl;
        pdd p2 = ansU.back(); ansU.pop_back();
        pdd p1 = ansU.back();

        if(convex(p1, p2, p3)){ //p2をansに戻す
            ansU.push_back(p2);
        }
        else{
            while(!check(ansU, p3)) //p3を加えるに際しp2より前の点も取り除く必要がないか確認
                ansU.pop_back();
        }   
        ansU.push_back(p3); //p3を追加
    }
    ansU.pop_back(); //終点を削除

    //出力開始位置が最も下にあるものの中で最も左にある頂点になるよう調整
    while( ansL.size() >= 2 && ansL[0].second > ansL[1].second){
        ansU.push_back(ansL.front());
        ansL.erase(ansL.begin());
    }

    //出力
    cout << ansU.size() + ansL.size() << endl;

    for(auto itr=ansL.begin(); itr!=ansL.end(); itr++){
        cout << itr->first << " " << itr->second << endl;
    }

    for(auto itr=ansU.begin(); itr!=ansU.end(); itr++){
        cout << itr->first << " " << itr->second << endl;
    }
}




Measured memory_bytes: 7580
#include<bits/stdc++.h>
using namespace std;
char s[100];
int main()
{
	scanf("%s", s + 1);
	int len = strlen(s + 1), sum = 0;
	for (int i = 1; i <= len; i++)
		if (s[i] == 'x') sum++;
	if (sum > 7) puts("NO");
	else puts("YES");
	return 0;
}

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

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

  vector<long int> l(n + 1);
  for (int i = 0; i < n + 1; i++) {
    if (i == 0)
      l[0] = 2;
    else if (i == 1)
      l[1] = 1;
    else if (i >= 2)
      l[i] = l[i - 1] + l[i - 2];
  }

  cout << l[n] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for (int i=1;i<=n;i++)
int a[100],n,p;
long long dp[51][2];
int main()
{
	//freopen("input.txt","r",stdin);
    cin>>n>>p;
    for (int i=1;i<=n;i++){
    	int x;
    	cin>>x;
    	a[i]=x%2;
    }
    dp[1][0]=1;
    if (a[1]) dp[1][1]=1;
    else dp[1][0]=2;
    for (int i=2;i<=n;i++){
    	if (a[i]){
    		dp[i][1]=dp[i-1][0]+dp[i-1][1];
    		dp[i][0]=dp[i][1];
    	}
    	else{
    		dp[i][1]=dp[i-1][1]*2;
    		dp[i][0]=dp[i-1][0]*2;
    	}
    }
    cout<<dp[n][p];
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        for (int i = 0; i < n + 1; i++) {
            if (n == Math.floor(i * 1.08)) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(":(");
    }
}


Measured memory_bytes: 23228
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define int long long 
typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=200005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int N, K, A[MAXN];
bool cmp(int x, int y){
	return abs(x) > abs(y);
}
main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> K;
	FOR(i,1,N) cin >> A[i];
	int ans = 1;
	if (K == N){
		FOR(i,1,K) ans *= A[i], ans %= MOD;
		ans = (ans + MOD)%MOD;
		cout<<ans;
		exit(0);
	}
	int p = 0, z = 0, n = 0;
	FOR(i,1,N){
		if (A[i] > 0) p++;
		else if (A[i] == 0) z++;
		else n++;
	}
	
	if (p==0){
		if (K%2==0){
			FOR(i,1,N) A[i] = abs(A[i]);
			sort(A+1, A+1+N, greater<int>());
			FOR(i,1,K) ans *= A[i], ans %= MOD;
			ans = (ans + MOD)%MOD;
			cout<<ans;
			exit(0);
		}
		else{
			if (z > 0){
				cout<<0;
				exit(0);
			}
			FOR(i,1,N) A[i] = abs(A[i]);
			sort(A+1, A+1+N);
			FOR(i,1,K) ans *= -A[i], ans %= MOD;
			ans = (ans + MOD)%MOD;
			cout<<ans;
			exit(0);
		}
	}
	vi pos, neg; 
	FOR(i,1,N){
		if (A[i] > 0) pos.pb(A[i]);
		else neg.pb(-A[i]);
	}
	sort(all(pos),greater<int>());
	sort(all(neg),greater<int>());
	int pidx = min(K, sz(pos));
	int nidx = max(0LL, K - sz(pos));
	if (nidx % 2!=0) {
		pidx--;
		nidx++;
		assert(nidx <= sz(neg));
	}
	//db(pidx); db(nidx);
	while (pidx > 1 && nidx < sz(neg)){
		//db(pidx); db(nidx);
		int pos_loss = pos[pidx-1] * pos[pidx-2];
		int neg_gain = neg[nidx] * neg[nidx+1];
		if (pos_loss < neg_gain){
			pidx-=2;
			nidx+=2;
		}
		else break;
	}
	ans = 1;
	//db(pidx); db(nidx);
	FOR(i,1,pidx){
		ans *= pos[i-1];
		ans %= MOD;
	}
	FOR(i,1,nidx){
		ans *= neg[i-1];
		ans %= MOD;
	}
	cout<<ans;
}
/*
5 3
-100 -1 -1 1000 1000
*/


Measured memory_bytes: 6816
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
	for (int i = (int)(n / 1.08); i <= n; i++) {
		if ((int)(i * 1.08) == n) {
			cout << i;
			return 0;
		}
		if ((int)(i * 1.08) > n) {
			cout << ":(";
			return 0;
		}
	}
}

Measured memory_bytes: 256
/**
 * @param input string[]
 */
function Main(input) {
  const songs = input.slice(1, -1).map((line) => line.split(' '));
  const X = input[input.length - 1];

  var i = 0;
  var XIndex;
  while (true) {
    if (songs[i][0] === X) {
      XIndex = i;
      break;
    }
    i++;
  }

  const answer = songs.slice(XIndex + 1).reduce((pv, cv) => {
    return pv + (+cv[1]);
  }, 0);

  console.log(answer);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim()
  .split('\n')
);


Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>

typedef long long ll;

using namespace std;

int main(void) {
  int N, K; cin >> N >> K;
  vector<int> x(N);
  for (int i = 0; i < N; i++) { cin >> x[i]; }

  int d = INT_MAX;
  for (int i = 0; i < N - K + 1; i++) {
    int l = i, r = i + K - 1;
    int cr = abs(x[r]) + abs(x[r] - x[l]);
    int cl = abs(x[l]) + abs(x[r] - x[l]);
    d = min(d, min(cr, cl));
  }
  cout << d << endl;
}


Measured memory_bytes: 640
n, m, x = gets.chomp.split(' ').map{|i| i.to_i}
a = gets.chomp.split(' ').map{|i| i.to_i}
left = 0
right = 0
a.each do |i|
        (i < x) ? left += 1 : right += 1
end
puts "#{(left < right) ? left : right}"

Measured memory_bytes: 1788
fun <T : Comparable<T>> List<T>.insertPosition(e: T): Int {
    var low = 0
    var high = size
    while (low < high) {
        val middle = (low + high) / 2
        if (this[middle] < e) {
            low = middle + 1
        } else {
            high = middle
        }
    }
    return low
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(' ').map(String::toInt).sorted()
    val bb = readLine()!!.split(' ').map(String::toInt)
    val cc = readLine()!!.split(' ').map(String::toInt).sorted()
    var sum = 0L
    for (b in bb) {
        val posA = aa.insertPosition(b)
        val posC = cc.insertPosition(b + 1)
        sum += posA.toLong() * (n - posC).toLong()
    }
    println(sum)
}


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

int main(){
  int r;
  cin >> r;
  
  if(r<1200)cout << "ABC" << endl;
  else if(r>=1200 && r<2800)cout << "ARC" << endl;
  else cout << "AGC" << endl;
  
  return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
S_list = []
T_list = []
n = 0
for i in range(len(S)):
    S_list.append(S[i])
    T_list.append(T[i])
for j in range(len(S)):
    if S_list == T_list:
        n = 1
        break
    else:
        a = T_list[0]
        T_list.append(a)
        T_list.remove(a)
if n == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main(){
  int c, n, s = 0;
  cin >> c >> n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
    s = s+ a[i];
  }
  if(s >= c){
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
}

Measured memory_bytes: 3948
n,k=map(int,input().split())
a=list(map(int,input().split()))
K=str(format(k,'b'))
M=str(format(max(a),'b'))
x=max(len(K),len(M))
K=str(format(k,'b').zfill(x))
l=[]
for i in range(n):
  l.append(str(format(a[i],'b').zfill(x)))
ctMz=0
for z in range(len(K)):
  if K[z]=='0':
    ctMz+=1
  else:
    break

l2=[]
l2=['0' for b in range(x)]
ct=0
for j in range(x):
  ctz=0
  cto=0
  for m in range(n):
    if l[m][j]=='0':ctz+=1
    else:cto+=1
  if j+1<=ctMz:
    ct+=(2**(x-j-1))*cto
    l2[j]='0'
  else:
    if ctz>cto:
      l2[j]='1'
      if int(K)>=int(''.join(l2)):
        ct+=(2**(x-j-1))*ctz
      else:
        ct+=(2**(x-j-1))*cto
        l2[j]='0'
    else:
      ct+=(2**(x-j-1))*cto
      l2[j]='0'
print(ct)

Measured memory_bytes: 17820
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;

int main() {
    int N;
    cin >> N;
    set<string> A;
    for (int i = 0; i < N; i++){
        string a;
        cin >> a;
        A.insert(a);
    }
    cout << A.size() << endl;
}

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

bool vis[10];

int n, k;

bool check(int k) {
	while (k) {
		int t = k % 10;
		k /= 10;
		if (vis[t]) return 0;
	}
	return 1;
}

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= k; i ++) {
		int x;
		scanf("%d", &x);
		vis[x] = 1;
	}
	while (!check(n)) n ++;
	printf("%d\n", n);
	return 0;
}


Measured memory_bytes: 3816
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def sieve(n):
    res = [True for _ in range(n + 1)]
    res[0] = False
    res[1] = False
    i = 2
    while i * i <= n:
        if res[i]:
            for j in range(i * 2, n + 1, i):
                res[j] = False
        i += 1
    return res

def factorize(n):
    if n == 1: return []
    res = []
    x, y = n, 2
    while y * y <= x:
        while x % y == 0:
            res.append(y)
            x //= y
        y += 1
    if x > 1:
        res.append(x)
    return res

from collections import Counter, defaultdict

N = int(input())
A = list(map(int, input().split()))

S = sieve(10**6 + 1)

flag = True

for i in range(N):
    if S[A[i]]:
        S[A[i]] = 0
    else:
        F = set(factorize(A[i]))
        for f in F:
            if S[f]:
                S[f] = 0
            else:
                flag = False
                break
        else:
            continue
        break

if flag:
    print('pairwise coprime')

else:
    res = 0
    for i in range(N):
        res = gcd(res, A[i])
    if res == 1:
        print('setwise coprime')
    else:
        print('not coprime')

Measured memory_bytes: 208952
#include<stdio.h>

int main(void) {

 int n;

 int x;

 int num;

 int min = 1000001;

 int max = -1000001;

 long total = 0;


 scanf("%d",&n);

 for(x = 0; x < n; x++){

 scanf("%d",&num);

 if(min >num)min = num;

 if(max < num)max = num;

total += num;

}

printf("%d %d %ld\n",min,max,total);

return 0;

}

Measured memory_bytes: 600
def IsOdd(n):
    return n & 1

N, A, B = map(int, input().split())

if IsOdd(B-A):
    ans = min((B+A-1) // 2, (2*N-A-B+1) // 2)
    print(ans)
else:
    print((B-A) // 2)


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

using namespace std;

#define fRead(x)  freopen(x,"r",stdin)
#define fWrite(x) freopen (x,"w",stdout)

#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define INF 2e16
#define PI acos(-1.0)
#define mk make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>


#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define SQR(a) ((a)*(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define ABS(x) ((x)<0?-(x):(x))

#define scanI(a) scanf("%d",&a)
#define scanI2(a,b) scanI(a) , scanI(b)
#define scanI3(a,b,c) scanI(a), scanI(b), scanI(c)
#define scanI4(a,b,c,d) scanI(a), scanI(b), scanI(c), scanI(d)

#define scanL(a) scanf("%I64d",&a)
#define scanL2(a,b) scanL(a) , scanL(b)
#define scanL3(a,b,c) scanL(a), scanL(b), scanL(c)
#define scanL4(a,b,c,d) scanL(a), scanL(b), scanL(c), scanL(d)

#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())


#define FastRead ios_base::sync_with_stdio(0);cin.tie(nullptr);

int main()
{
    LL n;
    cin >> n;
    vector<LL>v(3*n);
    REP(i,3*n)cin >> v[i];
    SORT(v);
    REV(v);
    int cnt = 1;
    LL ans = 0;
    for(int i = 1;cnt<=n;i+=2,cnt++){
        ans += v[i];
    }
    cout << ans << "\n";
}


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

class DsuClass {
public:
  DsuClass(int n) : p(n), s(n, 1) {
    for (int i = 0; i < n; i++)
      p[i] = i;
  }

  int get_parent(int x) {
    if (p[x] == x)
      return x;
    return p[x] = get_parent(p[x]);
  }

  void merge(int x, int y) {
    int px = get_parent(x), py = get_parent(y);
    if (px != py) {
      if (s[px] < s[py]) {
        p[px] = py;
        s[py] += s[px];
      }
      else {
        p[py] = px;
        s[px] += s[py];
      }
    }
  }

  int get_size(int x) {
    return s[x];
  }

private:
  vector<int> p, s;
};

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<pair<int, int>> e;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    e.emplace_back(a - 1, b - 1);
  }

  DsuClass dsu(n);
  vector<long long> ans;
  for (int i = m - 1; i >= 0; i--) {
    int pa = dsu.get_parent(e[i].first), pb = dsu.get_parent(e[i].second);
    long long v = 0;
    if (pa != pb) {
      v = 1LL * dsu.get_size(pa) * dsu.get_size(pb);
      dsu.merge(pa, pb);
    }
    ans.emplace_back(v);
  }
  
  for (int i = m - 1; i >= 0; i--) {
    if (i + 1 < m)
      ans[i] += ans[i + 1];
    printf("%lld\n", ans[i]);
  }

  return 0;
}

Measured memory_bytes: 3828
import java.util.*;

class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        if((A + B) == 4) System.out.println("2");
        if((A + B) == 3) System.out.println("3");
        if((A + B) == 5) System.out.println("1");
    }
}

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

using namespace std;

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  int n = X / (Y + Z);
  if ((Y + Z) * n + Z <= X) {
    cout << n;
  } else {
    cout << max(n - 1, 0);
  }
  return 0;
}


Measured memory_bytes: 256
def main():
    N, T = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    AB.sort()
    A = [a[0] for a in AB]
    B = [b[1] for b in AB]

    dp1 = [[0]*(T+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(T):
            dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j])

            t = j - A[i]
            if 0 <= t:
                dp1[i+1][j] = max(dp1[i+1][j], dp1[i][t] + B[i])
    ans = 0
    for i in range(N):
        ans = max(ans, dp1[i][T-1] + B[i])
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
  int a,b;
  cin >> a >> b;
  bool flg=false;
  for(int i=1;i<=3;i++){
    if(a*b*i%2==1){
      flg=true;
      break;
    }
  }
  if(flg){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  double ans=a[0];
  for(int i=1;i<n;i++){
    ans=(ans+a[i])/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
  long long int N;
  long long int A, B;
  cin >> N >> A >> B;
  long long int a = N / (A + B);
  long long int b = N % (A + B);
  cout << a * A + min(A, b) << endl;
}

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

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




int main()
{
	double a, b, h, m;
	cin >> a >> b >> h >> m;

	cout << fixed << setprecision(15) << "\n";


	
		double long_ang = m * 360 / 60;
		double short_ang = (h * 60  + m) * 360  / (12 * 60);

		//cout << long_ang << "\n";
		//cout << short_ang << "\n";

		double ang = 0;

		if((short_ang - long_ang) >= 180) ang = 360 - (short_ang - long_ang);
		else ang = short_ang - long_ang;


		double ans_ang = M_PI * ang / 180;


		double sq_1 = pow(a, 2) + pow(b, 2);
		double sq_2 = 2 * a * b * (cos(ans_ang));

		//cout << sq_1 - sq_2 << "\n";

		cout << sqrt(sq_1 - sq_2) << "\n";
	


	return 0;

}

Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		char[] S = sc.next().toCharArray();
		char[] P = sc.next().toCharArray();
		int n = S.length;
		int m = P.length;

		int[] T = new int[m + 1];
		T[0] = -1;
		T[1] = 0;
		int i = 2;
		int j = 0;
		while(i <= m) {
			if(P[i-1] == P[j]) {
				T[i] = j + 1;
				i++;
				j++;
			} else if(j > 0) {
				j = T[j];
			} else {
				T[i] = 0;
				i++;
			}
		}

		i = 0;
		j = 0;
		StringBuilder ans = new StringBuilder();
		while(i + j < n) {
//			System.out.println("i = " + i);
			if(P[j] ==S[i + j]) {
				j++;
				if(j == m) {
					ans.append(i);
					ans.append("\n");
				} else {
					continue;
				}
			}
			i = i + j - T[j];
			if(j > 0) {
				j = T[j];
			}
		}

		System.out.print(ans);
	}

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 76696
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

#include <climits>

using namespace std;

int main()

{
	string s;
	cin >> s;

	int start = 0;
	
	for(int i = 0 ; i < s.size() ; i++) {
		if (s[i] == 'A') {
			start = i;
			break;
		}
	}

	int end = 0;
	for (int i = s.size(); i > 0; i--) {
		if (s[i] == 'Z') {
			end = i;
			break;
		}

	}

	cout << end-start+1 << endl;

	return 0;

}

Measured memory_bytes: 3760
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String lineA = br.readLine();
		String lineB = br.readLine();
		String lineC = br.readLine();
		int indexA = 0;
		int indexB = 0;
		int indexC = 0;
		char ch = lineA.charAt(indexA++);
		while (true) {
			if (ch == 'a') {
				if (indexA == lineA.length()) {
					System.out.println("A");
					break;
				}
				ch = lineA.charAt(indexA++);
			}
			else if (ch == 'b') {
				if (indexB == lineB.length()) {
					System.out.println("B");
					break;
				}
				ch = lineB.charAt(indexB++);
			}
			else if (ch == 'c') {
				if (indexC == lineC.length()) {
					System.out.println("C");
					break;
				}
				ch = lineC.charAt(indexC++);
			}
		}
	}
}


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

int main() {

	string S;
    cin >> S;
  
	int y=700;
  
	if (S[0] == 'o') y = y + 100;
    if (S[1] == 'o') y = y + 100;
    if (S[2] == 'o') y = y + 100;
  
    cout << y << endl;

}


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int n;
	cin >> n;
	int b[150];
	rep(i, n - 1) {
		cin >> b[i];
	}
	int ans = 0;
	ans += b[0];
	for (int i = 1; i < n - 1; i++) {
		ans += min(b[i], b[i - 1]);
	}
	ans += b[n - 2];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

int main() {
	cout << fixed << setprecision(12);	
	ll x, y;
	cin >> x >> y;
	int ret = 0;
	while (x <= y) {
		ret++;
		x *= 2;
	}
	cout << ret << endl;
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



Measured memory_bytes: 3616
# input as list
a,b,c = [list(input()) for i in range(3)]

# set initial
temp = 'a'

# loop start
while True:
    if temp == 'a':
        if len(a) == 0:
            print('A')
            break
        else:
            temp = a.pop(0)
    elif temp == 'b':
        if len(b) == 0:
            print('B')
            break
        else:
            temp = b.pop(0)
    elif temp == 'c':
        if len(c) == 0:
            print('C')
            break
        else:
            temp = c.pop(0)

#eof

Measured memory_bytes: 3064
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


# import re
# import array
# import copy
# import functools
# import operator

# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd

# import collections
# import itertools
# import bisect

# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue

# from itertools import accumulate

# from collections import deque
# from collections import Counter

# from operator import mul
# from functools import reduce

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random
# import time


def main():
    n = int(input().strip())
    a = [0 for i in range(n)]
    for i in range(n):
        a[i] = int(input().strip()) - 1
    cnt = 0
    que = Queue()
    que.put(0)
    l_usedlist = [0 for i in range(n)]
    while que.qsize() > 0:
        v_current = que.get()
        l_usedlist[v_current] = 1
        cnt += 1
        if a[v_current] == 1:
            print(cnt)
            return
        else:
            if l_usedlist[a[v_current]] == 0:
                que.put(a[v_current])
    print(-1)
    return


if __name__ == '__main__':
    main()


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

#define ipr 			pair<int, int>
#define pb 				push_back
#define ff 				first
#define ss 				second
#define mp 				make_pair
#define fr(i, j, k) 	for (int i = j; i < k; i++)
#define rf(i, j, k) 	for (int i = j; i >= k; i--)
#define int 			long long
#define ll 				unsigned long long
#define ld 				long double
#define all(x) 			x.begin(), x.end()
#define rall(x) 		x.rbegin(), x.rend()
#define cnt_ones(x) 	__builtin_popcountll(x)
#define dbg() 			cerr << "okay" << endl;			

#define IOS                           \
	std::ios::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);

const int inf = 1000000000000000000;
const int Maxn = 100001;
const ld pi = acos(-1);
const int mod = 998244353;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A)
{
	for (auto x : A)
		out << x << " ";
	return out;
}

int n, e;
vector<vector<int > > g;
vector<vector<int>> dis;

void graph_print(){
    fr(i,0,n)
        cout << g[i] << endl;
}

void graph_inp(){
    g.resize(n);
    e = n-1;    //for a tree
    fr(i,0,e){
        int u,v;    cin>>u>>v;
        --u;   --v;
        g[u].pb(v);
        g[v].pb(u);
    }  
    
}

void bfs(int root, int col){
    queue<int> q;   q.push(root);
    dis[root][col] = 0;
    while(!q.empty()){
        int node = q.front();   q.pop();
        for(auto child : g[node])
            if(dis[child][col] == -1){
                dis[child][col] = dis[node][col] + 1;
                q.push(child);
            }
          
    }
}

//More complete and meaningful question
// https://codeforces.com/contest/813/problem/C
int32_t main(){IOS
    int x,y, ans=0;
    cin>>n>>x>>y;  x--; y--;
    graph_inp();
    dis.resize(n, vector<int>(2, -1));
    bfs(y,0);   bfs(x,1);
    fr(i,0,n)
       if(dis[i][1] < dis[i][0])
            ans = max(ans, dis[i][0]);
    cout << ans-1 << endl;
	return 0;
}

Measured memory_bytes: 11904
#include <iostream>
#include <vector>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
    int n,x,t;
    cin>>n>>x>>t;
    if(n%x==0){
        cout<<n/x*t<<endl;
    }else{
        cout<<(n/x+1)*t<<endl;
    }
    return 0;
}  


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 200001


int main(){	
	string s;
	cin>>s;
	if(s=="ABC"){
		cout<<"ARC"<<endl;
	}
	else{
		cout<<"ABC"<<endl;
	}


	
}

Measured memory_bytes: 3604
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

struct dijkstra{
    struct edge{int to; int cost;};
    vector<vector<edge>> graph;
    vector<int> dist;
    int MAX_dist;

    // 頂点数を入れる
    dijkstra(int n): graph(n,vector<edge>(0)){
        MAX_dist = inf;
    dist.resize(n,MAX_dist);
    }

    // 一方向に辺を追加
    void add(int from, int to, int cost){
        graph[from].push_back({to, cost});
        return;
    }

    // 双方向に辺を追加
    void add_both(int edge_one, int edge_two, int cost){
        graph[edge_one].push_back({edge_two,cost});
        graph[edge_two].push_back({edge_one,cost});
        return;
    }

    // 計算する
    void culc(int s){
        priority_queue<P, vector<P>, greater<P>> que;
        dist[s]=0;
        que.emplace(0,s);
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(dist[v]<p.first) continue;
            for(auto e: graph[v]){
                if(dist[e.to]>dist[v]+e.cost){
                    dist[e.to]=dist[v]+e.cost;
                    que.emplace(dist[e.to],e.to);
                }
            }
        }
    }

    // 距離を出す
    int ans(int t){
        return dist[t];
    }
};

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,m;
    cin>>n>>m;
    dijkstra dk(n*3);

    int x,z;
    rep(i,m){
        cin>>x>>z;
        x --,z --;
        dk.add(x,z+n,1);
        dk.add(x+n,z+n+n,1);
        dk.add(x+n+n,z,1);
    }
    int s,t;
    cin>>s>>t;
    s--,t--;

    dk.culc(s);
    int ans=dk.ans(t);
    if(ans==dk.MAX_dist) cout<<-1<<endl;
    else cout<<ans/3<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 20860
package main

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


const (
	MAX = 10000
	NIL = -1
)

type Node struct {
	parent int
	left   int
	right  int
}

var n int
var T = make([]Node, MAX)
var D = make([]int, MAX)
var H = make([]int, MAX)

func setDepth(u, d int) {
	if u == NIL {
		return
	}
	D[u] = d
	setDepth(T[u].left, d+1)
	setDepth(T[u].right, d+1)
}

func setHeight(u int) int {
	var h1, h2 int
	if T[u].left != NIL {
		h1 = setHeight(T[u].left) + 1
	}
	if T[u].right != NIL {
		h2 = setHeight(T[u].right) + 1
	}
	if h1 > h2 {
		H[u] = h1
	} else {
		H[u] = h2
	}
	return H[u]
}

// return sibling of node u
func getSibling(u int) int {
	if T[u].parent == NIL {
		return NIL
	}
	if T[T[u].parent].left != u && T[T[u].parent].left != NIL {
		return T[T[u].parent].left
	}
	if T[T[u].parent].right != u && T[T[u].parent].right != NIL {
		return T[T[u].parent].right
	}
	return NIL
}

func Print(u int) {
	fmt.Printf("node %d: ", u)
	fmt.Printf("parent = %d, ", T[u].parent)
	fmt.Printf("sibling = %d, ", getSibling(u))
	var deg int
	if T[u].left != NIL {
		deg++
	}
	if T[u].right != NIL {
		deg++
	}
	fmt.Printf("degree = %d, ", deg)
	fmt.Printf("depth = %d, ", D[u])
	fmt.Printf("height = %d, ", H[u])

	if T[u].parent == NIL {
		fmt.Println("root")
	} else if T[u].left == NIL && T[u].right == NIL {
		fmt.Println("leaf")
	} else {
		fmt.Println("internal node")
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	var v, l, r, root int
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())
	for i := 0; i < n; i++ {
		T[i].parent = NIL
	}
	for i := 0; i < n; i++ {
		sc.Scan()
		ss := strings.Split(sc.Text(), " ")
		v, _ = strconv.Atoi(ss[0])
		l, _ = strconv.Atoi(ss[1])
		r, _ = strconv.Atoi(ss[2])
		T[v].left = l
		T[v].right = r
		if l != NIL {
			T[l].parent = v
		}
		if r != NIL {
			T[r].parent = v
		}
	}
	for i := 0; i < n; i++ {
		if T[i].parent == NIL {
			root = i
		}
	}
	setDepth(root, 0)
	setHeight(root)
	for i := 0; i < n; i++ {
		Print(i)
	}
}



Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;
const int mod = 1e9 + 7;
const double EPS = 1e-9;


int main(){
	int n, t, ans;
	while(cin>>n && n > 0){
		map<int,int> mp;
		for(int i = 0; i < n; i++){
			cin>>t;
			++mp[t];
		}
		ans = -1;
		for(auto it = mp.begin(); it != mp.end(); ++it){
			if(it->se*2>n) ans = it->fi;
		}
		if(ans == -1) cout<<"NO COLOR"<<endl;
		else cout<<ans<<endl;
	}
}	

Measured memory_bytes: 4524
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

string RD() { return chomp(readln()); }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto tokens = RD.split;
	auto H = tokens[0].to!long;
	auto W = tokens[1].to!long;
	
	string[] s;
	foreach (i; 0..H)
	{
		s ~= RD;
	}

	bool visit(long i, long j)
	{
		if (i < 0 || i >= H || j < 0 || j >= W) return false;

		return s[i][j] == '#';
	}

	bool cant = false;
	foreach (i; 0..H)
	{
		foreach (j; 0..W)
		{
			if (s[i][j] == '.') continue;

			bool r = false;
			r |= visit(i-1, j);
			r |= visit(i+1, j);
			r |= visit(i, j-1);
			r |= visit(i, j+1);
			if (!r) cant = true;
		}
	}

	writeln(cant ? "No" : "Yes");
	stdout.flush();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int n,m,q;
int ans;
vector<int> a,b,c,d;

void dfs(vector<int> vc)
{
  if(vc.size()==n){
    int tmp = 0;
    REP(qq,q){
      if(vc[b[qq]]-vc[a[qq]]==c[qq]) tmp += d[qq];
    }
    ans = max(ans, tmp);
  }else{
    for(int i=vc.back(); i<=m; i++){
      vc.push_back(i);
      dfs(vc);
      vc.pop_back();
    }
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> q;
  a.resize(q);
  b.resize(q);
  c.resize(q);
  d.resize(q);
  REP(qq,q){ 
    cin >> a[qq] >> b[qq] >> c[qq] >> d[qq];
    a[qq]--, b[qq]--;
  }
  ans = 0;
  REP(i,m){
    vector<int> v;
    v.push_back(i+1);
    dfs(v);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
const double pi = 3.14159265358979;

int main(){
    double a, b, h, m; cin >> a >> b >> h >> m;
    double hour = h / 12.0 * 2 * pi + m / 60.0 * pi / 6.0;
    double minute = m / 60.0 * 2 * pi;
    cout << setprecision(15) << sqrt(a*a + b*b - 2*a*b*cos(abs(hour-minute))) << endl;
    return 0;
}

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

#define int long long

signed main(){
    int n;
    cin>>n;
    priority_queue<double, vector<double>, greater<double>> q;
    double tmp;
    for(int i=0; i<n; i++){
        cin>>tmp;
        q.push(tmp);
    }
    while(q.size() != 1){
        double i1 = q.top();
        q.pop();
        double i2 = q.top();
        q.pop();
        double i3 = (i1+i2)/2;
        q.push(i3);
    }
    double res = q.top();
    q.pop();
    printf("%0.10f\n", res);
    return 0;
}

Measured memory_bytes: 256