akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/
/****** define variable start ******/
ll h, w;
/******* define variable end *******/
ll solve() {
	cin >> h >> w;
	vector<vector<char>> a(h, vector<char>(w));
	vector<ll> count(26);
	REP(i, h){
		REP(j, w){
			cin >> a[i][j];
			int index = a[i][j] - 'a';
			count[index]++;
		}
	}
	vector<ll> count_vec;
	REP(i, 26){
		if(count[i] != 0){
			count_vec.push_back(count[i]);
		}
	}
	ll four_count = 0;
	ll two_count = 0;
	ll one_count = 0;
	REP(i, count_vec.size()){
		if(count_vec[i] >= 4){
			four_count++;
			count_vec[i] -= 4;
			i--;
		}
		else if(count_vec[i] >= 2){
			two_count++;
			count_vec[i] -= 2;
			i--;
		}
		else if(count_vec[i] >= 1){
			one_count++;
			count_vec[i] -= 1;
			i--;
		}
	}
	if(h % 2 == 0 && w % 2 == 0){
		if(four_count >= h * w / 4){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else if(h % 2 == 0 && w % 2 == 1){
		if(four_count >= h/2 * (w-1)/2 && two_count + (four_count - h/2 * (w-1)/2) * 2== h/2){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else if(h % 2 == 1 && w % 2 == 0){
		if(four_count >= (h-1)/2 * w/2 && two_count  + (four_count - (h-1)/2 * w/2) * 2== w/2){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else{
		if(four_count >= (h-1) / 2 * (w-1) / 2 && one_count == 1){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	return 0;
}
int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return (int)end_solve;
}


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

int main(){
    int n, k;
    cin >> n;
    int A[n], B[n];
    for(int i = 0; i < n ;i++){
        cin >> A[i];
        B[i] = A[i];
    }
    sort(B, B+n);    
    for(int i = 0; i < n; i++){
        if(A[i] != B[n-1]){
            cout << B[n-1] << endl;
        }else{
            cout << B[n-2] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int a[2], b[2];

int main(){
	cin >> a[0] >> b[0] >> a[1] >> b[1];
	
	cout << a[1]+b[0]-b[1] << " " << b[1]-a[0]+a[1] << " ";
	cout << a[0]+b[0]-b[1] << " " << b[0]-a[0]+a[1] << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int ans = (n - 1) / (k - 1);
        if ((n - 1) % (k - 1) != 0) {
            ans++;
        }
        System.out.println(ans);

        sc.close();
    }

}


Measured memory_bytes: 21844
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long A, B;

  std::cin >> A >> B;

  if (A == B) {
    std::cout << 0 << std::endl;
  }
  else if ((A + B) % 2 == 0) {
    std::cout << (A + B) / 2 << std::endl;
  }
  else {
    std::cout << "IMPOSSIBLE" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////		
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto i:a)
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve()
{
	IN(n);
	vl v;
	map<ll, ll>m;
	FOR(i, 0, n)
	{
		IN(in);
		v.pb(in);
	}
	FOR(i, 0, n)
	{
		ll k = v[i];
		FOR(j, 2, sqrt(k) + 1)
		{
			if (k % j == 0)
				m[j]++;
			while (k % j == 0)
			{
				k /= j;
			}
		}
		if (k != 1)
			m[k]++;
	}
	ll f = 0, f1 = 0;
	for (auto i : m)
	{
		if (i.second == n)
			f = 1;
		if (i.second > 1)
			f1 = 1;
	}
	if (f == 1)
	{
		cout << "not coprime";
	}
	else if (f1 == 1)
	{
		cout << "setwise coprime";
	}
	else
		cout << "pairwise coprime";
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}

Measured memory_bytes: 15936
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int A[100010];ll S[100010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),ans=0;
	for(int i=1;i<=n;++i)A[i]=gi();
	std::sort(A+1,A+n+1);
	for(int i=1;i<=n;++i)S[i]=S[i-1]+A[i];
	for(int i=1;i<=n;++i){
		ll now=A[i];
		int r=0;
		while(r<n){
			if(r+1==i){++r;continue;}
			if(now*2>=A[r+1]){
				int p=std::upper_bound(A+r+1,A+n+1,now*2)-A-1;
				now+=S[p]-S[r]-((r<i&&i<=p)?A[i]:0);r=p;
			}else goto gg;
		}
		++ans;gg:;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1408
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
def bubbleSort(a, n)
  res = 0
  flag = 1
  while flag == 1
    flag = 0
    (n-1).downto(1) do |j|
      if a[j] < a[j-1]
        a[j], a[j-1] = a[j-1], a[j]
        flag = 1
        res += 1
      end
    end
  end
  puts a.join(" ")
  puts res
end

bubbleSort(a, n)

Measured memory_bytes: 8632
import copy as cp
import itertools as itr
import numpy as np

H,W,K=map(int, input().split())
c=np.array([list(input()) for l in range(H)])
cnt=0

cnt=np.count_nonzero(c == '#')

hi=list(itr.product(range(2),repeat=H))
vi=list(itr.product(range(2),repeat=W))

ans=0

for i in range(len(hi)):
  for j in range(len(vi)):
    c1=cp.deepcopy(c)
    for i1 in range(H):
      if hi[i][i1]==1:
        c1[i1]='x'      
    for j1 in range(W):
      if vi[j][j1]==1:
        c1[:,j1]='x'
    cnt2=np.count_nonzero(c1 == '#')
    if cnt2==K:
      ans+=1
          
      
      

print(ans)

Measured memory_bytes: 26456
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define R register
#define LL long long
#define Maxn 100005

int n;
LL X,pos[Maxn];

inline LL gcd(R LL x,R LL y)
{
	return y ? gcd(y,x%y) : x;
}

int main()
{
	scanf("%d %lld",&n,&X);
	for (R int i=1;i<=n;++i) scanf("%lld",&pos[i]),pos[i]-=X;
	R LL ans=pos[1];
	for (R int i=2;i<=n;++i) ans=gcd(ans,pos[i]);
	printf("%lld\n",abs(ans));
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a[5];
    bool flg = true;
    for( int i = 0; i < 5; ++i ) {
        cin >> a[i];
    }
    int k;
    cin >> k;
    if( a[4] - a[0] <= k ) cout << "Yay!";
    else cout << ":(";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*

private data class Work(val start: Int, val end: Int, val dist: Int)
private data class Position(val pos: Int, val index: Int)

fun main(args: Array<String>) {

    /**
     * 同等のデータ構造, ロジックを実装しているが TLE で通らない,, java と kotlin の速度差?? どう分析するべきか
     * WAをあえて出すと実行時間を出力できる
     *
     * -> !! 最後の出力形式を for 文から　joinToString に変えると一気に早くなってAC
     */
    val (n, q) = readLine()!!.split(" ").map { it.toInt() }

    // 工事を格納 O(N)
    var workList = mutableListOf<Work>()

    for (i in 0 until n) {
        val (s, t, x) = readLine()!!.split(" ").map { it.toInt() }

        // 切り上げ，切り捨てをして閉区間で考える
        var start = Math.ceil(s - 0.5 - x).toInt()
        var end = Math.floor(t - 0.5 - x).toInt()

        workList.add(Work(start, end, x))
    }

    // 工事を距離が近い順にソート O(NlogN)
    workList.sortBy { it.dist }

    // スタート地点を配列に保持する（最初からソートされて渡されるのでソートの必要なし） O(N)
    // スタート地点の中で，ある工事区間に含まれるものを取り出し，配列から削除,
    var posSet = TreeSet<Position> { a, b -> a.pos - b.pos } // Comparator をラムダ式で渡す
    for (i in 0 until q) {
        posSet.add(Position(readLine()!!.toInt(), i))
    }


    // 答えにはデフォルトで -1 を設定 (選ばれなかったものは工事に合わない = -1 )
    val ans = IntArray(q) { -1 }


    for (work in workList) {

        // work.start よりも大きな開始地点を持つ posList 内の 最初の要素を指す イテレータを取得
        // O(logN)
        val comp = Position(work.start, -1)
        var position = posSet.ceiling(comp)

        // 工事に含まれる位置にいる posList の要素を取得し，削除
        while (position != null) {
            if (position.pos > work.end) {
                break
            }

            // O(logN)
            posSet.remove(position)

            // O(1)
            ans[position.index] = work.dist

            position = posSet.ceiling(comp)
        }
    }

    println(ans.joinToString("\n"))
//    for (a in ans) {
//        println(a)
//    }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> v(N*3);
  for(int i=0;i<N*3;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end(),greater<int>());
  int64_t ans=0;
  for(int i=1;;i+=2){
    ans+=v.at(i);
    if((i+1)/2==N){
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <stdexcept>
#include <utility>
// #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,n,h) for(int i = n; i < h; ++i)
#define rep3(l,n,h) for(int l = n; i <= h; ++i)
using namespace std;



int main() {
    string s;
    cin >> s;
    int n = 0;
    rep(i,4) {
        if(s[i] == '+') {
            n++;
        } else if(s[i] == '-'){
            n--;
        }
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
import fractions
def main():
    N, M = map(int, input().split())
    a = tuple(map(int, input().split()))
    s = a[0]
    s2 = a[0]
    s3 = 0
    while True:
        if s2 % 2 == 0:
            s2 /= 2
            s3 +=1
        else:
            break
    if s3 == 0:
        print(0)
        return 0
    for i in a:
        if i % (2 ** s3) != 0:
            print(0)
            return 0
        elif i % (2 ** (s3 + 1)) == 0:
            print(0)
            return 0
    for i in range(1,N):
        s = s * a[i] // fractions.gcd(s, a[i])
        if s > M*2:
            print(0)
            return 0
    s /= 2
    a = int(M // (2*s))
    if (M // s) % 2 == 0:
        print(a)
    else:
        print(a+1)
main()


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "YES"
#define FALSE__ "NO"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N, M, R;
vector<int> r;
vector<vector<int> > cost;
const int INF = 1000000000;

void init()
{
	cin >> N >> M >> R;
	r.resize(R);
	rep(i, R) {
		int a;
		cin >> a;
		r[i] = a-1;
	}
  	sort(all(r));
	cost.resize(N, vector<int>(N, INF));
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		cost[a][b] = c;
		cost[b][a] = c;
	}
	rep(i, N) cost[i][i] = 0;
	rep(k, N) {
		rep(i, N) {
			rep(j, N) {
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}
}

ll culc()
{
	ll res = 0;
	reps(i, 1, R) {
		res += cost[r[i-1]][r[i]];
		res = min((ll) INF, res);
	}
	return res;
}


void solve()
{
	ll res = INF;
	do {
		res = min(res, culc());
	} while (next_permutation(all(r)));
	cout << res << endl;
}





Measured memory_bytes: 384
#include <iostream>

int cnt = 0;

void marge(int A[], int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;

	int L[n1 + 1], R[n2 + 1];
	for (int i = 0; i < n1; ++i) {
		L[i] = A[left + i];
	}
	for (int i = 0; i < n2; ++i) {
		R[i] = A[mid + i];
	}
	L[n1] = 0x7fffffff;
	R[n2] = 0x7fffffff;

	int i = 0;
	int j = 0;
	for (int k = left; k < right; ++k) {
		A[k] = (L[i] <= R[j]) ? L[i++] : R[j++];
		++cnt;
	}
}

void marge_sort(int A[], int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		marge_sort(A, left, mid);
		marge_sort(A, mid, right);
		marge(A, left, mid, right);
	}
}

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

	for (int i = 0; i < n - 1; ++i) {
		printf("%d ", A[i]);
	}
	printf("%d\n%d\n", A[n-1], cnt);

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (s.at(i) != s.at(n - 1 - i)
        || ((n - 3) / 2 - i >= 0 && s.at(i) != s.at((n - 3) / 2 - i))) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}


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

using ll = long long;

using namespace std;

int main(){
  int N;
  ll K;
  cin >> N >> K;
  vector <int> A(N);
  for(int &i : A){
    cin >> i;
    i--;
  }
  vector <int> visti(N, false);
  vector <int> moves;
  int cur = 0;
  while(!visti[cur]){
    visti[cur] = true;
    moves.push_back(cur);
    cur = A[cur];
  }
  int i = 0;
  while(K && moves[i] != cur){
    i++;
    K--;
  }
  int period = moves.size() - i;
  int ans = moves[i + (K % period)] + 1;
  cout << ans;
  return 0;
}


Measured memory_bytes: 5836
#include<iostream>
#include<map>
#include<queue>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// input
uint64_t getZ() {
  uint64_t v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

int const MAXN = 1e5;
std::pair<int, int> BA[MAXN];

int main() {
  int N = getZ(), M = getZ();
  for(int i = 0; i < N; ++i) {
    BA[i].second = getZ();
    BA[i].first = getZ();
  }
  std::sort(BA, BA+N,
    [&](auto const& l, auto const& r){ return l.second < r.second; });
  std::priority_queue<std::pair<int,int>> q;
  int ans = 0, p = 0;
  for(int d = 1; d <= M; ++d) {
    while(p < N && BA[p].second <= d) q.push(BA[p++]);
    if(!q.empty()) {
      ans += q.top().first;
      q.pop();
    }
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 2168
#include <iostream>

using namespace std;

int main()
{
    char a, b, c, d;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    if((b == a) && (c == b))
    {
        cout << "Yes" << endl;
    }
    else if((c == b) && (d == c))
    {
         cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

typedef pair<int,int> P;

int N,T;
int M[1000],L[1000],K[1000];

int flg[1000];
bool used[1000];

bool check(int x){
  fill(flg,flg+x,0);
  fill(used,used+N,false);

  int cc=0;
  
  for(int t=0;t<=T;t++){
    for(int i=0;i<x;i++){
      if(flg[i]>t)continue;
      for(int j=0;j<N;j++){
        if(used[j])continue;
        int f=t%(L[j]+K[j]);
        if(L[j]<f)continue;
        used[j]=true;
        flg[i]=t+M[j];
        if(flg[i]>T)return false;
        cc++;
        break;
      }
    }
    if(cc==N)break;
              
    int mini=1e9;
    for(int j=0;j<N;j++){
      if(used[j])continue;
      int f=t%(L[j]+K[j]);
      if(L[j]<f){
        mini=min(mini,K[j]-(f-L[j]));
      }else mini=0;
    }
    int mini2=1e9;
    for(int j=0;j<x;j++){
      if(flg[j]>t)mini2=min(mini2,flg[j]-t);
      else mini2=0;
    }
    
    t+=max(0,max(mini,mini2)-1);
  }
  
  if(cc<N)return false;
  return true;
}

int main(){
  while(1){
    scanf("%d %d",&N,&T);
    if(N==0&&T==0)break;
    for(int i=0;i<N;i++)
      scanf("%d %d %d",&M[i],&L[i],&K[i]);
    
    int ans=N;
    for(int i=1;i<N;i++){
      if(check(i)){
        ans=i;
        break;
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 3216
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <array>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>

/* ----- Type Alias ----- */
using lint = long long int;
using Real = long double;
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T>
T ndvec(T v) { return v; }

template <class T, class... Ts>
auto ndvec(size_t l, Ts... ts) {
    return std::vector<decltype(ndvec<T>(ts...))>(l, ndvec<T>(ts...));
}

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;
template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    int precision;
    explicit Fout(int precision) : precision(precision) {}
};

std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}

/* ----- Constants ----- */
constexpr lint INF = std::numeric_limits<lint>::max() / 3;
// constexpr Int MOD = 1000000007;
// const Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

int main() {
    lint n;
    std::cin >> n;

    lint ans = INF;
    for (lint i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ans = std::min(ans, (i - 1) + (n / i - 1));
        }
    }

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


Measured memory_bytes: 256
from collections import deque

H, W, K = map(int, input().split())

move = [(1, 0), (-1, 0), (0, 1), (0, -1)]

G = [list(input()) for _ in range(H)]
check = [[-1] * (W) for _ in range(H)]

que = deque()

flag = False
for h in range(H):
    for w in range(W):
        if G[h][w] == 'S':
            que.append((h, w))
            flag = True
            break
    if flag:
        break

x_min = h
x_max = h

y_min = w
y_max = w

check[h][w] = 0
while que:
    tmp = que.popleft()
    
    x = tmp[0]
    y = tmp[1]
    
    now_ = check[x][y]
    if now_ == K:
        continue

    for dx, dy in move:
        nx = x + dx
        ny = y + dy
        if not (0 <= nx < H and 0 <= ny < W):
            continue
        if G[nx][ny] == '#':
            continue
        if check[nx][ny] == -1:
            check[nx][ny] = now_ + 1
            que.append((nx, ny))
            
            x_min = min(x_min, nx)
            x_max = max(x_max, nx)

            y_min = min(y_min, ny)
            y_max = max(y_max, ny)

ans = 10 ** 18
ans = min(ans, (x_min + K - 1) // K + 1)
ans = min(ans, (H - x_max - 1 + K - 1) // K + 1)
ans = min(ans, (y_min + K - 1) // K + 1)
ans = min(ans, (W - y_max - 1 + K - 1) // K + 1)

print (ans)


Measured memory_bytes: 80732
#include<stdio.h>

int main(){
    
    int a,b;

    -1000<=a<=1000;
    -1000<=b<=1000;

    scanf("%d %d",&a,&b);

    if(a<b){
        printf("a < b\n");
    }
    else if(a>b){
        printf("a > b\n");
    }
    else{
        printf("a == b\n");    
    }

    return 0;
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

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

    int N; cin >> N;
    cout << N*800 - N/15*200 << endl;
}

Measured memory_bytes: 3620
N,S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353

dp = [0] * (S+1)
ans = 0
for i in range(N):
    ndp = dp[:]
    if A[i] <= S:
        ndp[A[i]] = (ndp[A[i]] + i+1) % mod
    for j in range(S):
        if j+A[i] <= S:
            ndp[j+A[i]] = (ndp[j+A[i]] + dp[j]) % mod
    ans = (ans + ndp[S]) % mod
    dp = ndp[:]
print (ans)


Measured memory_bytes: 43500
#include <iostream>
#include <map>

using namespace std;

int main() {
  int N;
  cin >> N;
  int result[10000+10];
  for (int i = 0; i < 10010; i++) result[i] = 0;
  for (int x = 1; x < 100; x++) {
    for (int y = 1; y < 100; y++) {
      for (int z = 1; z < 100; z++) {
        int n = x*x + y*y + z*z + x*y + y*z + z*x;
        if (n < 10010) result[n]++;
      }
    }
  }
  for (int i = 1; i <= N; i++) {
    cout << result[i] << endl;
  }
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
        int n,sum=0,ans=0,max=0,min=1001;
        cin >> n;
        if(n==0) break;
        int s[n];
        for(int i=0; i<n; i++){
          cin >> s[i];
          sum += s[i];
        }
        for(int i=0; i<n; i++){
          if(s[i] > max) max = s[i];
          if(s[i] < min) min =s[i];
        }
        sum = sum -max -min;
        ans = sum/(n-2);
        cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3076
n = int(input())
r = [int(input()) for _ in range(n)]
minv = r[0]
maxv = r[1] - r[0]
for i in range(1,n):
    if maxv < r[i] -minv:
        maxv = r[i] -minv
    if minv > r[i]:
        minv = r[i]
    
print(maxv)
    
    


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

using namespace std;

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

	int n, c, k;

	cin >> n >> c >> k;

	vector<int> T(n);

	for (int i = 0; i < n; ++i){
		cin >> T[i];
	}

	sort(T.begin(), T.end());

	int answer = 0;

	for (int i = 0, j; i < n; i = j){
		for (j = i; j < n && j - i < c && T[j] <= T[i] + k; ++j);
		answer++;
	}

	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

//typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int a[110000];

int main(){
	
	int N;
	cin >> N;
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	map<long long int, long long int> m;
	int cnt = 0;
	
	vector<int> v;
	
	for(int i = 0; i < N; i++){
		m[a[i]]++;
		if(m[a[i]] == 0){
			cnt++;
		}else if(m[a[i]] == 1){
			cnt--;
		}
		m[a[N - i - 1]]--;
		if(m[a[N - i - 1]] == 0){
			cnt++;
		}else if(m[a[N - i - 1]] == -1){
			cnt--;
		}
		if(cnt == 0){
			v.push_back(i + 1);
		}
	}
	
	for(int i = 0; i < v.size() - 1; i++){
		cout << v[i] << " ";
	}
	cout << v[v.size() - 1] << endl;
	
	
	return 0;
}



Measured memory_bytes: 6664
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t;cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys
sys.setrecursionlimit(100000)

def seq():
    a = 1
    while True:
        yield a
        a += 1

def dfs(here, went, connect, discovery, low, answer, seq):
    went |= {here}
    discovery[here] = low[here] = next(seq)
    child = 0
    for con in connect[here]:
        if con not in went:
            parent[con] = here
            child += 1
            dfs(con, went, connect, discovery, low, answer, seq)
            low[here] = min(low[here], low[con])
            if parent[here] is None and child >= 2:
                answer[here] = 1
            elif parent[here] is not None and discovery[here] <= low[con]:
                answer[here] = 1
        elif parent[here] != con:
            low[here] = min(low[here], discovery[con])

vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
for _ in range(edges):
    v1, v2 = (int(n) for n in input().split(" "))
    connect[v1].append(v2)
    connect[v2].append(v1)
answer = [0 for n in range(vertices)]
new_seq = seq()
went = set()
discovery = [0 for n in range(vertices)]
low = [float("inf") for n in range(vertices)]
parent = [None for n in range(vertices)]
dfs(0, went, connect, discovery, low, answer, new_seq)
for i,n in enumerate(answer):
    if n:
        print(i)

Measured memory_bytes: 21636
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int m1 = s.nextInt();
        int d1 = s.nextInt();
        int m2 = s.nextInt();
        int d2 = s.nextInt();
        int ans = 0;
        if (m1 + 1 == m2 && d2 == 1)
            ans = 1;
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
trait Command
case class Print(a: Int, b: Int)
case class Reverse(a: Int, b: Int)
case class Replace(a: Int, b: Int, p: String)

object Main extends App {
  val scanner = new java.util.Scanner(System.in)

  val str = scanner.next()
  val q = scanner.nextInt()

  val commands = (1 to q).map { _ =>
    scanner.next() match {
      case "print"   =>
        Print(scanner.nextInt(), scanner.nextInt())
      case "reverse" =>
        Reverse(scanner.nextInt(), scanner.nextInt())
      case "replace" =>
        Replace(scanner.nextInt(), scanner.nextInt(), scanner.next())
    }
  }

  commands.foldLeft(str) { (acc, command) =>
    command match {
      case Print(a, b)      =>
        println(acc.substring(a, b+1))
        acc
      case Reverse(a, b)    =>
        acc.take(a) ++ acc.substring(a, b+1).reverse ++ acc.drop(b+1)
      case Replace(a, b, p) =>
        acc.take(a) ++ p ++ acc.drop(b+1)
    }
  }
}

Measured memory_bytes: 50928
s = int(input())

a = []
a.append(s)

for i in range(100000):
  if a[i] % 2 == 0:
    a.append(a[i] // 2)
  else:
    a.append(a[i] * 3 + 1)
  for j in range(i):
    if a[i] == a[j]:
      print(i+1)
      break
  else:
    continue
  break

Measured memory_bytes: 3060
n,m = map(int,input().split())
import sys
sys.setrecursionlimit(10**9)
rks = [None] *n
p = [set([]) for i in range(n)]
flist = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    flist[a-1].append(b-1)
    flist[b-1].append(a-1)
def dfs(graph,w,c):
    if rks[w] is None:
        rks[w] = 0
    for i in range(len(graph[w])):
        if rks[graph[w][i]] is not None:
            continue
        p[c].add(flist[w][i])
        dfs(graph, graph[w][i],c)
c = -1
for w in range(n):
    c += 1
    if rks[w] is None:
        dfs(flist,w,c)
ans = 0
for i in range(n):
    ans = max(ans,len(p[i])+1)
print(ans)

Measured memory_bytes: 276152
// Solution to https://atcoder.jp/contests/dp/tasks/dp_v
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int N, MOD;
vector<vector<int>> adj;

// down[node] = number of ways to paint node's subtree where node must be painted black.
// up[node] = number of ways to color the subtree of node that its parent is responsible for, empty coloring included.
vector<int64_t> down;
vector<int64_t> up;

void solve_down(int node, int parent) {
    vector<int> &children = adj[node];
    // Erase the edge from node to parent.
    children.erase(remove(children.begin(), children.end(), parent), children.end());
    down[node] = 1;

    for (int child : children) {
        assert(child != parent);
        solve_down(child, node);
        down[node] = down[node] * (down[child] + 1) % MOD;
    }
}

void solve_up(int node, int parent) {
    vector<int> &children = adj[node];
    int n = int(children.size());
    vector<int64_t> prefix(n + 1, 1), suffix(n + 1, 1);

    for (int i = 0; i < n; i++)
        prefix[i + 1] = prefix[i] * (down[children[i]] + 1) % MOD;

    for (int i = n - 1; i >= 0; i--)
        suffix[i] = suffix[i + 1] * (down[children[i]] + 1) % MOD;

    for (int i = 0; i < n; i++)
        up[children[i]] = (1 + prefix[i] * suffix[i + 1] % MOD * up[node]) % MOD;

    for (int child : children) {
        assert(child != parent);
        solve_up(child, node);
    }
}

int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    cin >> N >> MOD;
    adj.assign(N, {});

    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    down.resize(N);
    solve_down(0, -1);

    up.resize(N);
    up[0] = 1;
    solve_up(0, -1);

    for (int i = 0; i < N; i++)
        cout << up[i] * down[i] % MOD << '\n';
}


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    constexpr long double eps = 0.000000001;
    using real = long double;
    using point = complex<real>;
    vector<point> p(N);
    for(auto& i : p){
        real im, re;
        cin >> im >> re;
        i.imag(im);
        i.real(re);
    }
    using circle = pair<point, real>;
    const auto& circle_from_diameter = [](const point& a, const point& b) -> circle {
        auto center = (a + b) / 2.0L;
        auto hankei = norm(a - center);
        return {center, hankei};
    };
    const auto& circle_from_triangle = [](const point& a, const point& b, const point& c) -> circle {
        if(((a - b) / (a - c)).imag() < eps)return {0, 0};
        auto center = ((a - b) * norm(c) + (b - c) * norm(a) + (c - a) * norm(b)) / ((a - b) * conj(c) + (b - c) * conj(a) + (c - a) * conj(b));
        auto hankei = norm(a - center);
        return {center, hankei};
    };
    const auto& is_all_include = [&p](const circle& c) -> bool {
        const auto& is_included = [&c](const point& a) -> bool {
            return norm(a - c.first) <= c.second + eps;
        };
        return all_of(p.begin(), p.end(), is_included);
    };
    real mn_diam{2000000};
    for(const auto& i : p)for(const auto& j : p)if(i != j){
        auto c = circle_from_diameter(i, j);
        if(mn_diam > c.second && is_all_include(c))mn_diam = c.second;
    }
    for(const auto& i : p)for(const auto& j : p)for(const auto& k : p)if(i != j && j != k && k != i){
        auto c = circle_from_triangle(i, j, k);
        if(mn_diam > c.second && is_all_include(c))mn_diam = c.second;
    }
    cout << setprecision(15) << sqrt(mn_diam) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 1000005 
#define LL long long 
using namespace std;
int A[N];
char str[N]; 
bool cmp(int a,int b){
	return a>b;
}
int main(){ 
	int n,m,x;
	cin>>n>>m;
	int sum=0;
	for(int i=0;i<n;i++){
		scanf("%d",&A[i]);
		sum+=A[i];
	}
	sort(A,A+n,cmp);
	bool f=1;
	for(int i=0;i<m;i++){
		if(A[i]*4*m<sum)f=0;
	}
	puts(f?"Yes":"No");
	return 0; 
} 

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

int main() {
  string S ;
  cin >> S ;
 if (S == "Sunny")
   cout << "Cloudy";
  else if (S == "Cloudy")
    cout << "Rainy";
  else if (S == "Rainy")
    cout <<"Sunny";
}

Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class  Main{
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();int m=sc.nextInt();
        int[][]co=new int[n][m];
        for(int i=0;i<n;i++) {
        	for(int j=0;j<m;j++) {
        		co[i][j]=sc.nextInt();
        	}
        }
        int ans=0;
        for(int i=0;i<n;i++) {
        	for(int j=i+1;j<n;j++) {
        		int dist=0;
        		for(int o=0;o<m;o++) {
        			dist+=(co[i][o]-co[j][o])*(co[i][o]-co[j][o]);
        		}
        		if((Math.sqrt(dist))%1==0) {
        			ans++;
        		}
        	}
        }
        pw.println(ans);
        pw.flush();
    }
    
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 21204
N,X,M=map(int,input().split())
a = X
hist = [a]
indices = [-1]*M
indices[a] = 0
flag=0
for i in range(1,min(10**6,N)):
  a = a**2 % M
  if indices[a] != -1:
    idx = indices[a]
    flag=1
    break
  hist.append(a)
  indices[a] = i
  
if flag==0:
  print(sum(hist))
  exit()
  
cycle = hist[idx:]
margin = hist[:idx]
q,r = divmod((N-len(margin)),len(cycle))
print(sum(margin)+sum(cycle)*q+sum(cycle[:r]))

Measured memory_bytes: 14048
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0; }
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S, T;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//
ll gcd(ll x, ll y) {
	ll r;
	if (x < y) {
		swap(x, y);
	}
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}
int main() {
	ll A, B;
	cin >> A >> B;
	cout << A * B / gcd(A, B);
}

Measured memory_bytes: 256
function main(input) {
    var array = input.split('\n');
    var num = parseInt(array[0], 10);
    var color = array[1].split(' ');
    var change = 0;

    for(var i = 0; i< num - 1; i++){
        if(color[i] == color[i+1]){
            change++ ;
            i++ ;
        }
    }
    console.log(change);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 22084
#include <iostream>
#include <string>
int main(){
 std::string s[3];
 int a,b;
 while(1){
 	getline(std::cin,s[0],' ');
 	getline(std::cin,s[1],' ');
 	getline(std::cin,s[2]);
 	if(s[1] == "?")break;
 	a = std::stoi(s[0]),b=std::stoi(s[2]);
 	if(s[1] == "+"){std::cout<<(a+b) << std::endl;}
 	else if(s[1] == "-"){std::cout<<(a-b)<< std::endl;}
 	else if(s[1] == "*"){std::cout<<(a*b)<< std::endl;}
 	else if(s[1] == "/"){std::cout<<(a/b)<< std::endl;}
 }
}

Measured memory_bytes: 1196
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
arr = [0] * 100002

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

print(max(arr))


Measured memory_bytes: 20896
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=500050;
//int arr[SIZE]={};
//ここまでテンプレ
typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;
//
int N,M;
Graph G;
vector<int> col;
bool connect=false;

void bipartite_dfs(int pos, int par, int c) {
	if (col[pos] >= 0) {
		if (c != col[pos]) {
			connect = true;
			return;
		}
		else return;
	}
	col[pos] = c;
	for (auto e : G[pos]) {
		if (e.dst == par)continue;
		bipartite_dfs(e.dst, pos, 1 - c);
	}
}

int main(){
	cin>>N>>M;
	col=vector<int>(N,-1);
	for(int i=0;i<N;i++){
		Edges E;
		G.push_back(E);
	}
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(Edge(a,b,1));
		G[b].pb(Edge(b,a,1));
	}
	bipartite_dfs(0,-1,0);
	
	if(connect)
		cout<<(ll)N*(N-1)/2-M<<endl;
	else{
		int num=0;
		for(int i=0;i<N;i++)
			if(col[i])
				num++;
		cout<<(ll)num*(N-num)-M<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 8304
S = input()
dp = list()
for i in range(4):
	dp.append([0] * 4)
dp[0][0] = 1
target = "ABC"
modulo = 1000000007
N = len(S)
for i in range(N):
	for j in range(2, -1, -1):
		if target[j] == S[i] or S[i] == '?':
			for k in range(2, -1, -1):
				tark = k + (1 if S[i] == '?' else 0)
				dp[j + 1][tark] += dp[j][k]
				if dp[j + 1][tark] >= modulo:
					dp[j + 1][tark] -= modulo
numquestion = 0
for i in range(N):
	if S[i] == '?':
		numquestion += 1
ans = 0
for i in range(4):
	if dp[3][i] >= 1:
		delta = dp[3][i] * pow(3, numquestion - i, modulo) % modulo
		ans += delta
		ans %= modulo
print(ans)

Measured memory_bytes: 3316
import java.util.Scanner;

/**
 * Created by liguoxiang on 2017/02/18.
 */
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        long s = sc.nextLong();
        // スペース区切りの整数の入力
        long c = sc.nextLong();



        if(s*2>=c){
            System.out.println(c/2);
            return;
        }else{

            long diff=c-s*2;


            System.out.println(diff/4+s);
            return;
        }

    }
}


Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <bitset>

using namespace std;

int main(){
    long long c = 0;
    int N;
    string s;
    cin >> N;
    int count[5];
    for(int i=0;i<5;i++) count[i] = 0;
    for(int i=0;i<N;i++){
        cin >> s;
        if(s[0]=='M'){
            count[0]++;
        }
        if(s[0]=='A'){
            count[1]++;
        }
        if(s[0]=='R'){
            count[2]++;
        }
        if(s[0]=='C'){
            count[3]++;
        }
        if(s[0]=='H'){
            count[4]++;
        }
    }
    long long ans=0;
    long long memo;
    for(int i=0;i<32;i++){
        bitset<5> bt(i);
        memo = 1;
        if(bt.count()==3){
            for(int j=0;j<5;j++){
                if(bt[j]){
                    memo *= count[j];
                }
            }
            ans += memo;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
  int len;
  string input1,input2;
  string ans = "";
  int pos = 0;
  cin >> len >> input1 >> input2;
  for(int i=0;i<len*2;i++){
    if(i%2==1){
      ans += input2.at(pos);
      pos++;
    }
    else{
      ans += input1.at(pos);
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll s[200050];
int main()
{
    int n,i,ans=1;
    cin>>n;
    for(i=0;i<n;i++)
        scanf("%lld",&s[i]);
    ll mi=s[0];
    for(i=1;i<n;i++){
        if(mi>=s[i]) ans++;
        mi=min(s[i],mi);
    }
    printf("%d",ans);
    return 0;
}


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

using namespace std;

void solve(){
    string tmp;
    cin >> tmp;
    
    if(tmp.substr(0,1) == tmp.substr(2,1)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args ){
    Scanner sc = new Scanner(System.in);

    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();

    long [] arr = new long[]{ A,B,C };
    Arrays.sort(arr);

    long result = 0 ;
    if (A % 2 == 1 && B % 2 == 1 && C % 2 == 1 ) {
      result = arr[0] * arr[1];
      // result = Math.min(A * B, Math.min(A * C, B * C));
    }
    System.out.println(result);
  }
}



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

int main(){
    int n, m, sum = 0;
    cin>>n;
    m = n;
    while(m){
        sum += m % 10;
        m /= 10;
    }
    cout<<(n%sum==0?"Yes":"No")<<endl;
    return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int>count(N-1);
  vector<int>black(N);
  vector<int>white(N);
  int A = 0;
  int B = 0;
  
  for (int i = 0; i < N; i++){
    if (S.at(i) == '#'){
      A++;
    }
    else {
      B++;
    }
    black.at(i) = A;
    white.at(i) = B;
  }
  
  int sumb = black.at(N-1);
  int sumw = white.at(N-1);
  
  int ans = sumw;
  for (int i = 0; i < N; i++){
    if (ans > black.at(i) + sumw - white.at(i)){
      ans = black.at(i) + sumw - white.at(i);
    }
  }
  cout << ans << endl;
}
  
  
  
    
    


   
  
  






Measured memory_bytes: 6036
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    string s;
    cin >> s;
    rep(i, 0, s.size())
    {
        if (i % 2 == 0) cout << s[i];
    }
    cout << endl;
}


Measured memory_bytes: 592
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



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

	int x = 0;
	int y = 0;
	for (int i = 0; i < 2; i++) {
		x = x * 10 + (s[i] - '0');
		y = y * 10 + (s[i + 2] - '0');
	}



	if (x > 12 || x == 0) {
		if (y > 12 || y == 0) {
			cout << "NA" << endl;
		}
		else {
			cout << "YYMM" << endl;
		}
	}
	else {
		if (y > 12 || y == 0) {
			cout << "MMYY" << endl;
		}
		else {
			cout << "AMBIGUOUS" << endl;
		}




	}
}


Measured memory_bytes: 3592