akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

ll R, C;
ll ch(ll x, ll y) {
	if (x != 0 && x != R && y != 0 && y != C) return -1;
	if (y == 0) return x;
	else if (x == R) return R + y;
	else if (y == C) return R + C + (R - x);
	else return 2 * R + C + (C - y);
}

pll in[100050];
vector <ll> Vx;

int bit[530000];
void update(int p, int v) {
	for (; p <= IT_MAX; p += p & (-p)) bit[p] += v;
}
int getsum(int p) {
	int rv = 0;
	for (; p; p -= p & (-p)) rv += bit[p];
	return rv;
}

int main() {
	int N, i;
	scanf("%lld %lld %d", &R, &C, &N);
	for (i = 1; i <= N; i++) {
		ll x1, y1, x2, y2;
		scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
		ll t1 = ch(x1, y1), t2 = ch(x2, y2);
		if (t1 == -1 || t2 == -1) {
			i--;
			N--;
			continue;
		}
		if (t1 > t2) swap(t1, t2);
		in[i] = pll(t1, t2);
	}
	if (!N) return !printf("YES\n");

	for (i = 1; i <= N; i++) {
		Vx.push_back(in[i].first);
		Vx.push_back(in[i].second);
	}
	sort(all(Vx));
	Vx.erase(unique(all(Vx)), Vx.end());
	for (i = 1; i <= N; i++) {
		in[i].first = lower_bound(all(Vx), in[i].first) - Vx.begin() + 1;
		in[i].second = lower_bound(all(Vx), in[i].second) - Vx.begin() + 1;
	}
	sort(in + 1, in + N + 1);

	for (i = 1; i <= N; i++) {
		int t = getsum(in[i].second) - getsum(in[i].first);
		if (t) return !printf("NO\n");
		update(in[i].second, 1);
	}
	return !printf("YES\n");
}

Measured memory_bytes: 4336
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int main()
{
	IO_OP;
	
	int n;
	cin >> n;
	double ans = 0;
	for(int i=0;i<n;i++) {
		double t;
		string c;
		cin >> t >> c;
		if(c == "BTC") t *= 380000;
		ans += t;
	}
	cout << fixed << setprecision(10) << ans << endl;
	
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;
using namespace chrono;

#ifdef DEBUG
	#define LOCAL_INPUT_FILE
#else
	//~ #define USE_FILE_IO
#endif

#ifdef USE_FILE_IO
	#define INPUT_FILE "input.txt"
	#define OUTPUT_FILE "output.txt"
	#define cin ____cin
	#define cout ____cout
	ifstream cin(INPUT_FILE);
	ofstream cout(OUTPUT_FILE);
#else
	#ifdef LOCAL_INPUT_FILE
		#define cin ____cin
		ifstream cin("input.txt");
	#endif
#endif

const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7; 
const long double eps = 1e-8;

mt19937_64 randGen(system_clock().now().time_since_epoch().count());

inline void raiseError(string errorCode) {
	cerr << "Error : " << errorCode << endl;
	exit(42);
}

signed main() {
	#ifndef USE_FILE_IO
		ios_base::sync_with_stdio(false);
	#endif
	string s; cin >> s;
	int k; cin >> k;
	int n = s.size();
	k = min(k, n);
	int kk = k;
	static int dp[302][302][302] = {};
	
	vector<int> p0(n+1);
	p0[n] = n;
	for (int i = n-1; i >= 0; --i) {
		if (s[i] == '0') {
			p0[i] = i;
		} else {
			p0[i] = p0[i+1];
		}
	}
	
	const int mod = 998'244'353;
	dp[0][0][0] = 1;
	for (int i = 0; i < n; ++i) {
		if (s[i] == '0') {
			for (int j = 0; j <= n; ++j) {
				for (int k = 0; k <= kk; ++k) {
					// 0
					dp[i+1][j][k] += dp[i][j][k];
					dp[i+1][j][k] %= mod;
					// 1
					dp[i][j+1][k+1] += dp[i][j][k];
					dp[i][j+1][k+1] %= mod;
				}
			}
		} else if (s[i] == '1') {
			for (int j = 0; j <= n; ++j) {
				for (int k = 0; k <= kk; ++k) {
					// 0
					int spare = p0[i] - i;
					if (j >= spare) {
						dp[min(p0[i]+1, n)][j-spare][k] += dp[i][j][k];
						dp[min(p0[i]+1, n)][j-spare][k] %= mod;
					}
					// 1
					dp[i+1][j][k] += dp[i][j][k];
					dp[i+1][j][k] %= mod;
				}
			}
		} else {
			assert(false);
		}
	}
	
	//~ for (int i = 0; i <= n; ++i) {
		//~ for (int j = 0; j <= n; ++j) {
			//~ cout << "{" << dp[i][j][0];
			//~ for (int k = 1; k <= kk; ++k) {
				//~ cout << " " << dp[i][j][k];
			//~ }
			//~ cout << "} ";
		//~ }
		//~ cout << endl;
	//~ }
	
	int ans = 0;
	for (int i = 0; i <= kk; ++i) {
		ans += dp[n][0][i];
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 110792
n = int(input())
li = []
x = 0

for i in range(n):
    li.append(list(map(int,input().split())))
li.sort(key=lambda x: x[1])

for i in range(n):
    x += li[i][0]
    if x > li[i][1]:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 53720
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int X, A;

    AtCoder(FastScanner sc) {
        X = sc.nextInt();
        A = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(X < A ? "0" : "10");
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

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


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

int main(){
  int n,counter;

  std::cin >> n;
    std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    /* code */
    std::cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    /* code */
    if(a.at(a.at(i)-1)==i+1)counter++;
  }
  std::cout << counter/2 << std::endl;
}


Measured memory_bytes: 640
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 3);
  (v[0], v[1], v[2])
}

fn main() {
    let (a, b, k) = read_touple::<i64>();
    let x: i64 = a + b - k;
    if b <= x {
       println!("{} {}", x - b, b);
    } else if 0 <= x && x <= b {
        println!("{} {}", 0, x);
    } else {
        println!("{} {}", 0, 0);
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
 
int main(void)
{
	int N,x,a[100000]={},i,ans;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&x);
		if(a[x]==1){
			ans++;
		}
		a[x]=1;
	}
	if(ans%2==1){
		ans++;
	}
	printf("%d",N-ans);
	return 0;
}

Measured memory_bytes: 640
import scala.io.StdIn.readInt

object Main {
  def isPrime(n:Int):Boolean = (2 to Math.sqrt(n).toInt).forall(n%_ != 0)

  def main(args:Array[String]) = {
    val n = readInt
    println((for {
      i <- 0 until n
      if isPrime(readInt)
    } yield 1).length)
  }
}

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

vector<vector<int>> s;
vector<int> c, t;
vector<pair<int, int>> last;
vector<int64_t> b_score;
vector<vector<int64_t>> c_score;

int64_t calc_score() {
    last.assign(26, {0, 0});
    for (auto i = 0; i < (int)t.size(); i++) {
        if(i != 0) {
            b_score[i] = b_score[i - 1];
            c_score[i] = c_score[i - 1];
        } else {
            b_score[i] = 0;
            c_score[i].assign(26, 0);
        }
        b_score[i] += s[i][t[i]];
        last[t[i]] = {i + 1, last[t[i]].first};
        for (auto j = 0; j < 26; j++) {
            c_score[i][j] -= c[j] * (i + 1 - last[j].first);
        }
    }

    int64_t ret = b_score.back();
    for (auto i = 0; i < 26; i++) ret += c_score[(int)t.size() - 1][i];
    return ret;
}

int64_t calc_score(pair<int, int> q) {
    last.assign(26, {0, 0});
    for (auto i = 0; i < (int)t.size(); i++) {
        if(i != 0) {
            b_score[i] = b_score[i - 1];
            c_score[i][q.first] = c_score[i - 1][q.first];
            c_score[i][q.second] = c_score[i - 1][q.second];
        } else {
            b_score[i] = 0;
            c_score[i][q.first] = 0;
            c_score[i][q.second] = 0;
        }
        last[t[i]] = {i + 1, last[t[i]].first};
        b_score[i] += s[i][t[i]];
        c_score[i][q.first] -= c[q.first] * (i + 1 - last[q.first].first);
        c_score[i][q.second] -= c[q.second] * (i + 1 - last[q.second].first);
    }

    int64_t ret = b_score.back();
    for (auto i = 0; i < 26; i++) ret += c_score[(int)t.size() - 1][i];
    return ret;
}

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

    c.resize(26);
    for (auto i = 0; i < 26; i++) cin >> c[i];

    s.assign(d, vector<int>(26));
    for (auto i = 0; i < d; i++) {
        for (auto j = 0; j < 26; j++) cin >> s[i][j];
    }

    int64_t ans = 0;
    int index = 0;
    for (auto i = 0; i < d; i++) {
        t.resize(i + 1);
        for (auto j = 0; j < 26; j++) {
            t[i] = j;
            b_score.assign(t.size(), 0);
            c_score.assign(t.size(), vector<int64_t>(26, 0));
            auto tmp = calc_score();
            if(tmp > ans) {
                ans = tmp; index = j;
            }
        }
        t[i] = index;
    }

    auto now = chrono::system_clock::now();
    auto end = chrono::system_clock::now() + chrono::milliseconds(1800);
    random_device seed;
    default_random_engine engine(seed());
    uniform_int_distribution<> day_dist(0, d - 1);
    uniform_int_distribution<> contest_dist(0, 25);
    b_score.assign(t.size(), 0);
    c_score.assign(t.size(), vector<int64_t>(26, 0));
    int64_t score = calc_score();
    while(now < end) {
        int day = day_dist(engine);
        int contest = contest_dist(engine);
        int prev = t[day];
        t[day] = contest;
        auto tmp = calc_score(make_pair(prev, contest));
        if(score < tmp) score = tmp;
        else {
            t[day] = prev;
            calc_score(make_pair(contest, prev));
        }
        now = chrono::system_clock::now();
    }

    for (auto & elm : t) cout << elm + 1 << endl;
    return 0;
}

Measured memory_bytes: 3932
#include <iostream>
#include <set>

using std::cin;
using std::cout;
using std::endl;
using std::set;

int main(){
  int init[] = {1,3,5,7,8,10,12};
  set<int> g1(init, init + 7);
  int init2[] = {4,6,9,11};
  set<int> g2(init2, init2 + 4);
  int init3[] = {2};
  set<int> g3(init3, init3 + 1);
  int x, y;
  cin >> x >> y;

  if( 0 < g1.count(x) && 0 < g1.count(y) ){
    cout << "Yes" << endl;
    return 0;
  }
  if( 0 < g2.count(x) && 0 < g2.count(y) ){
    cout << "Yes" << endl;
    return 0;
  }
  if( 0 < g3.count(x) && 0 < g3.count(y) ){
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}


const int MAX_H = 15;
const int MAX_W = 1005;
int S[MAX_H][MAX_W];

int main2() {
  int H = nextInt();
  int W = nextInt();
  int K = nextInt();
  REP(i, H) {
    string s; cin >> s;
    REP(j, W) S[i][j] = s[j] - '0';
  }

  // REP(i, H) {
  //   REP(j, W) cout << S[i][j] << " ";
  //   cout << endl;
  // }

  ll ans = 1001001001;
  REP(set, (1 << (H-1))) {
    vector<int> cut;
    cut.push_back(0);
    REP(i, H-1) if (set >> i & 1) cut.push_back(i+1);
    cut.push_back(H);

    vector<int> g(H);
    REP(h, H) g[h] = distance(cut.begin(), upper_bound(ALL(cut), h)) - 1;

    int M = cut.size() - 1;

    // if (M == 10) {
    //   cout << "cut="; pv(ALL(cut));
    //   cout << "g="; pv(ALL(g));
    // }
    vector<int> block(M);
    ll val = cut.size() - 2;
    for (int w = 0; w < W; w++) {
      // if (M == 10) {
      //   pv(ALL(block));
      // }
      REP(h, H) block[ g[h] ] += S[h][w];
      bool over = false;
      REP(c, M) if (block[c] > K) over = true;
      if (over) {
        val++;
        REP(c, M) block[c] = 0;
        REP(h, H) block[ g[h] ] += S[h][w];
        bool over2 = false;
        REP(c, M) if (block[c] > K) over2 = true;
        if (over2) {
          val = 1001001001; break;
        }
      }
      // pv(ALL(block));
    }
    // cout << "val=" << val << endl;
    chmin(ans, val);
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.range;

void main()
{
    auto input = readln.split.to!(int[]);
    auto X = input[0];
    auto Y = input[1];
    auto Z = input[2];

    auto ans = X / (Y + Z);
    (ans * (Y + Z) + Z > X ? ans - 1 : ans ).writeln;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL; // VL a(n);
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VL> VLL; // VII a(n,VI(m)) n * m
typedef pair<ll, ll> PL;
typedef map<ll, ll> MP; // MP a;
typedef vector<pair<ll, ll>> PS; // PS a(n);

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
  ll n,k,m,x=0,y=0,z = 0,cnt=0,h=0,w=0,ans=0,sum = 0, Max = -1, Min = 3e9+1;
  string s;
  cin >> n >> k;
  for(int b=k+1; b<=n; b++){
    Max = 0;
    int p = n/b;
    int r = n%b;   // n = pb + r とする。
    chmax(Max,r-k+1);
    ans += p*(b-k) + Max;
    if(k==0) // r-k+1の1を減らす. 0が被る.
      ans--;
  }
  pri(ans);
  return 0;
}

Measured memory_bytes: 3568
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let line = get_input();
    let mut split = line.split_whitespace();
    let a:i64 = split.next().unwrap().parse().unwrap();
    let b:i64 = split.next().unwrap().parse().unwrap();
    let c:i64 = split.next().unwrap().parse().unwrap();
    
    let mut abc = vec![a + b, b + c, c + a];
    let ans = abc.iter().min().unwrap();
    println!("{}", ans);
 }

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, ans, a[maxn + 10];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for (int i = 1, lst; i <= n; i = lst) {
		int d = 0;
		for (lst = i + 1; lst <= n; ++lst) {
			if (a[lst] < a[lst - 1]) {
				if (!d) d = 1;
				else if (d == -1) break;
			} else if (a[lst] > a[lst - 1]) {
				if (!d) d = -1;
				else if (d == 1) break;
			}
		}
		++ans;
	}
	printf("%d", ans);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int N = 102, M = 100005;

int n, m;

long long dp[M];
int main()
{
    cin >> n >> m;
    while (n--)
    {
        int x, g;
        cin >> x >> g;
        for (int i = m - x; i >= 0; --i)
            dp[i + x] = max(dp[i + x], dp[i] + g);
    }
    cout << dp[m] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main() {
	int n, a[100], i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (i = n; i > 0; i--) {
		printf("%d", a[i - 1]);
		if (i != 1) {
			printf(" ");
		}
	}
	printf("\n");
}


Measured memory_bytes: 2700
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

	ll n;
	cin>>n;
	ll a[n];
	ll um=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		um+=a[i];
	}
	um = um/n;
	ll ans=0;
	ll mi =0;
	for(int i=0;i<n;i++){
		ans+=(a[i] - um)*(a[i] - um);
	}
	mi = ans;
	ans=0;
	for(int i=0;i<n;i++){
		ans+=(a[i] - um-1)*(a[i] - um-1);
	}
	mi = min(mi,ans);
	ans=0;
	for(int i=0;i<n;i++){
		ans+=(a[i] - um+1)*(a[i] - um+1);
	}
		mi = min(mi,ans);
	cout<<mi;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define float long double
#define f(i,a,b) for(int i = a;i < b;i++)
#define ff(i,a,b)  for(int i = a-1;i>=b;i--)
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL)
const int mod = 1e9+7;
//int to string -> to_string()
//string to int -> stoi()

int32_t main()
{
   IOS;
   string s;
   cin>>s;
   if(s[0]=='7' or s[1]=='7' or s[2]=='7')
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
   return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define irep(i,a,b) for(typeof(i) i = (a); i < (b); ++i)
#define itrep(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)

set<ll> primes(ll n) {
	
	vector<bool> num(((ll)sqrt(n)) + 1, true);
	set<ll> p;
	for (ll i = 2; i * i <= n; i++) {
		if (num[i]) {
			p.insert(i);
			for (ll j = i; j * j <= n; j += i) {
				num[j] = false;
			}
		}
	}
	return p;
}

map<ll, ll> factorize(ll n, set<ll>* p, bool log = false) {
	map<ll, ll> F;
	for (auto it = p->begin(); it != p->end(); it++) {
		while (n % (*it) == 0) {
			F[*it]++;
			n /= *it;
		}
	}
	// 最後に残ったら素数なので、加える。
	if (n > 1) {
		F[n]++;
	}
	if (log) {
		for (auto it = F.begin(); it != F.end(); it++) {
			cout << "F(" << it->first << ") = " << it->second << endl;
		}
	}
	return F;
}

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

	ll N;
	cin >> N;

	set<ll> P = primes(N);
	map<ll, ll> F = factorize(N, &P, false);

	ll count = 0;
	for (auto it = F.begin(); it != F.end(); it++) {
		ll dc = it->second;
		ll ic = 1;
		while (dc > 0) {
			dc -= ic;
			if (dc < 0) break;
			ic++;
			count++;
		}
	}
	cout << count << endl;

	return(0);
}


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

constexpr int MAXN = (int)2e5;
constexpr long long INF = (long long)1e15;

int dp[MAXN][3];

int main()
{

    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for(int i = 1; i < n; ++i){
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

    return 0;
}

Measured memory_bytes: 2560
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int inf = 1e9;
const int mod = 1e9+7;

int main() {
    int N, M;
    cin >> N >> M;
    int a[1000], b[1000], c[1000], dist[100][100];

    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) dist[i][j] = 0;
            else dist[i][j] = inf;
        }
    }

    for (int i = 0; i < M; i++) {
        dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
        dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
    }

    // Warshall-Floyed
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (dist[i][k] == inf || dist[k][j] == inf) continue;
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }

    int ans = M;
    for (int i = 0; i < M; i++) {
        bool shortest = false;
        for (int j = 0; j < N; j++) if (dist[j][a[i]]+c[i] == dist[j][b[i]]) shortest = true;
        if (shortest == true) ans--;
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(a))
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int n,col[101010];
vi ed[101010];
map<int,map<int,int> > m;
void dfs(int x,int y,int c){
	col[x]=c;
	fo(i,0,ed[x].size()) if(ed[x][i]!=y)dfs(ed[x][i],x,(c+m[x][ed[x][i]])%2);
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n-1){
		int x,y,z;
		cin>>x>>y>>z;
		--x;--y;
		ed[x].pb(y);
		ed[y].pb(x);
		m[x][y]=m[y][x]=z%2;
	}
	dfs(0,-1,0);
	fo(i,0,n)cout<<col[i]<<endl;
	return 0;
}


Measured memory_bytes: 28928
n = int(input())
data = []
init = [0, 0, 0, 0, 0]
ans=0
for i in range(0, n):
    data.append(input())
    if data[i][0] == "M":
        init[0] += 1
    elif data[i][0] == "A":
        init[1] += 1
    elif data[i][0] == "R":
        init[2] += 1
    elif data[i][0] == "C":
        init[3] += 1
    elif data[i][0] == "H":
        init[4] += 1
ans+=init[0]*init[1]*init[2]
ans+=init[0]*init[1]*init[3]
ans+=init[0]*init[1]*init[4]
ans+=init[0]*init[2]*init[3]
ans+=init[0]*init[2]*init[4]
ans+=init[0]*init[3]*init[4]
ans+=init[1]*init[2]*init[3]
ans+=init[1]*init[2]*init[4]
ans+=init[1]*init[3]*init[4]
ans+=init[2]*init[3]*init[4]
print(ans)

Measured memory_bytes: 9772
#include <stdio.h>

int main(void)
{
	int a[10000],b[10000],r[10000][2],n,i,t1,t2,k;
	scanf("%d",&n);
	k=0;
	while(n!=0){
	t1=0;
	t2=0;
	for(i=1;i<=n;i++){
						scanf("%d %d",&a[i],&b[i]);
	}
	for(i=1;i<=n;i++){
			if(a[i]>b[i]){
					t1+=a[i]+b[i];
			}
			else if(a[i]==b[i]){
				t1+=a[i];
				t2+=b[i];
			}
			else{
					t2+=a[i]+b[i];
			}}
			r[k][0]=t1;
			r[k][1]=t2;
	k++;
	scanf("%d",&n);
	}
	for(i=0;i<k;i++){
		printf("%d %d\n",r[i][0],r[i][1]);
	}
	
	
	return 0;
}

Measured memory_bytes: 684
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
int main(){
  ll n;cin>>n;
  vector<ll> a(n),b(n),v(n);
  vector<vector<ll>> ans;
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n) v[i]=i+1;
  do{
    ans.push_back(v);
  }while(next_permutation(ALL(v)));
  cout<<abs((lower_bound(ALL(ans),a)-ans.begin())-(lower_bound(ALL(ans),b)-ans.begin()))<<endl;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int K, S;
	cin >> K >> S;
 
	long long ans = 0;
	for (int x = 0; x <= K; x++) {
		for (int y = 0; y <= K; y++) {
			int z = S - x - y;
			if (z >= 0 && z <= K) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
char c;
int n,i,a=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%c",&c);
    if(c=='Y')a++;
  }
  if(a!=0)printf("Four");
  else printf("Three");
  return 0;


}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

l = len(A)
b = [0]*N
for i, a in enumerate(A):
    if i % 2 == 0:
        b[(l//2) + (i//2)] = a
    else:
        b[(l//2) - (i//2) - 1] = a

if len(A) % 2 == 0:
    print(*b)
else:
    print(*b[::-1])


Measured memory_bytes: 25156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll maxi[1000001];
ll p=1000000007;
ll bin(ll x,ll po)
{
    ll ans=1;
    if(po==0)
        return ans;
    else if(po%2==1)
    {
        po--;
        ans=ans*x%p;
    }
    ll p1=bin(x,po/2);
    ans=ans*p1%p;
    ans=ans*p1%p;
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    ll ao=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        ao=(ao+bin(a[i],p-2))%p;
        for(ll j=2;j<=1000;j++)
        {
            ll count=0;
            while(a[i]%j==0)
            {
                count++;
                a[i]/=j;
            }
            maxi[j]=max(maxi[j],count);
        }
        if(a[i]>1)
        {
            maxi[a[i]]=max(maxi[a[i]],(ll)1);
        }
    }
    ll ans=1;
    for(ll i=2;i<=1000000;i++)
    {
        ans=ans*bin(i,maxi[i])%p;
    }
    cout<<ans*ao%p;
	return 0;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using ll = long long;
const char newl = '\n';
#define var auto

template <typename T>
struct SegmentTree {
  using F = function<T(T, T)>;
  int n;
  F f;
  T ti;

  vector<T> dat;
  SegmentTree() {}
  SegmentTree(F f, T ti) : f(f), ti(ti) {}

  void init(int n_) {
    n = 1;
    while (n < n_) n <<= 1;
    dat.assign(n << 1, ti);
  }

  void build(const vector<T> &v) {
    int n_ = v.size();
    init(n_);
    for (int i = 0; i < n_; i++) dat[n + i] = v[i];
    for (int i = n - 1; i; i--)
      dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
  }

  void set_val(int k, T x) {
    dat[k += n] = x;
    while (k >>= 1)
      dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
  }

  T query(int a, int b) {
    T vl = ti, vr = ti;
    for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = f(vl, dat[l++]);
      if (r & 1) vr = f(dat[--r], vr);
    }

    return f(vl, vr);
  }

  template<typename C>
  int find(int st, C &check, T &acc, int k, int l, int r) {
    if (l + 1 == r) {
      acc = f(acc, dat[k]);
      return check(acc) ? k - n : -1;
    }

    int m = (l + r) >> 1;
    if (m <= st) return find(st, check, acc, (k << 1) | 1, m, r);
    if (st <= l && !check(f(acc, dat[k]))) {
      acc = f(acc, dat[k]);
      return -1;
    }
    int vl = find(st, check, acc, (k << 1) | 0, l, m);
    if (~vl) return vl;
    return find(st, check, acc, (k << 1) | 1, m, r);
  }

  template<typename C>
  int find(int st, C &check) {
    T acc = ti;
    return find(st, check, acc, 1, 0, n);
  }
};

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

  vector< int > xs(n);
  for (auto &i: xs) cin >> i;

  ll ans = accumulate(xs.begin(), xs.end(), 0ll);

  SegmentTree< ll > seg([&](ll a, ll b) { return max(a, b); }, 0);
  seg.init(n + 1);

  for (int i = 0; i < n; ++i) {
    int x = xs[i];
    seg.set_val(x, seg.query(0, x) + x);
  }

  ans -= seg.query(0, n + 1);
  cout << ans << endl;
}



Measured memory_bytes: 5216
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<Int> a(N), b(N + 1, 0);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		b[a[i]] += 1;
	}

	vector<Int> c(N + 1, 0);
	Int sum = 0;
	for (int i = 0; i <= N; ++i) {
		c[i] = b[i] * (b[i] - 1) / 2;
		sum += c[i];
	}

	for (int i = 0; i < N; ++i) {
		Int ans = sum - c[a[i]];
		Int add = (b[a[i]] - 1) * (b[a[i]] - 2) / 2;
		cout << ans + max((Int)0, add) << endl;
	}

	return 0;
}


Measured memory_bytes: 7936
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };
// struct edge{ll to; ll cost;};



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// struct UnionFind {
//     vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
//
//     UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
//         for(int i = 0; i < N; i++) par[i] = i;
//     }
//
//     int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
//         if (par[x] == x) return x;
//         return par[x] = root(par[x]);
//     }
//
//     void unite(int x, int y) { // xとyの木を併合
//         int rx = root(x); //xの根をrx
//         int ry = root(y); //yの根をry
//         if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
//         par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
//     }
//
//     bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };
//
// vint divisor(ll n){ // nの約数
//   vint ret;
//   for(ll i=1;i*i<=n;i++){
//     if(n%i == 0){
//       ret.pb(i);
//       if(i*i!=n) ret.pb(n/i);
//     }
//   }
//   vsort(ret);
//   return ret;
// }
//
ll my_pow(ll x, ll y){
  ll rtn = 1;
  rep(i,y) rtn*=x;
  return rtn;
}

ll get_digits_num(ll n){
  ll ret=0;
  while(n){
    n/=10;
    ret++;
  }
  return ret;
}

ll gcd(ll m, ll n){
  if(m<n) swap(m,n);
  if(n==0) return m;
  return gcd(n, m%n);
}



ll get_digits_in(ll n,ll m, ll max_digits){
  rep(i,max_digits-m){
    n/=10;
  }
  return n%10;
}

int main() {
  cout<<fixed<<setprecision(10);

  ll n,k;cin>>n>>k;

  ll ans = my_pow(n/k,3);
  if(k%2==0){
    ans += my_pow(n/k+(ll)(n%k>=k/2), 3);
  }

  cout << ans << endl;




}

















//


Measured memory_bytes: 256
N,W = map(int,input().split())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
dp = [float('inf')]*(10**5+1)
dp[0] = 0
for i in range(N):
  w = L[i][0]
  v = L[i][1]
  for j in range(10**5,-1,-1):
    dp[j] = min(dp[j-v]+w,dp[j])
ans = 0
for i in range(10**5+1):
  if dp[i] <= W:
    if ans <= i:
      ans = i
print(ans)

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

ll fact(ll n){
    ll ans=1;
    for(int i=1;i<=5;i++){
        ans *= n;
    }

    return ans;
}

int main() {
  ll x;
  cin >> x;
  ll ansa =0;
  ll ansb =0;

  for(ll i=-1000;i<=1000;i++){
      for(ll j=-1000;j<=1000;j++){
          ll a5 = fact(i);
          ll b5 = fact(j);
         if(a5 - b5 ==x){
             ansa =i;
             ansb =j;
             goto loopend;
         }
      }
  }

  loopend:
      cout << ansa << " " << ansb << endl;
      return 0;
}

Measured memory_bytes: 3632
def f(w1):
  m=1e9
  for i1 in range(w1/5+1):
    w2=w1-i1*5
    for i2 in range(w2/3+1):
      w3=w2-i2*3
      if w3%2==0: m=min(m,g([w3/2,i2,i1]))
  return m

def g(x):
  A=[380,550,850]
  B=[.2,.15,.12]
  C=[5,4,3]
  return sum([A[i]*(x[i]-x[i]/C[i]*C[i]*B[i]) for i in [0,1,2]])

while 1:
  w=input()
  if w==0: break
  print int(f(w/100))

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

vector<string> opr{"->", "+", "*", "-"};
vector<string> num{"1", "2", "3", "4"};

bool calc(string exp, int bits) {
    // cout << exp << endl;
    if (exp == "T") return true;
    if (exp == "F") return false;
    if ('a' <= exp[0] && exp[0] <= 'k') return (bits & (1 << (exp[0] - 'a')) ? true : false);
    if (exp[0] == '4') return !calc(string(exp.begin() + 1, exp.end()), bits);

    int idx = -1;
    for (int i = (exp[0] == '(' ? 1 : 0), count = 0, len = exp.size() - (exp[0] == '(' ? 1 : 0); i < len; i++) {
        if (exp[i] == '(') count++;
        else if (exp[i] == ')') count--;
        if (count == 0 && '1' <= exp[i] && exp[i] <= '3') {
            idx = i;
            break;
        }
    }

    if (exp[0] == '(') {
        auto exp1 = string(exp.begin() + 1, exp.begin() + idx);
        auto exp2 = string(exp.begin() + idx + 1, exp.end() - 1);
        if (exp[idx] == '1') return !(calc(exp1, bits) && !calc(exp2, bits));
        if (exp[idx] == '2') return calc(exp1, bits) | calc(exp2, bits);
        if (exp[idx] == '3') return calc(exp1, bits) & calc(exp2, bits);
    }
}

void solve(string str) {
    bool flag = true;
    for (int i = 0, len = opr.size(); i < len; i++) {
        auto idx = str.find(opr[i]);
        while (idx != string::npos) {
            str.replace(idx, (int)opr[i].size(), num[i]);
            idx = str.find(opr[i]);
        }
    }
    int eq_idx = str.find("=");

    string exp1 = string(str.begin(), str.begin() + eq_idx);
    string exp2 = string(str.begin() + eq_idx + 1, str.end());
    for (int i = 0; i < (1 << 11); i++) {
        if (calc(exp1, i) != calc(exp2, i)) {
            flag = false;
            break;
        }
    }

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

int main() {
    string str;
    while (cin >> str, str != "#") solve(str);

    return 0;
}

Measured memory_bytes: 3816
N=int(input())
P=list(map(int, input().split()))
Q=[0]*(N+1)
for i,p in enumerate(P):
    Q[p]=i
A=[i*N+Q[i] for i in range(1,N+1)]
B=[i*N for i in range(N,0,-1)]
print(*A)
print(*B)

Measured memory_bytes: 7196
#include <stdio.h>

int main(void)
{
    long N, i, j, k, cnt, min, sumW[300000+1];
    char S[300000+1];

    scanf("%d%s", &N, S);
    min = 30000000;
    if(S[0]=='W') sumW[0]=1;
    else sumW[0]=0;
    for (i = 1; i < N; i++) {
        if(S[i]=='W') sumW[i]=sumW[i-1]+1;
        else sumW[i]=sumW[i-1];
    }
    for (k = 0; k < N; k++) {
        cnt=0;
        if (k!=0) cnt = cnt + sumW[k-1];
        if (k!=N-1) cnt = cnt + (N-1-k) - (sumW[N-1]-sumW[k]);
        if (min > cnt) min = cnt;
    }
    printf("%d\n", min);
    return 0;
}


Measured memory_bytes: 2816
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node{int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u){
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if(T[u].p == NIL) cout << "root, ";
    else if(T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";

    for(i =  0, c = T[u].l; c != NIL; i++, c = T[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

int rec(int u, int p){
    D[u] = p;
    if(T[u].r != NIL) rec(T[u].r, p);
    if(T[u].l != NIL) rec(T[u].l, p + 1);
}

int main(){
    int i, j, d, v, c, l, r;
    cin >> n;
    for(i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

    for(i = 0; i < n; i++){
        cin >> v >> d;
        for(j = 0; j < d; j++){
            cin >> c;
            if(j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for(i = 0; i < n; i++){
        if(T[i].p == NIL) r = i;
    }

    rec(r, 0);

    for(i = 0; i < n; i++) print(i);

    return 0;
}


Measured memory_bytes: 7692
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int calc(vector<int>v)
{
	int m = v.size() / 2;
	int c1 = 0, c2 = 0;
	for (int i = m - 1; i >= 0; i--)
	{
		if (v[i] == v[i + 1])
		{
			c1 = i + 1;
			break;
		}
	}
	for (int i = m + 1; i < v.size(); i++)
	{
		if (v[i] == v[i - 1])
		{
			c2 = i - 1;
			break;
		}
	}
	if (v[c1] == v[c2])return v[c1];
	if (m - c1 < c2 - m)return v[c1];
	else return v[c2];
}
int main()
{
	int num;
	scanf("%d", &num);
	vector<int>v;
	for (int i = 0; i < num * 2 - 1; i++)
	{
		int z;
		scanf("%d", &z);
		v.push_back(z);
	}
	int beg = 0, end = num * 2 + 1;
	for (;;)
	{
		if (beg == end)break;
		int med = (beg + end + 1) / 2;
		vector<int>z;
		for (int i = 0; i < v.size(); i++)z.push_back(v[i] >= med);
		if (calc(z))beg = med;
		else end = med - 1;
	}
	printf("%d\n", beg);
}

Measured memory_bytes: 2984
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
using namespace std;
int N,i,cnt=1;
bool f;
int main(){
    cin>>N;
    int A[N];
    for(i=0;i<N;i++)cin>>A[i];
    for(i=0;A[i]==A[i+1];i++);
    if(A[i]>A[i+1])f=true;
    for(i++;i<N-1;i++){
        if(f&&A[i]<A[i+1]){
            cnt++;
            for(i++;A[i]==A[i+1];i++);
            f=(A[i]>A[i+1]);
        }
        if(!f&&A[i]>A[i+1]){
            cnt++;
            for(i++;A[i]==A[i+1];i++);
            f=(A[i]>A[i+1]);
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 640
# https://atcoder.jp/contests/agc039/submissions/14648645


INF = 10 ** 8
N = int(input())
S = []
for _ in range(N):
    S.append(list(map(int, list(input()))))

# Is G bipartite ?

color = [0] * N
def dfs(x, c):
    color[x] = c
    for i in range(N):
        # 色が同じ = 二部グラフじゃない
        if S[x][i] == 1 and color[i] == c:
            return False
        # 色はついていないけど，反転した二部グラフ判定に失敗 = 二部グラフじゃない
        if S[x][i] == 1 and color[i] == 0 and not dfs(i, -c):
            return False
    # 二部グラフ
    return True

for i in range(N):
    if color[i] == 0 and not dfs(i, 1):
        print(-1)
        exit()

# ワーシャルフロイド
d = [[INF if S[i][j] == 0 else S[i][j] for i in range(N)] for j in range(N)]
for k in range(N):
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

# 解の計算: 直径(max) + 1
ans = 0
for i in range(N):
    for j in range(N):
        if d[i][j] != INF:
            ans = max(ans, d[i][j] + 1)
print(ans)

Measured memory_bytes: 75056
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//main function
fn main() {
    let x:i64 = read();
    let y:i64 = read();
    println!("{}",x+y/2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  vector<string> w(n);
  set<string> s;
  rep(i, n) cin >> w[i];
  s.insert(w[0]);
  rep(i, n - 1) {
    if (s.count(w[i + 1])) {
      cout << "No" << endl;
      // cout << i << endl;
      return 0;
    }
    s.insert(w[i + 1]);
    if (w[i].back() != w[i + 1].front()) {
      cout << "No" << endl;
      // cout << i << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


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

template<int MOD>
class mod_int {
	unsigned x;
public:
	mod_int() : x(0) { }
	mod_int(int sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	mod_int(long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	mod_int &operator+=(mod_int that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	mod_int &operator-=(mod_int that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	mod_int &operator*=(mod_int that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	mod_int &operator/=(mod_int that) { return *this *= that.inverse(); }

	mod_int operator+(mod_int that) const { return mod_int(*this) += that; }
	mod_int operator-(mod_int that) const { return mod_int(*this) -= that; }
	mod_int operator*(mod_int that) const { return mod_int(*this) *= that; }
	mod_int operator/(mod_int that) const { return mod_int(*this) /= that; }

	bool operator==(const mod_int& that) const { return x == that.x; }

	mod_int inverse() const {
		long long a = x, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		return mod_int(u);
	}
};

template<int MOD>
istream& operator >> (istream& is, mod_int<MOD>& val) {
	long long x;
	is >> x; val = x;
	return is;
}

template<int MOD>
ostream& operator << (ostream& os, const mod_int<MOD>& val) {
	os << val.get();
	return os;
}

const int mod = 1e9 + 7;
using mint = mod_int<mod>;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N), sum(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum[i + 1] = sum[i] ^ A[i];
	}
	if (sum[N] == 0) {
		vector<mint> dp1(1 << 20), dp2(1 << 20);
		vector<int> cnt(1 << 20);
		int tmp = 0;
		mint zero = 1;
		for (int i = 1; i <= N; i++) {
			if (sum[i] == 0) {
				++tmp;
				zero *= 2;
			}
			else {
				int x = sum[i];
				dp2[x] += dp1[x] * (tmp - cnt[x]);
				cnt[x] = tmp;
				dp1[x] += dp2[x] + 1;
			}
		}
		mint res = zero / 2;
		for (int i = 1; i < (1 << 20); i++) {
			res += dp1[i];
		}
		cout << res << endl;
		return 0;
	}
	int val = sum[N];
	mint a = 0, b = 0;
	for (int i = 1; i <= N; i++) {
		if (sum[i] == val) {
			b += a + 1;
		}
		else if (sum[i] == 0) {
			a += b;
		}
	}
	cout << a + 1 << endl;
	return 0;
}


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

const int MAX=200001;

int main()
{
	int n;
	cin>>n;
	int R[MAX];

	for(int i=0;i<n;i++)
		cin>>R[i];

	int minv=R[0];
	int maxv=R[1]-R[0];
	for(int i=1;i<n;i++){
	 maxv=max(maxv,R[i]-minv);
	 minv=min(minv,R[i]);
	
	}
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 3856