akhauriyash/Code-Regression huggingface dataset:
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

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

			int N = scan.nextInt();
			int M = scan.nextInt();

			int A[] = new int[M];
			int B[] = new int[M];
			UnionfindTree Tree = new UnionfindTree(N);
			for(int i = 0;i<M;i++) {
				A[i] = scan.nextInt()-1;
				B[i] = scan.nextInt()-1;
				Tree.union(A[i], B[i]);
			}

			Map<Integer,Integer>map = new TreeMap<Integer,Integer>();

			for(int i = 0;i<N;i++) {
				//System.out.println(Tree.find(i));
				int a = Tree.find(i);
				if(map.containsKey(a)) {
					map.put(a, map.get(a)+1);
				}else {
					map.put(a, 1);
				}
			}

			//System.out.println();

			int max = 0;
			for(Integer key:map.keySet()) {
				if(max<map.get(key))max = map.get(key);
			}

			System.out.println(max);










		}


	}



	//unionfind は分割できない以下重要なこと。
/*
 * 繋げていく処理だけを考えるとき，繋げたものだけを考えれば良いので，連結かどうかの判定は簡単
 *
 * 辺を壊した後にグラフが連結がどうかは，遠くまで見ないと連結かどうかの判定が難しい．
 *
 * 上記の「難しい」というのは，グラフ上を遠くまで探索して連結かどうかを愚直に調べることのできるのは
 * DFS，BFS なので，制約が大きいと計算量的に判定が難しい，という意味．
 *
 * 以上 3 つを考えると意味が分かると思います．繋がっているかどうかの判定は，
 * ここまで見てきた通り，Union-Find 木を使えば簡単にできます
 * （DFS，BFS，ワーシャルフロイド法などでも繋がっているかの判定はできるが，制約が大きくなると計算量的に使えない）．
 * このポイントは，例えば「無向グラフが与えられてその辺を壊し
 * ，連結かどうかの判定」を行うという典型的な問題に対して適用することができます．
 */



//グループを作る、そしてそのグループについてどうなのかという問題に使えるUNIONFIND木
private static class UnionfindTree{
	int [] parent;//配列番号＝頂点番号、値＝その点の親の頂点
	int [] rank;//その頂点を根とするグラフの深さの値、独立した頂点をランク１とする


	public UnionfindTree(int size){//size=グループ分けしたい頂点の数の合計
		this.parent = new int[size];
		this.rank = new int[size];
		for(int i = 0;i<size;i++) {
			parent[i] = i;
			rank[i] = 0; //集合の高さ
		}
	}

	public void union(int x, int y) {//計算量　O(logN)パス圧縮してるのでO(1/A(n,n))と相当小さくなる
		int xRoot = find(x);
		int yRoot = find(y);

		//xが属する木の方が大きい場合
		if (rank[xRoot] > rank[yRoot]) {
			parent[yRoot] = xRoot; //yの親をxに更新

		} else if(rank[xRoot] < rank[yRoot]) {
			parent[xRoot] = yRoot;

		} else if (xRoot != yRoot){//高さ一緒で同じ値ではない、同じ値は無視していい
			parent[yRoot] = xRoot;
			rank[xRoot]++; //同じ高さの木がルートの子として着くから大きさ++;
		}
	}

	//引数の属する木のルートのidを返す
	public int find(int i) {//計算の工夫パス圧縮、これによりこのメソッドの計算量は  O(logN)  になる。(非自明)
		if (i != parent[i]) {//指定された頂点が根(親)なら無視してそのまま値を返せばいい
			parent[i] = find(parent[i]);//そうでないならその頂点がもつ親の値までいきそこでその値をもらいに行く
		}//それと同時に、指定された頂点のもつ値をそこで保存しておくことで、パス圧縮が行われ計算量が短縮される。
		return parent[i];
	}

	//同じ木に属しているか
	public boolean same(int x, int y) {//計算量O(logN)
		return find(x) == find(y);
	}
}


}


Measured memory_bytes: 65708
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {

	public static double getDistance (double a, double b, double c, double d) {

		return Math.sqrt(Math.pow(c -a,2) + Math.pow(d - b,2));

	}

	public static void main(String[] args) throws IOException {

		BufferedReader br =
			new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> ans = new ArrayList<String>();
		int n = Integer.parseInt(br.readLine());

		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine()," ");

			double x1 = Double.parseDouble(st.nextToken());
			double y1 = Double.parseDouble(st.nextToken());
			double x2 = Double.parseDouble(st.nextToken());
			double y2 = Double.parseDouble(st.nextToken());
			double x3 = Double.parseDouble(st.nextToken());
			double y3 = Double.parseDouble(st.nextToken());

			double a1 = 2 * (x2 - x1);
			double b1 = 2 * (y2 - y1);
			double c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
			double a2 = 2 * (x3 - x1);
			double b2 = 2 * (y3 - y1);
			double c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;

			double xp = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
			double yp = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);

			double a = getDistance(x1,y1,x2,y2);
			double b = getDistance(x1,y1,x3,y3);
			double c = getDistance(x2,y2,x3,y3);

			double s = (a + b + c) / 2;
			double S = Math.sqrt(s * (s - a) * (s - b) * (s - c));
			double r = (a * b * c) / (S * 4);

			BigDecimal bd_xp = BigDecimal.valueOf(xp).setScale(3, BigDecimal.ROUND_HALF_UP);
			BigDecimal bd_yp = BigDecimal.valueOf(yp).setScale(3, BigDecimal.ROUND_HALF_UP);
			BigDecimal bd_r  = BigDecimal.valueOf(r).setScale(3, BigDecimal.ROUND_HALF_UP);

			ans.add(bd_xp.toString() + " " + bd_yp.toString() + " " + bd_r.toString());
		}
		for (String s : ans) {
			System.out.println(s);
		}
	}

}

Measured memory_bytes: 9912
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long li;

int main(void) {
  int cnt[26] = {};
  int n;
  static char s[100001];
  scanf("%d%s", &n, s);
  for (int i = 0; i < n; ++i) cnt[s[i] - 'a'] += 1;

  const int mod = 1e9 + 7;
  int ans = 1;
  for (int i = 0; i < 26; ++i) ans = 1LLU * ans * (cnt[i] + 1) % mod;
  ans = (ans + mod - 1) % mod;
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int n,m;
double dp[1<<16][16];
double data[17][17];

double memo(int bit,int v){
	if(v==n)return 1.0;
	if(bit==0)return 0.0;
	if(dp[bit][v]>=0.0)return dp[bit][v];
	double res=0.0;
	for(int i=0;i<m;i++){
		if(!(bit>>i & 1))continue;
		double sum=0.0,win=1.0;
		int lbit=bit-(1<<i);
		for(int j=v;j<n;j++){
			sum+=memo(lbit,j)*win*(1-data[i][j]);
			win*=data[i][j];
		}
		sum+=win;
		res=max(res,sum);
	}
	return dp[bit][v]=res;
}

int main(void){
	scanf("%d %d",&m,&n);
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			scanf("%lf",&data[i][j]);
		}
	}
	memset(dp,-1,sizeof(dp));
	double res=0.0;
	printf("%.10f\n",memo((1<<m)-1,0));
	return 0;
}

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

int main() {
  string S;
  int count=0;
  cin >> S;
  for(int i=0; i<S.size()/2; i++) {
    if(S.at(i)==S.at(S.size()-i-1)&&S.at(i)==S.at((S.size()+1)/2+i)) {
      count++;
    }
  }
  if (count==S.size()/2) {
    cout << "Yes" << endl;
  }
  else if(count!=S.size()/2) {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include<complex>

using namespace std;

typedef long long            ll;
typedef unsigned             ui;
typedef unsigned long long   ull;
typedef pair<int,int>        i_i;
typedef pair<ll,int>         ll_i;
typedef pair<ll,ll>          ll_ll;
typedef pair<double,int>     d_i;
typedef pair<double,double>  d_d;
typedef vector<int>          vi;
typedef vector<vector<int> > vii;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      x.begin(),x.end()
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(int,x,a);
  putv(x<a?0:10);
  return 0;
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cout.precision(10);
    cout << (double)(n - n / 2) / (double)n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod2 = 1000000007;
constexpr ll mod = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,-1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    vector<vector<int>> G(H+1, vector<int> (W+1));
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            cin >> G[i][j];
        }
    }
    int ans = inf;
    for(int i=1; i<=H+W; i++){
        for(int j=1; j<=H+W; j++){
            int sum = 0;
            for(int h=1; h<=H; h++){
                for(int w=1; w<=W; w++){
                    int suzu = inf;
                    if(i >= H){
                        chmin(suzu,abs((i-H)-h));
                    }else{
                        chmin(suzu,abs(i-h));
                    }
                    if(j >= H){
                        chmin(suzu,abs((j-H)-w));
                    }else{
                        chmin(suzu,abs(j-w));
                    }
                    sum += G[h][w] * suzu;
                }
            }
            chmin(ans,sum);
        }
    }
    cout << ans << enld;
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  cout << (x - a) % b << endl;
  return 0;
}

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2011

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const int MAX = 31;

typedef long long ll;

int main()
{
	int N,M;
	while( cin >> N && N )
	{
		ll dp[N][MAX]; //i番目の人がj日目までに集められる最大値(bitで表現)
		bool is_ok[N][MAX]; //その人の都合を表す配列
		fill_n((int *)dp, sizeof(dp) / sizeof(int), 0);
		fill_n((bool *)is_ok, sizeof(is_ok) / sizeof(bool), false);

		int f;
		rep(i,N)
		{
			cin >> M;
			rep(m,M){
				cin >> f;
				is_ok[i][f] = true;
			}	
		}
		
		REP( i, 0, N ){
			dp[i][0] |= 1LL<<i;
		}

		const ll COMP = (1LL<<N)-1;
		int ans=-1;
		REP( j, 1, MAX ){
			REP( i, 0, N ){
				if(is_ok[i][j]){
					REP( k, 0, N ){
						if(is_ok[k][j]){
							dp[i][j] |= dp[k][j-1];
						}
					}
				}else{
					dp[i][j] |= dp[i][j-1];
				}
	
				if(dp[i][j] == COMP){ ans=j; goto end; }
			}
		}
end:
		cout << ( (ans==-1) ? -1 : ans ) << endl;  
	}
	return 0;
}

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

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

  int H, W;
  cin >> H >> W;
  vector<string> C(H);
  for (int i = 0; i < H; ++i) {
    cin >> C.at(i);
    cout << C.at(i) << endl;
    cout << C.at(i) << endl;
  }

  return 0;
}


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

#define ll long long 
#define int long long 
#define mod 1e9 + 7
void add(ll &a, ll b){
	a += b;
	if(a >= mod)
		a -= mod;
	}
	
void sub(ll &a, ll b){
	a -= b;
	if(a >= mod)
		a -= mod;
	else if(a < 0)
		a += mod;
	}
ll pref[405];	
ll sum(int l, int r){
	if(l == 0)
		return pref[r];
	return pref[r] - pref[l-1];
	}

const int nax = 405;
ll dp[nax][nax];
//~dp[i][j] - min cost of combining interval [i, j]
//~similar to prev question where we took smaller intervals and then combined them to form bigger intervals

signed main(){
	int n; cin>>n;
	int arr[n];
	for(int i = 0; i<n; i++){
		cin>>arr[i];
		if(i)
			pref[i] = pref[i-1] + arr[i];
		else
			pref[i] = arr[i];
		//~cout << pref[i] << " ";
		}
	//~cout << endl;
	for(int L = n-1; L>=0; L--){
		for(int R = L; R<n; R++){
			if(L == R){
				dp[L][R] = 0;
				continue;
			}
			ll temp = LLONG_MAX;
			for(int  i = L; i<R; i++){
				temp = min(temp, dp[L][i] + dp[i+1][R] + sum(L, R));
				//~cout << "the fook "<< temp <<" " << dp[L][i] + dp[i+1][R] + sum(L, R) <<"\n";
			}
			dp[L][R] = temp;
			}
		}
	cout << dp[0][n-1] << endl;
	return 0;
	}


Measured memory_bytes: 1536
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int N;

    scanf("%d", &N);

    int D[N][2];

    for(int i = 0; i < N; i++){
        scanf("%d%d", &D[i][0], &D[i][1]);
    }

    int f = 0;

    for(int i = 2; i < N; i++){
        if(D[i-2][0] == D[i-2][1] && D[i-1][0] == D[i-1][1] && D[i][0] == D[i][1]){
            f = 1;
            break;
        }
    }

    if(f == 1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1660
from collections import deque
N = int(input())
adj = [[] for i in range(N)]


for i in range(N-1):
    a, b = map(int, input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)


dq = deque([(0, 'b'), (N-1, 'w')])

colors = [0] * N
colors[0] = 'b'
colors[-1] = 'w'


while dq:
    node, color = dq.popleft()
    for dest in adj[node]:
        if colors[dest] != 0:
            continue
        else:
            colors[dest] = color
            dq.append((dest, color))

print('Fennec' if colors.count('b') > N//2 else 'Snuke')

Measured memory_bytes: 23440
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n=sc.nextInt();
			if(n==0) {
				break;
			}
			double[] array = new double[n];
			double sum =0;
			for(int i=0; i<n; i++) {
				array[i]=sc.nextDouble();
				sum+=array[i];
			}
			double m = sum/n;

			double a=0;

			for(double s : array) {
				a+=(s-m)*(s-m);
			}
			a=Math.sqrt(a/n);
			System.out.printf("%f",a);
			System.out.println();
		}

	}
}


Measured memory_bytes: 39928
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n: usize,
        happi: [[u64; 3]; n], 
    }
    let mut dp = vec![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] + happi[i][k]);
                }
            }
        }
    }
    println!("{}", max(dp[n][0], max(dp[n][1], dp[n][2])));
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, l;
  cin >> n >> l;
  int a[n];
  REP(i, n) cin >> a[i];
  int pos = -1;
  REP(i, n - 1) {
    if (l <= a[i] + a[i + 1]) {
      pos = i;
      break;
    }
  }
  if (pos == -1) {
    cout << "Impossible" << endl;
  } else {
    cout << "Possible" << endl;
    for (int i = 0; i < pos; ++i) cout << i + 1 << endl;
    for (int i = n - 2; i > pos; --i) cout << i + 1 << endl;
    cout << pos + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	s := nextMega()

	ans := 0
	for i, r := len(s)-1, len(s)-1; i >= 0 && r >= 0; i-- {
		if s[i] == 'B' {
			ans += r - i
			r--
		}
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 1280
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

vector<int> adj[300001];
int vis[300001],sub[300001];
void dfs(int node)
{
    vis[node]=1;
    int cnt=0;
    for(int i=0;i<adj[node].size();i++)
    {
        if(!vis[adj[node][i]])
            dfs(adj[node][i]);
    }
    sub[node]=cnt;
}
void go()
{
    int n,k;
    cin>>n>>k;
    vector<int> a(n),dp(n+1,INT_MAX);
    for(int i=0;i<n;i++)
        cin>>a[i];
    dp[1]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j > 0)
                dp[i]=min(dp[i],dp[i-j]+abs(a[i-1]-a[i-1-j]));
            else
                break;
        }
    }
    cout<<dp[n];
}
int main()
{
    FIO;
//    int t;
//    cin>>t;
//    while(t--)
        go();
    return 0;
}


Measured memory_bytes: 11060
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n):
    if sum(list([a*b for (a,b) in zip(A[i],b)]))+c > 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
import sys
import math
import collections
n = int(input())
#a, b, c = map(int, input().split())
#s = input()
#a = list(map(int, input().split()))

l = []
for i in range(n):
  s = input()
  l.append(s)

c = collections.Counter(l)
x = c.most_common()
y = x[0][1]
ans = []
for i in range(len(x)):
  if x[i][1] != y:
    break

  ans.append(x[i][0])


ans.sort()
for j in range(len(ans)):
  print(ans[j])


Measured memory_bytes: 47820
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll  = long long;
template <typename T> T In() { T t; cin >> t; return t;}
template <typename T> vector<T> ReadVec1(int N) {
    vector<T> vec(N);
    for(int i = 0; i < N; i++)
        vec[i] = In<T>();
    return move(vec);
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(j, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}

template <typename T> constexpr T gcd(T m, T n){
    return n == 0 ? m : gcd(n, m % n);
}
template <typename T> constexpr T lcm(T m, T n) {
    return n == 0 or m == 0 ? 0 : m  / gcd(m, n) * n;
}

ll count(ll A, ll C, ll D) { 
    return A - (A / C) - (A / D) + (A / lcm(C, D)); 
}

int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << count(B, C, D) - count(A - 1, C, D) << endl;
}

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

int popcount(int x){
  int ans=0;
  while(x!=0){ans+=x&1;x>>=1;}
  return ans;
}


int main(){
    while(1){
        int n; cin >> n;
        if(n==0) break;
        bool jotai[1<<10][10]={};
        string po;
        cin >> po;
        for(int i=0;i<po.size();i++){
          if(po[i]=='u'){
            int j=i-1;
            while(j>=0&&po[j]!='u')j--;
            j++;
            for(int k=j+1;k<min(i,j+11);k++){
              int S=0;
              for(int l=j;l<k;l++)S|=1<<(po[l]-'0');
              jotai[S][po[k]-'0']=true;
            }
          }
        }
        for(int len=2;len<=10;len++){
          for(int S=1;S<(1<<10);S++){
            if(popcount(S)==len){

              for(int x=0;x<=9;x++){
                for(int Sprime1=1;Sprime1<S;Sprime1++){
                  if(jotai[Sprime1][x]==true&&(S^Sprime1)==S-Sprime1){
                    for(int y=0;y<=9;y++){
                      if((Sprime1>>y)%2==1&&jotai[S^Sprime1][y]==1)jotai[S][x]=true;
                    }
                  }
                }
              }

            }
          }
        }
        int isOK=1;
        for(int x=0;x<=9;x++)for(int S=1;S<(1<<10);S++)if(jotai[S][x]==true&&(S>>x)%2==1)isOK=0;
      //  printf("%d",jotai[3][1]);
        if(isOK)printf("SAFE\n");
        else printf("UNSAFE\n");
    }
    return 0;
}



Measured memory_bytes: 3152
n, k = map(int, input().split())
a = list(map(int, input().split()))
l = [1]
b = [1] + [0] * (n-1)
for i in range(n):
  b[a[l[i]-1]-1] += 1
  if b[a[l[i]-1]-1] == 2:
    break
  else:
    l.append(a[l[i]-1])

lindex = l.index(a[l[i]-1])
r = len(l) - lindex
rlist = l[lindex:]

if k >= lindex:
  kmod = (k - lindex) % r
  ans = rlist[kmod]
else:
  ans = l[k]
  
print(ans)

Measured memory_bytes: 32360
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int a[103];

 int main()
 {   int n;
 cin>>n;
 for(int i=1;i<=n;i++)
     cin>>a[i];
 sort(a+1,a+1+n);
 int sum=0;
 for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
    for(int k=j+1;k<=n;k++)
      if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]+a[j]>a[k])sum++;
 cout<<sum;

 }


Measured memory_bytes: 3636
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    int i, n, cnt, *a_n, *n_n;
    cin >> n;
    cnt = 1;
    a_n = new int[n];
    n_n = new int[n];    

    for(i = 0; i < n; i++){
        cin >> a_n[i];
        n_n[a_n[i] - 1] = cnt;
        cnt++;
    }
    for(i = 0; i < n; i++){
        cout << n_n[i] << endl;
    }

}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

// int gcd(int a, int b){
//   if (a%b==0){
//     return(b);
//   }
//   else{
//     return(gcd(b,a%b));
//   }
// }


int x[110];
int y[110];

int main(){
  int N,M;
  int X,Y;
  cin >> N >> M >> X >> Y;
  rep(i,N) cin >> x[i];sort(x,x+N);
  rep(i,M) cin >> y[i];sort(y,y+M);
    if(max(x[N-1],X) < min(y[0],Y)){
      cout << "No War" << endl;
      return 0;
    }
  cout << "War" << endl;
  
}



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

int main() {
	int  a, b, x;

	cin >> a >> b;
	x = a*b;
	if (x % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))

rui=[]
rui.append(p[0]/2+0.5)
for i in range(1,n):
    rui.append(rui[i-1]+(p[i]/2+0.5))

#print(rui)
ans=[]
ans.append(rui[k-1])
for i in range(n-k):
    ans.append(rui[k+i]-rui[i])
    #print(ans)
print(max(ans))

Measured memory_bytes: 25060
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    PriorityQueue<Double> pq = new PriorityQueue<>(n);
    for(int i=0;i<n;i++){
      pq.add(sc.nextDouble());
    }
    double te=pq.poll();
    while(!pq.isEmpty()){
      te=(te+pq.poll())/2;
    }
    System.out.println(te);
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc099_c() {
	ll N;
	string S;
	ll ans = 0;
	cin >> N >> S;

	vector<ll> W(N, 0), E(N, 0);
	rep(i, N) {
		if (i != 0) {
			W[i] = W[i - 1];
			E[N - 1 - i] = E[N - i];
		}
		if (S[i] == 'W') {
			W[i]++;
		}
		if (S[N - 1 - i] == 'E') {
			E[N - 1 - i]++;
		}
	}

	ans = INF;
	rep(i, N) {
		if (i == 0) {
			ans = min(ans, E[i + 1]);
		}
		else if (i == N - 1) {
			ans = min(ans, W[i - 1]);
		}
		else {
			ans = min(ans, E[i + 1] + W[i - 1]);
		}
	}

	cout << ans << "\n";
}

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

	solve_abc099_c();

	return 0;
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

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

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    if (a >= k) {
        cout << k << endl;
        return;
    }

    k -= a;

    if (b >= k) {
        cout << a << endl;
        return;
    }
    
    k -= b;

    cout << a - k << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3652
// https://atcoder.jp/contests/abc138/tasks/abc138_d
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#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 ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

vector<vector<int>> Graph;
vector<int> total;
int pscore[200005];
void dfs(int num, int score) {
    total[num] += score;
    for (auto x : Graph[num]) {
        dfs(x, score + pscore[x]);
    }
    return;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q, a, b;
    cin >> n >> q;
    Graph.resize(n);
    total.resize(n, 0);
    REP(i, n - 1) {
        cin >> a >> b;
        a--;
        b--;
        Graph[a].push_back(b);
    }
    REP(i, q) {
        cin >> a >> b;
        a--;
        pscore[a] += b;
    }
    dfs(0, pscore[0]);
    for (auto x : total) {
        cout << x << " ";
    }

    return 0;
}


Measured memory_bytes: 20992
inputs = [int(x) for x in input().split(' ')]
n = inputs.pop(3)
inputs.sort(reverse=True)

count = 0
for i in range(n // inputs[0] + 1):
  tmp_n1 = n
  tmp_n1 -= i * inputs[0]

  if tmp_n1 == 0:
    count += 1
    continue

  for j in range(tmp_n1  // inputs[1] + 1):
    tmp_n2 = tmp_n1 - j * inputs[1]
    
    if tmp_n2 == 0:
      count += 1
      continue

    if tmp_n2 % inputs[2] == 0:
      count += 1

print(count)

Measured memory_bytes: 3064
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M, K = mapint()

s = set()
for n in range(N+1):
    for m in range(M+1):
        s.add(n*M + m*N - n*m*2)

if K in s:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 108628
import java.util.*;

public class Main{
	Scanner sc = new Scanner(System.in);
	int [] table = {0,1,2,3,5,7,8,9};

	private void doit(){
		while(true){
			int n = sc.nextInt();
			if(n == 0)break;
			String s = Integer.toOctalString(n);
			StringBuilder ans = new StringBuilder();
			for(int i = 0; i < s.length(); i++){
				int ind = s.charAt(i) - '0';
				ans.append(table[ind]);
			}
			System.out.println(ans.toString());
		}
	}
	
	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 50928
"""
Writer: SPD_9X2
https://atcoder.jp/contests/agc044/tasks/agc044_d

文字数はわかる
どの文字がいくつあるかは分かる
a文字入ってたとすると
128-|S| + |S|-a = 128-a = rep
a = 128-rep

文字列のマージを考える
同じ文字はまとめて扱ったほうが良い？
大きい方を小さい方に融合することを考える

aaaa + bbb → aabbaba
にすることを考えてみようか

aaaa → 3
aabaa
左側の文字列に右の文字列を前から入れていく
入れる場所が正しければ回数は減る

2分割していけばマージ計算量でO(nlogn)!
128 + log128 + log128

マージ部分が違うっポイ？
同じ文字が両方に交じってると面倒なことになる
小さい方からマージ？
"""

def merge(L,R):

    if len(L) > len(R):
        tmp = L
        L = R
        R = tmp

    #Rが長いのでLをRにマージする

    if len(R) > 1:
        print ("?","".join(R),flush=True)
        origin = int(input())
    else:
        origin = len(s)-1

    ok = []
    while len(L) > 0 and len(R) > 0:
        
        q = ok + [ L[0] ] + R
        if len(q) > 1:
            print ("?" , "".join(q) , flush=True)
            now = int(input())
        else:
            now = len(s)-1

        if now < origin:
            ok.append(L[0])
            del L[0]
            origin = now
        else:
            ok.append(R[0])
            del R[0]

    if len(L) > 0:
        ok = ok + L
    if len(R) > 0:
        ok = ok + R

    return ok


import heapq

alp = "abcdefghjiklmnopqrstuvwxyz"
ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
NUM = "0123456789"

ss = alp+ALP+NUM
#ss = "abc"
    
dic = {}
q = []
s = ""

for i in ss:

    print ("?",i*128,flush=True)
    ret = int(input())
    tmp = list(i * (128-ret))
    heapq.heappush (q , ( 128-ret , tmp ) )
    s += i*(128-ret)

while len(q) >= 2:

    alen,astr = heapq.heappop(q)
    blen,bstr = heapq.heappop(q)

    cat = merge(astr,bstr)
    heapq.heappush(q , (alen+blen , cat))

print ("!","".join(q[0][1]))
    

    


Measured memory_bytes: 9316
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  int x=max(0,N-5000);
  int X=-1;
  for(int i=x;i<=N;i++){
  if(N==i+(8*i)/100){
    X=i; break;
  }
   }if(X==-1)
    cout<<":("<<endl;
  else
    cout<<X<<endl;
    return 0;
}

Measured memory_bytes: 256
k = input()
s = list(map(len, k.split("T")))
x, y = map(int, input().split())
x_list = []
y_list = []
check = 1
for i in range(len(s)):
    if check == 1:
        x_list.append(s[i])
        check = -1
    else:
        y_list.append(s[i])
        check = 1

now_x = [x_list[0]]
for move in x_list[1:]:
    nxt = set()
    for i in now_x:
        nxt.add(i + move)
        nxt.add(i - move)
    now_x = nxt
    
now_y = [0]
for move in y_list:
    nxt = set()
    for i in now_y:
        nxt.add(i + move)
        nxt.add(i - move)
    now_y = nxt

if (x in now_x) & (y in now_y):
    print('Yes')
else:
    print('No')

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

int main(){
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    long double answer, rad;
    rad = M_PI * 2 * ((long double)h / 12 +((long double)m / 60) / 12 - (long double)m / 60);

    answer = (long double)(a*a + b*b) - (long double)(2 * a * b * cos(rad));

    cout << setprecision(10) << sqrtl(answer) << endl;
}

Measured memory_bytes: 4164
h, k = map(int, input().split())
mat = [input() for _ in range(h)]
for _  in range(2):
    poplist = []
    for i, row in enumerate(mat):
        for x in row:
            if x == '#':
                break
        else:
            poplist.append(i)
    poplist.reverse()
    for i in poplist:
        mat.pop(i)
    poplist = []
    mat = [x for x in zip(*mat)]
for row in mat:
    print(''.join(row))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
   int a,b,c,d,pay;
  cin>>a>>b>>c>>d;
  
  if(a<=b){
    pay=a*c;
  }
  else{
    pay=b*c+(a-b)*d;
  }
  
  cout<<pay<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int n;
    string s;

    cin >> n >> s;
    if(s.substr(0, n/2) == s.substr(n/2, n)){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ALDS1_1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ');
            var A = new int[1000];
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(input[i]);
            }
            var prt = "";
            for (int k = 0; k < N; k++)
            {
                if (k == N - 1)
                {
                    prt += A[k];
                }
                else
                {
                    prt += A[k] + " ";
                }
            }
            Console.WriteLine(prt);
            InsertionSort(A, N);
        }
        public static int[] InsertionSort(int[] A, int N)
        {
            for (int i = 1; i <= N - 1; i++)
            {
                var v = A[i];
                var j = i - 1;
                while (j >= 0 && A[j] > v)
                {
                    A[j + 1] = A[j];
                    j--;
                }
                A[j + 1] = v;

                var prt = "";
                for (int k = 0; k < N; k++)
                {
                    if (k == N - 1)
                    {
                        prt += A[k];
                    }
                    else
                    {
                        prt += A[k] + " ";
                    }
                }
                Console.WriteLine(prt);
            }

            return A;
        }
    }
}



Measured memory_bytes: 17936
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef char keytype;

int gcd(int a, int b){ return (a % b) ? gcd(b, a % b) : b;}
int lcm(int a, int b){ return (a / gcd(a, b)) * b;}

/* a[0], ..., a[n-1] の数の最大公約数 */
int ngcd(int n, int a[])
{
    int i, d;

    d = a[0];
    for (i = 1; i < n && d != 1; i++)
        d = gcd(a[i], d);
    return d;
}

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

//#define N 5
//int p[N + 1];
int nextperm(int p[], int N)  /* 辞書式順序で次の順列 */
{
    int i, j, t;

    i = N - 1;
    p[0] = 0;  /* 番人 */
    while (p[i] >= p[i + 1]) i--;
    if (i == 0) return 0;  /* 完了 */
    j = N;
    while (p[i] >= p[j]) j--;
    t = p[i];  p[i] = p[j];  p[j] = t;
    i++;  j = N;
    while (i < j) {
        t = p[i];  p[i] = p[j];  p[j] = t;  i++;  j--;
    }
    return 1;  /* 未了 */
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

const int inf = 1012345678;
int main(){
    int x, y;
    int g[13] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};

    scanf("%d%d", &x, &y);

    if(g[x] == g[y]) puts("Yes");
    else puts("No");

    return 0;
}


Measured memory_bytes: 1632
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
using namespace std;
typedef long long ll;


int main(void) {
	int n, k; cin >> n >> k;
	vector<double> p(n);
	rep(i, n) {
		double x;
		cin >> x;
		p[i] = (x + 1.0) / 2.0;
	}
	int cnt = 0;
	double sum = 0.0;
	double m=0.0;
	rep(i, n) {
		cnt++;
		if (cnt <= k) {
			sum += p[i];
			m = max(m, sum);
		}
		else {
			sum += p[i] - p[i - k];
			m = max(m, sum);
		}
		
	}
	printf("%.9f\n", m);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define VI vector<int>
#define VL vector<long long>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
 
template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL N=1e6+5;
LL t,n,m,q,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;

string s;
LL vis[33];

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0;
	cin>>n>>m;
	repu(i,1,n){
		cin>>s;
		vis[s[0]-'A']++;
	}
	ans=n/m;
	for(i=ans;i>=0;i--){
		k=0;
		for(j=0;j<26;j++){
			k+=min(i,vis[j]);
		}
		if(k>=i*m)return cout<<i<<endl,0;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
	string s;
	int op;
	cin >> s;
	vector<int> a(4);
	a[0] = s[0] - '0';
	a[1] = s[1] - '0';
	a[2] = s[2] - '0';
	a[3] = s[3] - '0';
	for(int i = 0; i <= 7; i++){
		int t = a[0];
		for(int j = 0; j < 3; j++){
			if(i & (1 << j)){
				t += a[j + 1];
			}else{
				t -= a[j + 1];
			}
		}
		if(t == 7){
			op = i;
			break;
		}
	}
	string ans;
	ans.push_back(s[0]);
	for(int i = 0; i < 3; i++){
		if(op & (1 << i)){
			ans += "+";
		}else{
			ans += "-";
		}
		ans.push_back(s[i + 1]);
	}
	ans += "=7";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    int N, K;
    while (cin >> N >> K) {
        if (N == 0 && K == 0) break;
        int S[K];
        for (int i = 0; i < K; i++) {
            cin >> S[i];
        }
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < K; j++) {
                int b; cin >> b;
                S[j] -= b;
            }
        }

        string ans = "Yes";
        for (int i = 0; i < K; i++) {
            if (S[i] < 0) {
                ans = "No";
            } 
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 904
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

const ll MOD = 1e9 + 7;
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    string S1,S2;
    cin >> S1 >> S2;
    ll res = 0;
    ll len = S1.length();
    bool flag = false;
    for(int i = 0;i < len;){
        if(i == 0){
            if(S1[i] == S2[i]){
                res = 3;
                i++;
                flag = true;
            }else{
                res = 6;
                i+=2;
            }
            continue;
        }
        
        if(flag){
            if(S1[i] == S2[i]){
                (res *= 2)%=MOD;
                i++;
            }else{
                (res*=2)%=MOD;
                i+=2;
                flag = false;
            }
        }else{
            if(S1[i] == S2[i]){
                i++;
                flag = true;
            }else{
                (res *=3)%=MOD;
                i+=2;
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int LinerSearch(int*,int,int);
int main(){
  int n,q,i,key,ans=0;
  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(LinerSearch(S,n,key)==1)ans++;
  }
  printf("%d\n",ans);
  return 0;
}

int LinerSearch(int *S,int n,int key){
  int i=0;
  S[n]=key;
  while(S[i]!=key){
    i++;
    if(i==n)return 0;
  }
  return 1;
}
    


      



Measured memory_bytes: 2108
#include<bits/stdc++.h>
		using namespace std;
		#define ll long long
		#define endl "\n"
		void solve();
		int main()
		{
			ios_base::sync_with_stdio(false);
			cin.tie(NULL);

		/*#ifndef ONLINE_JUDGE
			freopen("input.txt","r",stdin);
			freopen("output.txt","w",stdout);
		#endif*/
		
			int t=1;
			//cin>>t;
			while(t--){
			solve();
			cout << endl;
			}

			cerr << "time taken : "	<< (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
			return 0;		
		}
		void solve(){
			int x,y;
			cin>>x>>y;
			if(y<=4*x && y>=2*x && y%2==0){
				cout<<"Yes";
			}
			else{
				cout<<"No";
			}
		}
	

Measured memory_bytes: 3772