akhauriyash/Code-Regression huggingface dataset:
"use strict";

function binarySearch(ar, el) {
  var m = 0;
  var n = ar.length - 1;
  while (m <= n) {
      var k = (n + m) >> 1;
      var cmp = el - ar[k];
      if (cmp > 0) {
          m = k + 1;
      } else if(cmp < 0) {
          n = k - 1;
      } else {
          return k;
      }
  }
  return -m - 1;
}

function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");

  const N = Number(inputs[0].split(" ")[0]);
  const M = Number(inputs[0].split(" ")[1]);
  
  const P = [];
  const Y = [];
  const ID = [];

  for (let i = 0; i < M; i++) {
    const inputLine = inputs[1+i].split(" ");
    const Pi = inputLine[0];
    const Yi = inputLine[1];
    P.push(Pi);
    Y.push(Yi);
  }

  const mapArr = {};

  for (let i = 0; i < P.length; i++) {
    if (mapArr[P[i]]) {
      mapArr[P[i]].push(Y[i]);
    } else {
      mapArr[P[i]] = [Y[i]];
    }
  }

  for (let Pi in mapArr) {
    mapArr[Pi] = mapArr[Pi].sort((a,b) => a - b);
  }

  let result = "";
  for (let i = 0; i < P.length; i++) {
    let firstHalf = "" + P[i];
    while (firstHalf.length < 6) {
      firstHalf = "0" + firstHalf;
    }

    let secondHalf = "" + (binarySearch(mapArr[P[i]], Y[i]) + 1);
    while (secondHalf.length < 6) {
      secondHalf = "0" + secondHalf;
    }

    result = result + firstHalf + secondHalf + "\n";
  }

  console.log(result);
}

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


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

int main()
{
  int N;
  cin >> N;
  int a[N];
  for(int i = 0; i < N; i++) cin >> a[i];
  cout << *max_element(a,a+N)-*min_element(a,a+N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int, int>
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  ll n, k;
  cin >> n >> k;
  vi d(n);
  int max_a = 0;
  REP(i, n) {
    cin >> d[i];
    chmax(max_a, d[i]);
  }
  int l = 0;
  int r = max_a;
  while (r - l > 1) {
    int x = (l + r) / 2;
    int cnt = 0;
    for (auto a : d) {
      cnt += (a - 1) / x;
    }
    cnt <= k ? r = x : l = x;
  }
  cout << r << endl;
}

Measured memory_bytes: 3984
#include <iostream>
#include <vector>
using namespace std;
int main(){
int N;
cin>>N;
vector<long long> a(N),b(N);
for(int i=0;i<N;i++)cin>>a[i];
for(int i=0;i<N;i++)cin>>b[i];
long long dif=0;//b-a
for(int i=0;i<N;i++)dif-=a[i];
for(int i=0;i<N;i++)dif+=b[i];
long long act=0;
for(int i=0;i<N;i++){
long long d=b[i]-a[i];
if(d>0)act+=(d+1)/2;
}
cout<<((dif>=act)?"Yes":"No")<<endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main() {
	int N, M, X;
	cin >> N >> M >> X;
	int map[N+1];
	for (int i = 0; i <= N; i++) {
		map[i] = 0;
	}
	for (int i = 0; i < M; i++) {
		int costpos;
		cin >> costpos;
		map[costpos] = 1;
	}
	//入力と主な変数宣言
	int ans1 = 0;
	for (int i = X; i <= N; i++) {
		ans1 = ans1 + map[i];
	}
	int ans2 = 0;
	for (int i = X; i >= 0; i--) {
		ans2 = ans2 + map[i];
	}
	if (ans1 < ans2) {
		cout << ans1 << endl;
	}else {
		cout << ans2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int N,A,B,C;
int D[10000]={};
int main() {
	cin>>N>>A>>B>>C;
	for (int i=0;i<N;i++){
      cin>>D[i];
	}

	int R=0;
	int CPD=0;
	int TotalC=0;
	TotalC=C;
	int T;
	for(int i=0;i<N;i++){
		for(int i=0;i<N;i++){
			if(D[i]<D[i+1]){
				T=D[i];
				D[i]=D[i+1];
				D[i+1]=T;
			}
		}
	}

	for (int i=0;i<N;i++){
		TotalC+=D[i];
		CPD=TotalC/(A+(i+1)*B);
				if (R<CPD)R=CPD;
	}

	cout << R<< endl;
	return 0;
}

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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
typedef long long ll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

ll gcd(ll a, ll b){
    if(b==0){
        return a;
    }
    return gcd(b, a%b);
}

// vector<int> takasa(101);

int main(){
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i,n){
        cin >> h[i];
    }
    
    ll takasa=0;
    ll kaisuu=0;

    rep(i,n){
        if(takasa<h[i]){
            kaisuu+=h[i]-takasa;
        }
        takasa=h[i];
    }
    cc(kaisuu);
}

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

int main(){
	string s;
	int j=0;
	int i=0;
	cin>>s;
	size_t a=s.length();
	for(i=0;i<a;i=i+2){
		if(s[i]=='h' && s[i+1]=='i' && s[i+2]!='i'){
			j=1;
			
		}
		else{
			j=0;
			break;
		}
	}
	if(j==1) cout<<"Yes";
	if(j==0) cout<<"No";
}
			
	

Measured memory_bytes: 384
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	printf("%d\n",(b-a)*(b-a-1)/2-a);
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N, M = map(int, input().split())
    A_list = list(map(int, input().split()))
    diff = N - sum(A_list)
    if diff >= 0:
        print(diff)
    else:
        print(-1)

if __name__ == "__main__":
    main()




Measured memory_bytes: 10008
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
  input! {
    n: usize,
    table: [[i32; 3]; n]
  };

  let mut dp = vec![[0; 3]; n+1];
  for i in 0..n {
    for j in 0..3 {
      for k in 0..3 {
        if j != k {
          dp[i+1][k] = max(dp[i+1][k], dp[i][j]+table[i][k]);
        }
      }
    }
  }

  let best = max(dp[n][0], max(dp[n][1], dp[n][2]));
  println!("{}", best);
}

Measured memory_bytes: 12540
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    LL N,M; cin >> N >> M;
    LL x = 1900 * M + 100 * (N - M);
    LL rp = LL(pow(2,M));
    cout << x * rp << endl;

}


Measured memory_bytes: 384
# require "enumerator"

N = gets

P = gets
P_arry = P.split(" ")

P_int = P_arry.map {|p|
    p.to_i
}

isBreak = false
failure_count = 0

if P_int.each_cons(2).all? {|a, b| a <= b }
    isBreak = true
    print "YES"
    exit
end

for i in 0..N.to_i-1
    for j in 0..N.to_i-1
        if i >= j
            next
        end
        if P_int[i] > P_int[j]
            P_int[i],P_int[j] = P_int[j],P_int[i]
            if P_int.each_cons(2).all? {|a, b| a <= b }
                isBreak = true
                break
            else
                failure_count = failure_count + 1
                P_int[i],P_int[j] = P_int[j],P_int[i]
            end
        end
    end
    break if isBreak || (failure_count > 0)
end

if isBreak
    print "YES"
else
    print "NO"
end

Measured memory_bytes: 1916
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define pb push_back

ll power(int x, unsigned int y){
    ll res = 1;
    while(y > 0){
        if(y & 1) res = res * x;
        y >>= 1;
        x *= x;
    }
    return res;
}

// Check for number of Cases!!
void solve() {
    
    string str; cin >> str;

    ll ans = 0;

    for(auto i : str) {
        ans += i - '0';
    }

    if(ans % 9) {
        cout << "No";
    }else cout << "Yes";

}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t = 1;
    // cin >> t;
    while(t--) {
      solve();
    }
}

Measured memory_bytes: 3716
#include<iostream>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define all(in) in.begin(),in.end()
#define pb(in,a) in.push_back(a)
using namespace std;
int a[4]={0,1,0,-1};
int b[4]={1,0,-1,0};
int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    int to=0;
    string s;
    int x=1,y=1;
    while(1){
      cin>>s;
      if(s=="FORWARD"){
	int tmp;
	cin>>tmp;
	x+=tmp*a[to];
	y+=tmp*b[to];
      }else if(s=="BACKWARD"){
	int tmp;
	cin>>tmp;
	x-=tmp*a[to];
	y-=tmp*b[to];
      }else if(s=="STOP")break;
      else if(s=="LEFT")to--;
      else to++;

      if(to>3)to=0;
      else if(to<0)to=3;

      if(x>n)x=n;
      else if(x<1)x=1;
      if(y>m)y=m;
      else if(y<1)y=1;
      //cout<<x<<" "<<y<<endl;
    }
    cout<<x<<" "<<y<<endl;
  }
}

Measured memory_bytes: 1216
def solve(A, N):
    answer = 0

    B = list(A)
    V = [False] * N
    T = [None] * 10001
    s = min(A)

    B.sort()

    # print(A)
    # print(B)

    for i in range(N):
        T[B[i]] = i

    for i in range(N):
        if V[i] is True:  # すでにカーソルが来ていたら飛ばす。
            continue

        cur = i  # カーソル
        S = 0
        m = 10000  # VMAX
        an = 0  # サイクルの長さ

        while True:
            V[cur] = True  # まずは今の位置を走査済みにする。
            an += 1  # サイクルの長さを増やす
            v = A[cur]  # 入力列の値
            m = min(m, v)  # このサイクルの最小値
            S += v  # 今の値の重さを足す。SはΣwi
            cur = T[v]  # 次のカーソルの位置を決める
            if V[cur]:  # 次のカーソルの位置がTrueなら
                break  # サイクルの始まりまで戻ってきたということ。

        # この状態で、
        # an = サイクルの長さ
        # S = wiの合計の重さ
        # m = このサイクルの最小値
        # の3つが分かっている。

        answer += min(S + (an - 2) * m, m + S + (an + 1) * s)

    return answer


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

answer = solve(A, N)
print(answer)



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

#include <iostream>
#include <fstream>

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

class DFaceProducesUnhappiness {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n,k;
        in >> n >> k;
        string s;
        in >> s;
        int ans=0;
        for(int i=0;i<n;i++){
            if(i!=n-1&&s[i]=='R'&&s[i+1]=='R'){
                ans++;
            }
            if(i!=0&&s[i]=='L'&&s[i-1]=='L'){
                ans++;
            }
        }
        ans=min(ans+(k*2),n-1);
        out << ans << endl;
	}
};


int main() {
	DFaceProducesUnhappiness solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n;
bool is_prime(int x)
{
    if(x==2)return true;
    for(int i=2;i<=ceil(sqrt(x*1.0));i++){
        if(x%i==0)return false;
    }
    return true;
}
int main()
{
    cin>>n;
    for(int i=n;i<=1e6;i++)if(is_prime(i))return cout<<i,0;
}

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

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

    vector<int> A(N), B(N), C(N - 1);
    int ans = 0;

    for(int i = 0; i < N; i++)
    {
        cin >> A[i];
        A[i]--;
    }

    for(int i = 0; i < N; i++)
    {
        cin >> B[i];
        ans += B[i];
    }

    for(int i = 0; i < N - 1; i++)
    {
        cin >> C[i];
    }

    for(int i = 0; i < N - 1; i++)
    {
        if(A[i] + 1 == A[i + 1])
        {
            ans += C[A[i]];
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
typedef vector<lint> poly;
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;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    int a[n];
    rep(i, n) scanf("%d", &a[i]);
    int m=mod, id=-1;
    rep(i, n)if(a[i]<m){
        m=a[i];
        id=i;
    }
    printf("%d\n", id+1);
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define INF 1000000001
#define INFL 1000000000000000001
#define M 1000000007
int h,w,dp[105][105];
char s[105][105];
int main(void){
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf(" %c",&s[i][j]);
			if(i==0&&j==0){
				if(s[i][j]=='#')dp[i][j]=1;
				else dp[i][j]=0;
			}else{
				dp[i][j]=INF;
				if(i>0){
					int q=0;
					if(s[i-1][j]=='.'&&s[i][j]=='#')q=1;
					dp[i][j]=min(dp[i][j],dp[i-1][j]+q);
				}
				if(j>0){
					int q=0;
					if(s[i][j-1]=='.'&&s[i][j]=='#')q=1;
					dp[i][j]=min(dp[i][j],dp[i][j-1]+q);
				}
			}
		}
	}
	printf("%d\n",dp[h-1][w-1]);
}

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


int main(){
    ll N, X, M;
    cin >> N >> X >> M;

    vector<ll> A;
    A.push_back(X);
    A.push_back(X);

    int flag[M];
    for (int i = 0; i < M; ++i){
        flag[i] = 0;
    }
    flag[X] = 1;

    int index = 2;
    ll next;
    for (; index < M + 2; ++index){
        next = A[index - 1] * A[index - 1] % M;
        A.push_back(next);
        if (flag[next] != 0) break;
        flag[next] = index;
    }

    ll sum[index + 1];
    sum[0] = 0;
    for (int i = 1; i < index + 1; ++i){
        sum[i] = sum[i - 1] + A[i];
    }
    int start = flag[A[index]];


    ll ans;
    ans = sum[start];

    N -= start;

    int l = index - flag[next];
    ans += (N / l) * (sum[index] - sum[start]);

    ans += sum[flag[next] + (N % l)] - sum[flag[next]];

    cout << ans << endl;

}

Measured memory_bytes: 4576
#include <iostream>
#include <vector>
 
using namespace std;
 
//combinationを作る前処理
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}
 
const int MAX = 210000;
const int MOD = 1000000007;
 
 
 
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
 
long long com(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
 
int main() {
    int n, m, k;
    COMinit();
    cin >> n >> m >> k;
  
    long long res = 0;
  
  for(int d =1;d<n;d++){
   res += ((((com(n*m-2,k-2)*(n - d) % MOD)* m% MOD) * m % MOD) * d % MOD) % MOD;
  }
  for(int d =1;d<m;d++){
   res += ((((com(n*m-2,k-2)*(m - d) % MOD)* n% MOD) * n % MOD) * d % MOD) % MOD;
  }
  
  
   
    cout << res%1000000007 << endl;
}          


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int cnt=0;

    for(int i=0; i<s1.size(); i++)
    {

            if(s1[i]==s2[i])
            {
                cnt++;
            }
}

    if(cnt==0)
        cout<<0<<endl;
    else
        cout<<cnt<<endl;

        exit(0);
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N;

int main(void){
	
	scanf("%d", &N);
	
	int i = 1;
	for(; i <= N; i *= 2);
	printf("%d\n", i / 2);
    
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

ll euler[1000002];
int N = 1000000;
map<int,int> tmp;

ll eulerf(int n){
  ll base = n;
  ll basert = sqrt(n);
  int i=2;
  double ret=n;

  while(n != 1){
    if(i > sqrt(n)) i = n; 
    if(n%i == 0){
      ret *= 1 - (double)1/i;
      while(n%i == 0) n /= i;
    }else{
      i++;
    }
  }

  //dump(round(ret));
  return round(ret);
}

ll sum(int i){
  ll s=0;
  while(i > 0){
    s += euler[i];
    i -= i & -i;
  }
  return s;
}

ll add(ll i, ll x){
  while(i <= N){
    euler[i] += x;
    i += i & -i;
  }
}

int main(void){
  int t;

  cin >> t;
  memset(euler,0,sizeof(euler));

  //calc euler function
  add(1, 1);
  for(int i=2;i<=1000000;i++){
    add(i, eulerf(i));
  }
  //cerr << "ok" << endl;
  for(int x=0;x<t;x++){
    int n;
    cin >> n;
    cout << (ll)sum(n) + 1 << endl;
  }
}

Measured memory_bytes: 8680
unittest
{
	assert( [ "2", "1 4" ].parse.expand.solve == 5 );
	assert( [ "7", "14 14 2 13 56 2 37" ].parse.expand.solve == 2354 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	return tuple( xs );
}

auto solve( long[] xs )
{
	auto ans = long.max;
	foreach( p; 1L .. 101L )
	{
		auto t = 0L;
		foreach( x; xs )
		{
			t += ( x - p ) ^^ 2;
		}
		ans = min( ans, t );
	}
	return ans;
}


Measured memory_bytes: 256
let compare a = function
  | b when a > b -> "a > b"
  | b when a < b -> "a < b"
  | b -> "a == b"

let main a b = Printf.printf "%s\n" (compare a b)

(* ;; print_string "input: " *)
;; Scanf.sscanf (read_line ()) "%d %d" main

Measured memory_bytes: 2236
use std::io::stdin;

fn main() {
    let mut num = String::new();
    stdin().read_line(&mut num).unwrap();
    let num:i64 = num.trim().parse().unwrap();
    let mut result:i64 = 0;
    for i in 1..num+1 {
        if (i%3!=0) && (i%5!=0) {result += i;}
    }
    println!("{}", result);
}

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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define FORE( i, m, n ) FOR( i, m , n + 1 )
#define REP( i, n )     FOR( i, 0, n )
#define REPE( i, n )	FOR( i, 0, n + 1 )
#define REPA( i, n )	FOR( i, 1, n )
#define FORR( i, m, n ) for( int (i) = (m); (i) >= 0; (i)-- )
#define ALL( a )        (a).begin(), (a).end()             
#define MP( a, b )		make_pair( (a), (b) )
#define fi				first
#define se				second

const int INF = 1e9;
const int MOD = 1e9 + 7;

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

	double res = 0;
	REPA( i, n + 1 ) {
		double t = 1.0 / n;
		int now = i;
		while( now < k ) {
			now *= 2;
			t /= 2;
		}
		res += t;
	}

	printf( "%.12f\n", res );
	
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    ans += min(2 * x, 2 * (K - x));
  }
  cout << ans << endl;
}

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

#define PII pair<int, int> 
#define mp make_pair
#define pb push_back
#define x first
#define y second

using namespace std;

const int N = 300 + 10;
const int mod = 1e9 + 7;

vector<PII> vec[N];

int dp[N][N][N], vis[N][N][N];
int n, m;

void Check(int r, int g, int b) {
	int flag = (r == 0) + (g == 0) + (b == 0);
	if(flag < 2 && (r == g || r == b || g == b)) 
		return void(vis[r][g][b] = 1);
	int now = max(r, max(g, b));
	for(auto v : vec[now]) 
		if((r >= v.x) + (g >= v.x) + (b >= v.x) != v.y)
			return void(vis[r][g][b] = 1);
}

void add(int r, int g, int b, int val) {
	if(!vis[r][g][b]) (dp[r][g][b] += val) %= mod;
}

int main() {

	int x, y, z, ans = 0;

	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++ i) {
		scanf("%d%d%d", &x, &y, &z);
		vec[y].pb(mp(x, z));
	}
	
	for(int i = 0; i <= n; ++ i)
		for(int j = 0; j <= n; ++ j)
			for(int k = 0; k <= n; ++ k) 
				Check(i, j, k);

	dp[0][0][0] = 1;

	for(int i = 0; i <= n; ++ i)
		for(int j = 0; j <= n; ++ j)
			for(int k = 0; k <= n; ++ k)
				if(dp[i][j][k]) {
					int now = max(i, max(j, k));
					add(now + 1, j, k, dp[i][j][k]);
					add(i, now + 1, k, dp[i][j][k]);
					add(i, j, now + 1, dp[i][j][k]);
					if(now == n) (ans += dp[i][j][k]) %= mod;
				}

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


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

int main() {
  int64_t X;
  cin >> X;
  int y = 0;
  int64_t money = 100LL;
  while (money < X) {
    money += money / 100LL;
    y++;
  }
  cout << y << endl;
}

Measured memory_bytes: 3620
def main():
    a = [0]*4
    for _ in range(3):
        x, y = map(int, input().split())
        a[x-1] += 1
        a[y-1] += 1
    a.sort()
    if a[0] == 1 and a[1] == 1 and a[2] == 2 and a[3] == 2:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    static long[][][] dp;
    static int[] x;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        dp = new long[n+1][n+1][50*50+100];
        x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        dp[0][0][0] = 1;
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < a * n; j++) {
                    dp[k+1][i + 1][j + x[k]] += dp[k][i][j];
                    dp[k+1][i][j] += dp[k][i][j];
                }
            }
        }
        long ret = 0;
        for (int i = 1; i <= n; i++) {
            ret += dp[n][i][a*i];
        }
        System.out.println(ret);
    }
}

Measured memory_bytes: 87648
a = list(input())
b = 0
c = 0

for i in range(len(a)):
  if a[i] == "A":
    b = b + 1
  elif a[i] == "C":
    b = b + 1
  elif a[i] == "G":
    b = b + 1
  elif a[i] == "T":
    b = b + 1
  else :
    if c < b :
      c = b
      b = 0
    else :
      b = 0
if c < b :
      c = b
      b = 0
else :
      b = 0
     
print(c)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <climits>
#include <utility>
#include <map>
#include <set>
#include <complex>
#include <numeric>

#include <time.h>
#include <float.h>

#define loop(i, n) for(i = 0; i < n; i++)
#define loop1(i, n) for(i = 1; i <= n; i++)
#define loop2(i, n, start) for(i = start; i <= n; i++)
#define loopIterators(it, vec) for(it = (vec).begin(); it != (vec).end(); it++)
#define loopIteratorsRev(it, vec) for(it = (vec).rbegin(); it != (vec).rend(); it++)
#define loopRev(i, n) for(i = (n - 1); i >= 0; i--)
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCases(t) cin >> t; while(t--)
#define PN(n) cout << (n)
#define PN1(n) cout << (n) << " "
#define PN2(a, b) cout << (a) << " " << (b) << " "
#define PNN1(n) cout << (n) << endl
#define PNN2(a, b) cout << (a) << " " << (b) << endl
#define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define PrintArray(ar, n) for(i = 0; i < n; i++) cout << ar[i] << " "; cout << endl
#define PrintSet(ar, it) for(it = ar.begin(); it != ar.end(); it++) cout << *it << " "; cout << endl
#define PrintMap(map, it) for(it = map.begin(); it != map.end(); it++) PNN2(it -> first, it -> second)
#define sz(a) sizeof(a)
#define IN1(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define ALL(s) s.begin(), s.end()
#define SWAP(a, b, c) c = a; a = b; b = c
#define STRSP(s) scanf("%[^\n]%*c", s)
#define ENTER PNN1("");
#define MOD7 1000000007
#define MOD9 10000009
#define MAX 100005
#define llPair std::pair<lli, lli>
#define iiPair std::pair<int , int>
#define ONLINE_JUDGE

typedef long long int lli;
typedef long int li;
typedef unsigned long long int ulli;
typedef long double ld;

using namespace std;

int main(void){
	FLASH

	#ifndef ONLINE_JUDGE
		freopen("input-stream.txt", "r", stdin);
    freopen("output-stream.txt", "w", stdout);
	#endif

	std::string str;
	std::string::iterator it;
	deque<char> queue;
	deque<char>::iterator itDeque;
	deque<char>::reverse_iterator itDequeRev;
	int q, i, reverse = 0;

	IN2(str, q);
	loopIterators(it, str) queue.emplace_back(*it);

	while (q--) {
		int t;
		IN1(t);
		switch (t) {
			case 1:
				reverse = (reverse + 1) % 2;
				break;
			case 2:
				int f;
				char c;
				IN2(f, c);
				--f;
				f = (f + reverse) % 2;
				f == 0? queue.emplace_front(c): queue.emplace_back(c);
				break;
		}
	}

	if (reverse == 0) loopIterators(itDeque, queue) PN(*itDeque);
	else loopIteratorsRev(itDequeRev, queue) PN(*itDequeRev);

	#ifndef ONLINE_JUDGE
		fclose(stdin);
    fclose(stdout);
	#endif

	return 0;
}


Measured memory_bytes: 976
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[100001];
        int countMinus = 0;
        for(int i = 0; i < n; i++) {
            int num = sc.nextInt();
            array[num]++;
            array[num+1]++;
            if(num-1 == -1) {
                countMinus++;
            } else {
                array[num-1]++;
            }
        }
        int max = countMinus;
        for(int num: array) {
            max = Math.max(max, num);
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 51856
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rg register
#define usn unsigned
#define llint long long
using namespace std;
const int N=1008611;

struct ios{
	template <typename _tp>
	inline ios operator >> (_tp &x){
		x = 0;int f = 1;char c = getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f = -1;
		for(;c<='9'&&c>='0';c=getchar()) x = (x<<1)+(x<<3)+(c^48);
		x *= f;
		return *this;
	}
	template <typename _tp>
	inline ios operator << (_tp x){
		char s[66];int dgt = 0;
		if(x==0) putchar('0');
		if(x<0) putchar('-'),x = -x;
		while(x) ++dgt,s[dgt] = x%10+'0',x/=10;
		while(dgt) putchar(s[dgt]),--dgt;
		return *this;
	}
	inline ios operator << (char x){
		putchar(x);
		return *this;
	}
}io;

int n,num[N],qwq[N];

int main()
{
	io >> n;
	for(rg int i=1;i<=n;++i){
		io >> num[i];
		qwq[i] = num[i];
	}
	sort(qwq+1,qwq+n+1);
	int qaq = 0;
	for(rg int i=1;i<=n;++i){
		if(qwq[i]!=num[i]){
			++qaq;
		}
	}
	if(qaq<=2) puts("YES");
	else puts("NO");
	return 0;
}

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

using namespace std;

int main()
{
  string s;
  while(getline(cin, s), s != "."){
    stack<int> bkt;
    for(int i = 0; i < s.size(); i++){
      if(s[i] == '(') bkt.push(1);
      else if(s[i] == '[') bkt.push(2);
      else if(s[i] == ')'){
	if(bkt.empty() || bkt.top() == 2){
	  bkt.push(-1);
	  break;
	} else {
	  bkt.pop();
	}
      }
      else if(s[i] == ']'){
	if(bkt.empty() || bkt.top() == 1){
	  bkt.push(-1);
	  break;
	} else {
	  bkt.pop();
	}
      }
    }
    if(bkt.empty()) cout << "yes" << endl;
    else cout << "no" << endl;
    cin.clear();
  }
  return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


int a;
int N, M;

map<vint, int> dist;

int main() {
    while (cin >> N >> M) {
        vector<int> start(N, 0), goal1(N, 0), goal2(N, 0);
        for (int i = 0; i < N; ++i) cin >> a, start[i] = a;
        int t = 0;
        for (int i = 0; i < M; ++i) {
            cin >> a;
            for (int j = 0; j < a; ++j) {
                goal1[t] = (i&1);
                goal2[t++] = !(i&1);
            }
        }
        //COUT(start); COUT(goal1); COUT(goal2);
        
        dist.clear();
        dist[start] = 0;
        queue<vint > que;
        que.push(start);
        while (!que.empty()) {
            vint bit = que.front();
            int d = dist[bit];
            que.pop();
            
            //cout << bit << " : " << d << endl;
            
            for (int i = 0; i < N-1; ++i) {
                swap(bit[i], bit[i+1]);
                if (!dist.count(bit)) {
                    dist[bit] = d+1;
                    que.push(bit);
                }
                swap(bit[i], bit[i+1]);
            }
        }
        
        int res = 1<<29;
        if (dist.count(goal1)) chmin(res, dist[goal1]);
        if (dist.count(goal2)) chmin(res, dist[goal2]);
        cout << res << endl;
    }
    
    return 0;
}


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

int main(){
    ll n;
    cin >> n;
    vector<ll> dp(n+1, 1e18);
    dp[0] = 0;
    rep(i, 1, n+1){
        for(ll j = 1; j <= i; j *= 6){
            dp[i] = min(dp[i], dp[i-j]+1);
        }
        for(ll j = 1; j <= i; j *= 9){
            dp[i] = min(dp[i], dp[i-j]+1);
        }
    }
    cout << dp[n] << endl;
    return 0;
}

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

int N, K;
vector<int> G[2020];

void rec(int v, int p, int curdepth, vector<int> &depth) {
  depth[v] = curdepth;
  for (auto nv : G[v]) {
    if (nv == p) continue;
    rec(nv, v, curdepth + 1, depth);
  }
}

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

  int ans = 1e18;
  vector<int> depth(N);
  if (K % 2 == 0) {
    for (int i = 0; i < N; i++) {
      rec(i, -1, 0, depth);
      int num = 0;
      for (int i = 0; i < N; i++)
        if (depth[i] > K / 2) num++;
      ans = min(ans, num);
    }

  } else {
    for (int u = 0; u < N; u++) {
      for (auto v : G[u]) {
        depth[v] = 0;
        rec(u, v, 0, depth);
        rec(v, u, 0, depth);
        int num = 0;
        for (int i = 0; i < N; i++)
          if (depth[i] > K / 2) num++;
        ans = min(ans, num);
      }
    }
  }

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


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

int main() {
  int n, c, p;
  cin >> n >> c;
  int sum = 0;
  int i;
  for (i = 0; i < c; i++) {
    cin >> p;
    sum += p;
  }
  cout << (sum + n) / (n + 1) << endl;
  return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N;
vector<int> a;

int main(){
    cin >> N;
    a.resize(N);
    rep(i,N) cin >> a[i];
    sort(all(a));
    reverse(all(a));

    if(a[0]==N-1 and a[N-1]==N-1){
        cout << "Yes" << endl;
        return 0;
    }

    if(a[0]-a[N-1] >1){
        cout << "No" << endl;
        return 0;
    }

    if(a[0]-a[N-1]==1){
        int mn = a[N-1];
        int mx = a[0];
        int mnn=0,mxn=0;
        rep(i,N) if(a[i]==mn) mnn++;
        rep(i,N) if(a[i]==mx) mxn++;

        int unused  = N - mx;

        int use = mx - mnn;
        //cout << use << endl;
        if(use<=0){
            cout << "No" << endl;
            return 0;
        }

        if(unused < use){
            cout << "No" << endl;
            return 0;
        }

        int t=use+unused;
        if(mxn!=t){
            cout << "No" << endl;
            return 0;
        }

        cout << "Yes" << endl;
    }else{
        if(N >= a[0]*2){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

signed main()
{
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, 0, n)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3624
import queue
H, W = map(int, input().split())
S = [list(map(int, input().replace(".", "0").replace("#","1"))) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
Visited = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if not Visited[h][w]:
            Visited[h][w] = True
            Color = ([1, 0] if S[h][w] == 0 else [0, 1])
            Q = queue.Queue()
            Q.put((h, w, S[h][w]))
            while not Q.empty():
                nh, nw, nc = Q.get()
                for s in Search:
                    nexth, nextw = nh + s[0], nw + s[1]
                    if 0 <= nexth < H and 0 <= nextw < W:
                        if not Visited[nexth][nextw] and S[nexth][nextw] != nc:
                            nextc = S[nexth][nextw]
                            Visited[nexth][nextw] = True
                            Q.put((nexth, nextw, nextc))
                            Color[nextc] += 1
            Total += Color[0] * Color[1]

print(Total)

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

public class Main {

  // // 最大公約数
  // public static long gcd (long m,long n) {
  //   if (m < n) return gcd(n,m);
  //   if (n == 0) return m;
  //   return gcd(n,m%n);
  // }
  //
  // // 最小公倍数
  // public static long lcm (long m,long n) {
  //   return m*n/gcd(m,n);
  // }
  //
  // // 素数判定
  // public static boolean isPrime (long n) {
  //   if (n == 2) return true;
  //   if (n < 2 || n%2 == 0) return false;
  //   double d = Math.sqrt(n);
  //   for (int i = 3; i <= d; i+=2) {
  //     if (n%i == 0) {
  //       return false;
  //     }
  //   }
  //   return true;
  // }
  //
  // public static final long gcd3(long[] param) {
  //   int len = param.length;
  //   long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
  //   for (int i = 1; i < len - 1; i++) {
  //       g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
  //   }
  //   return g;
  // }

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

    long[] h = new long[n];

    for (int i = 0; i < n; i++) {
      h[i] = sc.nextLong();
    }

    Arrays.sort(h);

    long[] data = new long[n];

    long min = h[k-1]-h[0];

    for (int i = 0; i < n-k+1; i++) {
      data[i] = h[i+k-1]-h[i];
      min = Math.min(min,data[i]);
    }

    System.out.println(min);

  }

}


Measured memory_bytes: 50592
# -*- coding: utf-8 -*-

import sys

primes = [2]
for i in range(3, 50022):
    flag = True
    for p in primes:
        if i % p == 0:
            flag = False
            break
    if flag:
        primes.append(i)

for line in sys.stdin:
    n = int(line)
    i = 0
    while primes[i] < n and i < len(primes):
        i += 1
    if primes[i] == n:
        s = primes[i-1]
        m = primes[i+1]
    else:
        s = primes[i-1]
        m = primes[i]
    print s, m

Measured memory_bytes: 7988
object Main {
  def main(args: Array[String]): Unit = {
    for (ss <- io.Source.stdin.getLines()) {
      var s = ss
      while (!check(s)) {
          s = next(s)
      }
      println(s)
    }
  }

  def next(s: String): String = {
    val sss = s.map(c => {
      c match {
        case ' ' => ' '
        case '.' => '.'
        case cc: Char => (((cc - 'a' + 1) % 26) + 'a').toChar
      }
    })
    return sss.toString()
  }

  def check(s: String): Boolean = {
    val list = List("the", "this", "that")
    list.foreach { ss =>
      if (s.contains(ss)) {
        return true
      }
    }
    return false
  }
}

Measured memory_bytes: 43992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[N];
        int sum = 0;
        for (int i = 0; i < N; i++) {
            A[i] += sc.nextInt();
            sum += A[i];
        }
        double border = (double)sum / 4 / M;
        int count = 0;
        for (int i = 0; i < N; i++) {
            if (border <= A[i])
                count++;
        }
        if (count >= M) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22864
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout<<'\n';
#define MOD 1000000007
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define deb(x) cout << "[" << #x << "=" << x << "]" << '\n'
#define deb2(x,y) cout << "[" <<#x << "=" << x << "] [" << #y << "=" << y << "]" << '\n'
#define deb3(x,y,z) cout << "[" <<#x << "=" << x << "] [" << #y << "=" << y << "] [" << #z << "=" << z << "]" << '\n'

void solve(){
	int n,d; cin>>n>>d;
	int cnt=0;
	for(int i=0 ; i<n ; i++){
		int u,v; cin>>u>>v;
		if(sqrt(u*u+v*v)<=d){
			++cnt;
		}
	}
	cout<<cnt;LOL
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
 // int _;
  //for(cin>>_ ; _ ; --_){
    //cout<<"Case "<<_<<": ";
    solve();
  //}
  return 0;
}

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

int main() {
	int n;
	string s;
	cin >> n >> s;
	int open = 0, close = 0;
	int o = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == ')') {
			if (o > 0) o--;
			else open++;
		}
		else o++;
		
		if (s[i] == ')') {
			if (close > 0) close--;
		}
		else close++;
	}
	
	for (int i = 0; i < open; i++) {
		cout << '(';
	}
	cout << s;
	for (int i = 0;i < close; i++) {
		cout << ')';
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main(void)
{
    int A,B,N;
    scanf("%d%d%d",&N,&A,&B);
    if(N==1)
    {
        if(A==B)
            printf("1\n");
        else
            printf("0\n");
    }
    else 
    {
        if(A>B)
            printf("0\n");
        else
            printf("%lld\n",(long long )(B-A)*(N-2)+1);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

struct Graph {
    struct Vertex { int n, d[2]; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1, { -1, -1 } }), e(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    void dfs(int i, int d, int t) {
        if (v[i].d[t] >= 0) return;
        v[i].d[t] = d;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            dfs(o.i, d + 1, t);
        }
    }
    bool solve() {
        int k = 0;
        for (int i = 0; i < n; i++) {
            k += v[i].d[0] <= v[i].d[1];
        }
        return k > n - k;
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n;
    cin >> n;

    Graph g(n, (n - 1) * 2);

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    g.dfs(0, 0, 0);
    g.dfs(n - 1, 0, 1);

    cout << (g.solve() ? "Fennec" : "Snuke") << endl;

    return 0;
}

Measured memory_bytes: 4736