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

typedef long long ll;

#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back

const long double PI = acos(-1);

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll GetDigit(ll num) {return log10(num)+1;}

int main(){
  ll n, k;
  cin >> n >> k;
  vector<double> p(n, 0);
  for(ll i = 0; i < n; i++) cin >> p[i];

  double psum = 0;
  for(ll i = 0; i < k; i++){
    psum += ((p[i]*(p[i]+1))/2.0)/p[i];
  }

  double ans = psum;
  for(ll i = k; i < n; i++){
    psum -= ((p[i-k]*(p[i-k]+1))/2.0)/p[i-k];
    psum += ((p[i]*(p[i]+1))/2.0)/p[i];

    ans = max(ans, psum);
  }

  printf("%.16f\n", ans);
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

long long int dp[101][100001];

int main()
{
	fastio;
	int n, w;
	cin >> n >> w;
	vector<pair<int, int> > v(n+1);
	for(int i = 1; i <= n; i++) {
		cin >> v[i].first >> v[i].second;
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= w; j++) {
			if(v[i].first > j) dp[i][j] = dp[i-1][j];
			else dp[i][j] = max(dp[i-1][j], dp[i-1][j-v[i].first] + v[i].second);
		}
	}
//	for(int i = 1; i <= n; i++) {
//		for(int j = 1; j <= w; j++) {
//			cout << dp[i][j] << " ";
//		}
//		cout << endl;
//	}
	cout << dp[n][w] << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

template <typename T>
struct Kruskal {
  struct UnionFind {
    int n;
    vector<int> rank, par;
    UnionFind() {}
    UnionFind(int n) : n(n), rank(n, 1), par(n) {
      iota(par.begin(), par.end(), 0);
    }
    int root(int x) {
      return par[x] == x ? x : par[x] = root(par[x]);
    }
    bool merge(int x, int y) {
      if ((x = root(x)) == (y = root(y))) return false;
      if (rank[x] < rank[y]) swap(x, y);
      rank[x] += rank[y];
      par[y] = x;
      return true;
    }
    bool same(int x, int y) {
      return root(x) == root(y);
    }
    int size(int x) {
      return rank[root(x)];
    }
  };
  struct edge {
    int from, to; T cost;
    edge() {}
    edge(int f, int t, T c) : from(f), to(t), cost(c) {}
    friend ostream& operator<<(ostream& os, edge &e) {
      return os << e.from << " " << e.to << " " << e.cost;
    }
  };

  int n;
  vector<edge> es;
  Kruskal() {}
  Kruskal(int n) : n(n) {}

  void add_edge(int from, int to, T cost) {
    es.emplace_back(from, to, cost);
  }
  T mst() {
    T res = 0;
    UnionFind uf(n);
    sort(es.begin(), es.end(), [&](edge a, edge b) {
      return a.cost < b.cost;
    });
    for (auto &e : es) if (uf.merge(e.from, e.to)) {
      res += e.cost;
    }
    return res;
  }
};

double len(double x, double y, double z) {
  return sqrt(x * x + y * y + z * z);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(3);
  
  int n;
  while (cin >> n, n) {
    vector<double> x(n), y(n), z(n), r(n);
    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i] >> z[i] >> r[i];
    }

    Kruskal<double> K(n);
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (j != i) {
        K.add_edge(i, j, max(0., len(x[i] - x[j], y[i] - y[j], z[i] - z[j]) - r[i] - r[j]));
    }
    cout << K.mst() << endl;
  }

  return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>

int get_number_of_digits(int num)
{
    if(num == 0)
        return 1;
        
    int digit = 0;
    while(num != 0){
        num /= 10;
        ++digit;
    }
    return digit;
}

int main()
{
    const int num_of_data = 200;
    const int min = 0;
    const int max = 1000000;
    
    int a, b, i = 0;
    //std::cout << num_of_data << "個のまでの整数データa bの入力" << std::endl;
    while(std::cin >> a >> b && i < 200){
        if(min <= a && a <= max && min <= b && b <= max){
            std::cout << get_number_of_digits(a + b) << std::endl;
            ++i;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES

typedef long long ll;
const ll MD = 1000000007;

#include <iostream>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;

/* sample input

*/
ll test = 0;
ll inv[100002];
ll fact[100002], ifact[100002];
ll n;
ll a[100002];
bool flug[100002] = {};
ll dup = 0;


ll factorial(ll n){
	ll fac=1;
	for (ll i = n; i >= 1; i--){
		fac *= i;
	}
	return  fac;
}


ll conv(ll n, ll k){

	if (n < k){
		return 0;
	}
	ll ret;
	ret = (((fact[n] * ifact[k]) % MD)*ifact[n - k]) % MD;
	return ret;
}

int main()
{

	cin >> n;

	for (int i = 0; i < n+1; i++){
		cin >> a[i];
		if (flug[a[i]]){
			dup = a[i];
		}
		flug[a[i]] = true;
	}

	//if (test){
	//	cout << dup << endl;

	//	for (int i = 0; i < n + 1; i++){
	//		cout << a[i] << " ";
	//	}
	//	cout << endl;
	//}

	int inc = 0;
	int pos[2];
	for (int i = 0; i < n+1; i++){
		if (a[i] == dup){
			pos[inc] = i;
			inc++;
		}
	}

	//if (test){
	//	cout << pos[0] << " " << pos[1] << endl;
	//}

	int duplen = pos[1] - pos[0]+1;


	//真面目に階乗を計算するパターン。計算時間や桁数的に厳しい
	//for (int i = 1; i <= n + 1;i++){
	//	ll all = factorial(n + 1) / factorial(i) / factorial(n + 1 - i);

	//	if (n + 1 - duplen - (i - 1) >= 0){
	//		ll dupvar = factorial(n + 1 - duplen) / factorial(i - 1) / factorial(n + 1 - duplen - (i - 1));
	//		all = all - dupvar;
	//	}

	//	cout << all;
	//	if (i != n + 1){
	//		cout << endl;
	//	}
	//}

	//n!と(n!)^(-1) mod MDを求める
	//n!のmod MD
	inv[1] = 1;
	fact[0] = 1;
	fact[1] = 1;
	ifact[0] = 1;
	ifact[1] = 1;

	//fact,ifactの作成
	for (int i = 2; i <= n + 1; i++){
		inv[i] = MD - inv[MD%i] * (MD / i) % MD;
		fact[i] = fact[i - 1] * i%MD;
		ifact[i] = ifact[i - 1] * inv[i] % MD;
	}

	for (int i = 1; i <= n + 1; i++){
			ll all = conv(n+1,i);

			if (n + 1 - duplen - (i - 1) >= 0){
				ll dupvar = conv(n+1-duplen,i-1);
				all = all - dupvar;
			}
			if (all < 0){
				all += MD;
			}

			cout << all;
			if (i != n + 1){
				cout << endl;
			}
	}

	return 0;
}

Measured memory_bytes: 4480
def main():
    a, b, c, d = map(int, input().split())
    ans = 0
    if a < d:
        ans += a
        d -= a
    else:
        ans += d
        d = 0
    if b < d:
        d -= b
    else:
        d = 0
    if c < d:
        ans -= a
        d -= c
    else:
        ans -= d
        d = 0
    print(ans)


main()


Measured memory_bytes: 9192
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

int read()
{
	int k = 1;
	int x = 0;
	char c = getchar();
	while (c > '9' || c < '0') 
		if (c == '-') c = getchar(), k = -1;
		else c = getchar();
	while (c >= '0' && c <= '9')
		x = (x << 1) + (x << 3) + (c ^ 48),
		c = getchar();
	return k * x;
}

int n, m;
int ans = -1;

int main()
{
	n = read();
	m = read();
	int ccc = m/n;
	int bbb = sqrt(m);
	ccc = min(ccc, bbb);
	for (int i = 1; i * i <= m; ++i)
	{
		if (m % i == 0) 
		{
			int i1 = i;
			int i2 = m / i;
			if (i1 <= m / n) ans = max(ans, i1); 
			if (i2 <= m / n) ans = max(ans, i2);
		}
	}
	cout << ans;
}

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

int main() {

 int a,b,k; cin>>a>>b>>k;
  int q=0,w=0; 
vector<int> c(b);
  for(int i=0; i<b; i++){
    cin>>c.at(i); if(c.at(i)>k){q++;}
    else{w++;}}
  cout<<min(q,w)<<endl;
}


Measured memory_bytes: 256
# N
# H1 H2 ... Hn

n = gets.chomp.to_i
hs = gets.chomp.split(" ").map(&:to_i)

a = Array.new(n, 0)
c = 0

(0...n).reverse_each do |i|
  a[i] = c

  next if i == 0

  if hs[i - 1] >= hs[i]
    c += 1
  else
    c = 0
  end
end

puts a.max


Measured memory_bytes: 11268
fun main(args: Array<String>) {

    val (a, b) = readLine()!!.split(" ").map(String::toInt)
    if (0 in a..b) {
        println("Zero")
    } else if (a < 0) {
        val count = (a * -1) - (if (b > -1) {
            -1
        } else {
            b
        } * -1) + 1
        if (count and 1 == 1) {
            println("Negative")
        } else {
            println("Positive")
        }
    } else {
        println("Positive")
    }
}





Measured memory_bytes: 37748
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++) h[i] = scan.nextInt();
        int c = 0;
        int out = -1;
        for(int i = 0; i < n - 1; i++){
            if(h[i] >= h[i + 1]) c++;
            else{
                if(c == 0) continue;
                out = Math.max(c, out);
                c = 0;
            }
        }
        out = Math.max(out, c);
        System.out.println(out);
        scan.close();
    }

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

Measured memory_bytes: 59724
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long int ll;
int main(){
	int n,k,k2;
	cin>>n>>k;
	ll sum=0;
	sum+=pow(n/k,3);
	if (k%2==0){
		k2=k/2;
		sum+=pow(n/k2-n/k,3);
	}
	cout<<sum<<endl;
	
	return 0;
}

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

using namespace std;

int main()
{
	string a;
	
while(cin>>a )
{	
	int total=0;
	for(int i=0;i<a.size();i++)
	{
		total+=(a[i]-48);
	}
	if(total==0){break;}
	cout<<total<<endl;
}
	
	return 0;
}


Measured memory_bytes: 3228
#include<iostream>
using namespace std;
int main()
{
	// スペース区切りの整数の入力
    long long int a,b,c,d;
    cin >> a >> b >> c >> d;
    
    long long int i = a*c;
    long long int j = a*d;
    long long int k = b*c;
    long long int l = b*d;
    long long int x = 0;
    long long int y = 0;   
    long long int z = 0;
	x = max(i,j);
	y = max(k,l);    
    z = max(x,y);
 
    // 出力
    cout << z << endl;
    return 0;
}

Measured memory_bytes: 3632
k=int(input())
result = []
def dfs(pos, val):
  result.append(val)

  if pos == 10:
    return
  
  for i in range(-1,2):
    add_num = (val % 10) + i
    if 0 <= add_num <= 9:
      dfs(pos+1, val*10+add_num)

for i in range(1,10):
  dfs(1,i)
result.sort()
print(result[k-1])

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

int main() {
  long long N;
  cin >> N;
  
  vector <long long> p;
  p.reserve(N);
  
  for (int i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    p.push_back(tmp);
  }
  
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (p[i] != i + 1) {
      count++;
    }
  }
  
  string result;
  if (count <= 2) {
    result = "YES";
  } else {
    result = "NO";
  }
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;


int main()
{
	int n, x, t;
	
	scanf("%d%d%d", &n, &x, &t);
	
	int count = n / x;
	if (n % x != 0)	count++;
	
	int cost = count * t;
	printf("%d\n", cost);

	return 0;
}




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

int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  long long wa,wb,ans;
  wa = a-1;
  wb = n-b; 

  if((b-a)%2==0) cout << (b-a)/2 << endl; 
  else if((b-a)==1){
    if((a-1)<=(n-b)) cout << b-1 << endl;
    else cout << n-a << endl;
  }else{
    if(wa>=wb){
        ans=wb+1+(b-a-1)/2;
        cout << ans << endl;
    }else{
        ans=a+(b-a-1)/2;
        cout << ans << endl;
    }
  }
  
}

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

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

# ifdef Local
# define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
# else
# define debug(...) (__VA_ARGS__)
# define cerr if(0)cout
# endif

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
struct edge {
  int x, y, w;
};
struct dsu{
  int n;
  vec<int> p, sz;
  dsu (int n = 0): n(n) {}
  void init (int n) {
    p = sz = vec<int>(n + 1);
    for (int i = 1; i <= n; i++)
      p[i] = i, sz[i] = 1;
  }
  int get (int v) {
    return (p[v] == v ? v : p[v] = get(p[v]));
  }
  void unite (int x, int y) {
    if (sz[x] < sz[y])
      swap (x, y);
    p[y] = x;
    sz[x] += sz[y];
  }
  bool connected() {
    return (sz[get(1)] == n);
  }
};

int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n + m == 0)
      break;

    vec<edge> e;
    for (int i = 1; i <= m; i++) {
      int x, y, w;
      cin >> x >> y >> w;
      e.pb ({x, y, w});
    }
    sort (e.begin(), e.end(), [] (edge i, edge j) {
      return i.w < j.w;
    });

    dsu T(n);
    int ans = MX;
    for (int i = 0; i < m; i++) {
      T.init (n);
      int mx = 0;
      for (int j = i; j < m; j++) {
        int X = T.get (e[j].x);
        int Y = T.get (e[j].y);
        if (X != Y) {
          T.unite (X, Y);
          mx = e[j].w;
        }
      }
      if (T.connected())
        ans = min (ans, mx - e[i].w);
    }
    if (ans == MX)
      ans = -1;
    cout << ans << endl;
  }


  return 0;
}






// Coded by Z..


Measured memory_bytes: 3336
from sys import stdin
from collections import Counter


def get_result(data):
    N = data[0][0]
    A = data[1]
    L = [0 for _ in range(N)]
    R = [0 for _ in range(N)]
    for i in range(N):
        L[i] = i + A[i] + 1
        R[i] = i + 1 - A[i]

    L_cnt = Counter(L)
    R_cnt = Counter(R)
    ans = 0
    all_key = list(set(R_cnt.keys() & L_cnt.keys()))
    for key in all_key:
        ans += L_cnt[key] * R_cnt[key]
    return ans


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Measured memory_bytes: 73156
#include <iostream>
using namespace std;
int main()
{
int k;
cin>>k;
int ans=1;
int n=7%k;//前回値
int r=0;//合計

if(k%2==0 ||k%5==0)
{
cout <<-1;
return 0;
}

if(n==0)
{
cout <<1;
return 0;
}

r=n;
while(1)
{
n=n*10;
n=n%k;
r+=n;r=r%k;
ans++;
if(r==0)break;

}
cout<< ans;
    
}

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

using namespace std;

struct Node {
	int key;
	Node* parent;
	Node* left;
	Node* right;
};

Node* root;
Node* NIL;

int floorfunc(double num) {
	return int(num);
}

int main() {
	Node* tree[300];
	int n, data[300];
	cin >> n;
	for (int i = 1; i <= n; i++) {
		tree[i] = new Node;
		cin >> tree[i]->key;
	}
	tree[1]->parent = NIL;
	tree[1]->left = tree[2];
	tree[1]->right = tree[3];
	for (int i = 2; i <= n; i++) {
		tree[i]->parent = tree[floorfunc(i / 2)];
		if (2 * i <= n) {
			tree[i]->left = tree[2 * i];
		}
		else {
			tree[i]->left = NIL;
		}
		if (2 * i + 1 <= n) {
			tree[i]->right = tree[2 * i + 1];
		}
		else {
			tree[i]->right = NIL;
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << "node " << i << ": ";
		cout << "key = " << tree[i]->key << ", ";
		if (tree[i]->parent != NIL) {
			cout << "parent key = " << tree[i]->parent->key << ", ";
		}
		if (tree[i]->left != NIL) {
			cout << "left key = " << tree[i]->left->key << ", ";
		}
		if (tree[i]->right != NIL) {
			cout << "right key = " << tree[i]->right->key << ", ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int MAX_N = 35;
const int MAX_C = 35;
const int INF = 1e9 + 7;
const int D_INF = (double)1e5;

class C{
  public:
    int now, bef, c;
    double sum;
    C(int _n, int _b, int _c, double _s){ now = _n; bef = _b; c = _c; sum = _s; }
    C(){}
    bool operator > (const C &cc) const { return sum > cc.sum; }
};

int N, M, S, G;
// P(距離, 制限速度), P(INF, INF)で無し
P v[MAX_N][MAX_N];

double dij(){
  priority_queue<C, vector<C>, greater<C> > open;
  open.push( C(S, MAX_N - 1, 1, 0.0) );
  double closed[MAX_N][MAX_N][MAX_C];
  REP(i, MAX_N) REP(j, MAX_N) REP(k, MAX_C) closed[i][j][k] = D_INF;
  while(!open.empty()){
    C tmp = open.top(); open.pop();
    int now = tmp.now, bef = tmp.bef, c = tmp.c;
    double sum = tmp.sum;
    //cout <<"now = " <<now + 1 <<", bef = " <<bef + 1 <<", c = " <<c <<", sum = " <<sum <<endl;
    if(c == 1 && now == G){
      closed[now][bef][c] = min(closed[now][bef][c], sum);
      break;
    }
    //if(closed[now][bef][c] <= sum) continue;
    REP(i, N){
      if(v[now][i].first == INF || i == bef) continue;
      for(int pls = -1; pls <= 1; ++pls){
        int next_c = c + pls;
        if(bef == MAX_N - 1 && pls != 0) continue;
        double next_sum = sum + ((double)(v[now][i].first) / next_c);
        if(next_c > v[now][i].second || next_c <= 0 || closed[i][now][next_c] <= next_sum) continue;
        closed[i][now][next_c] = next_sum;
        open.push( C(i, now, next_c, next_sum) );
      }
    }
  }
  double ret = D_INF;
  REP(i, N) ret = min(ret, closed[G][i][1]);
  return ret;
}

int main() {
  while(cin >>N >>M && N){
    cin >>S >>G;
    --S; --G;
    REP(i, N) REP(j, N) v[i][j] = P(INF, INF);
    REP(i, M){
      int x, y, d, c; cin >>x >>y >>d >>c;
      --x; --y;
      v[x][y] = P(d, c);
      v[y][x] = P(d, c);
    }
    //REP(i, N){
    //  cout <<i <<": ";
    //  REP(j, N) cout <<v[i][j].first <<", " <<v[i][j].second <<endl;
    //  cout <<endl;
    //}
    double ans = dij();
    if(ans == D_INF) cout <<"unreachable" <<endl;
    else printf("%.5lf\n", ans);
  }
  return 0;
}

Measured memory_bytes: 2088
from collections import deque
N=int(input())

mp={}
for _ in range(N-1):
    i,j,w=map(int,input().split())
    if not i in mp:
        mp[i] = []
    if not j in mp:
        mp[j] = []
    mp[i].append((j,w))
    mp[j].append((i,w))


res = [-1 for _ in range(N+1)]
que = deque([])

que.append((1,0))
res[1]=0
while que:
    i, dist = que.popleft()
    for j, dist2 in mp[i]:
        if res[j] == -1:
            bw = (dist + dist2) % 2
            res[j] = bw
            que.append((j,bw))

for i in range(1, N+1):
    print(res[i])


Measured memory_bytes: 44576
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int D, T, S;
    cin >> D >> T >> S;
    if(D <= T * S) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int N;
  cin >> N;
  set<int> A;
  for (int i=0; i<N; i++) {
    int num;
    cin >> num;
    A.insert(num);
  }
  if (A.size()%2!=0) cout << A.size() << endl;
  else cout << A.size()-1 << endl;
  return 0;
}

Measured memory_bytes: 8104
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long ll;

int n,k;
ll ans;

int main(){
    scanf("%d%d",&n,&k);
    ll x=n/k;
    ans=x*x*x;
    if(k&1);
    else{
        if(n%k>=k/2)
            x++;
        ans+=x*x*x;
    }
    printf("%lld",ans);
}


Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int i, cnt = 0;;
		int[] a = new int[M];
		int[] b = new int[M];
		for(i = 0;i < M;i ++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for(i = 1;i <= N;i ++) {
			for(int k = 0;k < M;k ++) {
				if(i == a[k]) cnt++;
				if(i == b[k]) cnt++;
			}
			System.out.println(cnt);
			cnt = 0;
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
int main()
{
	double a,s;
	while(std::cin >> a)
	{
		if(std::cin.eof()) break;
		s=a;
		for(int i=2;i<=10;i++)
		{
			if(i%2) a/=3.0;
			else a*=2.0;
			s+=a;
		}
		printf("%.8f\n",s);
	}
}

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

#define F first
#define S second
#define gcd __gcd
#define nset __builtin_popcount
#define pb push_back
#define btoe(x) x.begin(), x.end()
#define trim_chains(x) (x).resize(unique(btoe(x)) - (x).begin())
#define remove_dups(x) sort(btoe(x)); trim_chains(x);
#define rep(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define nrep(i, a, b) for (int i = int(a); i >= int(b); i--)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define circ_inc(i, n) (i + 1) % int(n)
#define circ_dec(i, n) (i + int(n) - 1) % int(n)
#define round(x) (int)((double)int(x) + 0.5)

void println() { cout << '\n'; }
template <typename Head, typename... Tail>
void println(Head H, Tail... T) {
    cout << " " << H;
    println(T...);
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef map<string, int> msi;
typedef istringstream iss;

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

int main() 
{
    FASTIO;
    ll a, b, n;
    cin >> a >> b >> n;
    if(n >= b) n = b-1;
    cout << (a*n)/b - a*(n/b) << '\n';
    return 0;
}


Measured memory_bytes: 3648
import copy
N=int(input())
T=list(map(int,input().split()))
M=int(input())
PX=[]
for i in range(M):
    PX.append(list(map(int,input().split())))
for i in range(M):
    A=copy.copy(T)
    A[PX[i][0]-1]=PX[i][1]
    print(sum(A))

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

int main(){
  int n;
  while(cin >> n && n){
    int cnt=0,sum;
    for(int i=1;i<1010 && i<n;i++){
      sum=0;
      for(int j=i;j<n;j++){
	sum+=j; 
	if(sum == n){
	  cnt++;break;
	}
      }
    }
    cout << cnt << endl;

  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>

using namespace std; 
using boost::algorithm::join;

int main() {
  int l,n;
  cin>>n>>l;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  sort(s.begin(),s.end());
  string S=join(s,"");
  cout<<S<<'\n';
  return(0);
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
count=0

for i in range(n):
  if(a[i]>=b[i]):
    count=count+b[i]
    continue
  else:
    count=count+a[i]
    b[i]=b[i]-a[i]

    if(a[i+1]>=b[i]):
      count=count+b[i]
      a[i+1]=a[i+1]-b[i]
      continue
    else:
      count=count+a[i+1]
      a[i+1]=0

print(count)

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int n = 0;
  for(int i = 0; i <= A; i++) {
    for(int j = 0; j <= B; j++) {
      for(int k = 0; k <= C; k++) {
        if(X == i * 500 + j * 100 + k * 50) {
          n++;
        }
      }
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll N; cin>>N;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];
  vector<pair<ll,ll>> ord(N);
  rep(i,N) ord[i] = pair<ll,ll>(i, A[i]);
  sort(ord.begin(), ord.end(), [](pair<ll,ll> a, pair<ll,ll> b) {return a.second>b.second;});
  vector<vector<ll>> dp(N+1, vector<ll>(N+1,0)); // total when there's l babies on the left and r on the right

  ll ans = 0;
  rep(l, N) {
    rep(r,N) {
      if (l+r==N) {
        ans = max(ans, dp[l][r]);
        break;
      }
      ll idx = l+r;
      dp[l+1][r] = max(dp[l+1][r], dp[l][r]+ord[idx].second*abs(ord[idx].first-l));
      dp[l][1+r] = max(dp[l][r+1], dp[l][r]+ord[idx].second*abs((N-1-r) - ord[idx].first));
    }
  }
 printf("%lld\n", ans);
  return 0;
}

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

public class Main {
    int n, k, x, y;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        k = sc.nextInt();
        x = sc.nextInt();
        y = sc.nextInt();
        solve();
    }

    void solve() {
        int ans = 0;
        if (n >= k) {
            ans = x * k + y * (n - k);
        } else {
            ans = x * n;
        }
        System.out.println(ans);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


Measured memory_bytes: 20308
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>

using namespace std;

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


string tostr(int i) {
	stringstream ss;
	ss << i;
	return ss.str();
}

int toint(string s) {
	stringstream ss(s);
	int i;
	ss >> i;
	return i;
}


signed main() {

	string s;
	cin >> s;
	int c = s[2] - '0';
	vector<int> a(c + 1);
	a[c] = 1;

	rep(i, s.size()) {
		if (s[i] == '+' || s[i] == '-') {
			int j;
			for (j = i; j < s.size() && s[j] != 'x'; j++);
			int k = 0;
			if (s[j] == 'x') {
				if (s[j + 1] == '^') {
					k = s[j + 2] - '0';
				}
				else {
					k = 1;
				}
				j--;
			}
			string t;
			if (j - i == 0) {
				t = "1";
			}
			else {
				t = s.substr(i + 1, j - i);
			}

			int m = toint(t);
			if (s[i] == '-') m *= -1;
			a[k] = m;
		}
	}

	vector<int> ans;

	for (int x = -2 * 1000; x <= 2 * 1000; x++) {
		int sum = 0;
		rep(i, a.size()) {
			a[i];
			//i
			int px = 1;
			for (int j = 0; j < i; j++) {
				px *= x;
			}
			sum += a[i] * px;
		}
		if (sum == 0) {
			ans.push_back(-x);
		}
	}

	string l = "(x";
	string r = ")";

	reverse(ans.begin(), ans.end());

	rep(i, ans.size()) {
		cout << l;
		if (ans[i] > 0) {
			cout << "+";
		}
		cout << ans[i];
		cout << r;
	}
	cout << endl;



}

Measured memory_bytes: 3144
#include<stdio.h>
void swap(int *,int *);
int gcd(int,int);
int main(){
  int x,y;
  int i;
  scanf("%d%d",&x,&y);


  printf("%d\n",gcd(x,y));
  return 0;
}
int gcd(int x,int y){
  int r = 1;
  if(x<y){
    swap(&x,&y);
  }
    while(r != 0){
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

void swap(int *x,int *y){
  int r;
  r = *x;
  *x = *y;
  *y = r;
}



Measured memory_bytes: 2048
use strict;
use warnings;

# N の入力受付
chomp(my $n = <>);

# 文字列S の入力受付
my @s;
for (my $i = 0; $i < $n; $i++){
  chomp($s[$i] = <>);
}

# 文字列の並べ替え
@s = sort @s;

my $max = 1;
my @scount;
$scount[0]=1;
# 最大値をカウント
for (my $i = 1; $i < $n; $i++) {
  if ($s[$i-1] eq $s[$i]){
    $scount[$i] = $scount[$i-1] + 1;
    if ($max < $scount[$i]) {$max = $scount[$i];}
  } else {
    $scount[$i] = 1;
  }
}

# 最大の文字出力
for (my $i = 0; $i < $n; $i++) {
  if($max == $scount[$i]) {
    print "$s[$i]\n";
  }
}

Measured memory_bytes: 38652
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,sum=0;
    cin>>N;
    vector<int> weight(N,0);
    for(int i=0;i<N;i++){
        cin>>weight[i];
        sum+=weight[i];
    }

    int min=abs(sum-2*weight[0]);

    for(int i=0;i<N;i++){
        int S_1=0,S_2=0; //初期化
        for(int j=0;j<i;j++){
            S_1+=weight[j];
        }
        S_2=sum-S_1;
        if(min>abs(S_1-S_2)) {
            min = abs(S_1 - S_2);
        }
    }
    cout<<min<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
** Partition
*/

# include <cstdio>
# include <iostream>
using namespace std;

const int maxn = 100000 + 10;
int s[maxn];

int partition(int *a, int p, int r) {
    int x = *(a + r);
    int i = p - 1;
    for (int j = p; j <= r - 1; j++) {
        if (*(a+j) <= x) {
            ++i;
            swap(*(a + i), *(a + j));
        }
    }
    swap(*(a + (++i)), *(a + r));
    return i;
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &s[i]);
    }
    int p = partition(s, 0, n - 1);
    for (int i = 0; i < p; i++) {
        printf("%d ", s[i]);
    }
    printf("[%d]", s[p]);
    for (int i = p + 1; i < n; i++) {
        printf(" %d", s[i]);
    }
    printf("\n");
    return 0;
}


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

using namespace std;

struct Edge {
	int to, cap, rev;
};

vector< vector<Edge> > G;
bool used[2000];

void addEdge(int from, int to, int cap) {
	G[from].push_back({to, cap, G[to].size()});
	G[to].push_back({from, 0, G[from].size()-1});
}

int dfs(int v, int t, int f) {
	if (v == t) return f;
	used[v] = true;

	for (int i = 0; i < G[v].size(); ++i) {
		Edge& e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

#define INF 1e9

int max_flow(int s, int t) {
	int flow = 0;
	while (1) {
		memset(used, false, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0) break;
		flow += f;
	}
	return flow;
}

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}

int main() {
	int M, N;
	while (cin >> M >> N, M || N) {
		G.clear(); G.resize(N+M+2);

		vector<int> a(M);
		for (int i = 0; i < M; ++i) {
			cin >> a[i];
		}
		vector<int> b(N);
		for (int i = 0; i < N; ++i) {
			cin >> b[i];
		}
		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < N; ++j) {
				if (gcd(a[i], b[j]) > 1) {
					addEdge(i, M+j, 1);
				}
			}
		}
		for (int i = 0; i < M; ++i) {
			addEdge(M+N, i, 1);
		}
		for (int i = 0; i < N; ++i) {
			addEdge(M+i, M+N+1, 1);
		}
		cout << max_flow(N+M, N+M+1) << endl;
	}
}

Measured memory_bytes: 5492
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		int[][] a = new int[3][3];
		int[] b = new int[10];
		boolean[][] match = new boolean[3][3];
		int n;
		boolean result = false;
		Scanner sc = new Scanner(System.in);

		for (int i = 0; i < 3; i++) {

			String arg1 = sc.nextLine();
			String[] column = arg1.split(" ");
			int[] ia = new int[column.length];

			for (int j = 0; j < column.length; j++) {
				ia[j] = Integer.parseInt(column[j]);
				a[i][j] = ia[j];
			}
		}

		n = sc.nextInt();

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

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {

				match[i][j] = false;

				for (int k = 0; k < b.length; k++) {
					if (a[i][j] == b[k]) {
						match[i][j] = true;
					}
				}

			}
		}

		for (int i = 0; i < 3; i++) {
			if (match[i][0] && match[i][1] && match[i][2]) {
				result = true;
			}
		}

		for (int i = 0; i < 3; i++) {
			if (match[0][i] && match[1][i] && match[2][i]) {
				result = true;
			}
		}

		if (match[0][0] && match[1][1] && match[2][2]) {
			result = true;
		}

		if (match[0][2] && match[1][1] && match[2][0]) {
			result = true;
		}

		System.out.println(result ? "Yes" : "No");

		sc.close();

	}
}

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

int main(){
int N,M,C;
  cin>>N>>M>>C;
  vector<int>B(M);
  for(int i=0; i<M; i++){
   cin>>B[i]; }
  
  int A[N][M];
  for(int i=0; i<N; i++){
   for(int j=0; j<M; j++){
    cin>>A[i][j]; }}
  
  int ans=0;
  for(int i=0; i<N; i++){
    int sum=0;
   for(int j=0; j<M; j++){
    sum+=A[i][j]*B[j]; }
    if(sum+C>0){ans++;}
  } 
    
  cout<<ans<<endl;
}

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

inline bool distance(int x,int y, int d){
    return (x*x + y*y)<=(d*d);
}

signed main(){
    int n,p;
    cin>>n>>p;
    int size = n;
    int count = 0;
    while(n--){
        int x, y;
        cin>>x>>y;
        if(distance(x,y,p)){
            ++count;
        }
    }
    cout<<count;
}

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

int main(void){
    int n;
    scanf("%d",&n);
    int t[n],a[n];
    for (int i=0; i<n; i++){
        scanf("%d%d",&t[i],&a[i]);
    }
    long long tt=t[0],aa=a[0],tmpt1,tmpa1,tmpt2,tmpa2;
    for (int i=1; i<n; i++){
        tmpt1=tt;
        while (tmpt1%t[i]!=0){
            tmpt1++;
        }
        tmpa1=tmpt1/t[i]*a[i];
        tmpa2=aa;
        while (tmpa2%a[i]!=0){
            tmpa2++;
        }
        tmpt2=tmpa2/a[i]*t[i];
        if(tmpa1<aa){
            tt=tmpt2;
            aa=tmpa2;
        } else if(tmpt2<tt){
            tt=tmpt1;
            aa=tmpa1;
        } else if (tmpt1+tmpa1<tmpt2+tmpa2){
            tt=tmpt1;
            aa=tmpa1;
        } else {
            tt=tmpt2;
            aa=tmpa2;
        }
    }
    printf ("%lld\n",tt+aa);
	return 0 ;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>

using namespace std;  //このネームスペースを使う

int main(){
  int A,B,X;
  cin >> X >> A >> B ;
  
  if(A*X < B){
    cout << A*X << endl;
  }
  else{
    cout << B << endl; 
  }
  
  return 0;
}



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

int main(){
    int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;
    
    if
    (b - a <= k && 
    c - a <= k &&
    d - a <= k &&
    e - a <= k &&
    
    c - b <= k &&
    d - b <= k &&
    e - b <= k &&
    
    d - c <= k &&
    e - c <= k &&
    
    e - d <= k ){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int gcd(int a,int b){
  if(a<b){
    int tmp=a;
    a=b;
    b=tmp;
  }
  while(b){
    int temp=a%b;
    a=b;
    b=temp;
  }
  return a;
}


signed main(){
  int a,b;
  while(cin>>a>>b){
    cout<<gcd(a,b)<<' '<<a*b/gcd(a,b)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3076
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstring>

using namespace std;

const int MOD = (int)1e9 + 7;
const int N = 1000 + 5;

int n;
int cnt[N];

void solve()
{
    long long ans = 1;
    cin >> n;
    for(int i = 1; i <= n; ++ i) {
        int tn = i;
        for(int i = 2; i * i <= tn; ++ i) {
            if (tn % i == 0) {
                while(tn % i == 0) {
                    cnt[i] ++;
                    tn /= i;
                }
            }
        }
        if (tn > 1) {
            cnt[tn] ++;
        }
    }
    for(int i = 2; i < N; ++ i) {
        ans = ans * (cnt[i] + 1) % MOD;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 764
#include <iostream>
#include <cmath>
#include <sstream>
#include <string>

#if defined SUBLIME
#  define ISTREAM ss
#else
#  define ISTREAM cin
#endif


using namespace std;
int main()
{
	#if defined SUBLIME
		string str = "5 5 -100000000 -100000000 -100000000 100000000 100000000 -100000000 100000000 100000000 0 0 0 0 100000000 100000000 100000000 -100000000 -100000000 100000000 -100000000 -100000000";
		stringstream ss;
		ss << str;
	#endif
	int n, m;
	int a[50][2], c[50][2];
	ISTREAM >> n >> m;
	for(int i = 0; i < n; i++){
		ISTREAM >> a[i][0] >> a[i][1];
	}
	for(int i = 0; i < m; i++){
		ISTREAM >> c[i][0] >> c[i][1];
	}
	for(int i = 0; i < n; i++){
		int min = 999999999;
		int p = 0;
		for(int j = 0; j < m; j++){
			int d = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]);
			if(d<min){
				p = j+1;
				min = d;
			}
		}
		cout << p << endl;
	}
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	L := make([]int, n+1)
	for i := 1; i < n+1; i++ {
		fmt.Scan(&L[i])
	}
	bounds := 1
	var di, di1 int
	di1 = 0
	for i := 2; i <= n+1; i++ {
		di = di1 + L[i-1]
		if di <= x {
			bounds++
		}
		di1 = di
	}
	fmt.Println(bounds)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int ec[300010],wc[300010];
int main(){
	int n;cin>>n;
	string s;cin>>s;
	for(int i=0;i<n;i++){
			ec[i+1]=ec[i];
			wc[i+1]=wc[i];
		if(s[i]=='W'){
			wc[i+1]++;
		}else{
			ec[i+1]++;
		}
	}
	int ans=INF;
	for(int i=1;i<=n;i++){
		ans=min(ans,wc[i-1]+ec[n]-ec[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3076
import sys
input = sys.stdin.readline
N,M = map(int,input().split())

x = [0] * N
y = [0] * N
z = [0] * N

for i in range(N):
    x[i],y[i],z[i] = map(int,input().split())

m = 0

#print(x,y,z)

for k in range(8):
    kk = k
    k1 = kk % 2
    kk //= 2
    k2 = kk % 2
    kk //= 2
    k3 = kk % 2

    s = [0] * N
    
    for i in range(N):
        s[i] = ((-1)**k1) * x[i] + ((-1)**k2) * y[i] + ((-1)**k3) * z[i]

    s.sort(reverse = True)
    #print(s)
    total = sum(s[:M]) 
    #print(total)
    m = max(total,m)

print(m)

Measured memory_bytes: 39792
#include<stdio.h>

int main()
{
	char str[1000];
	int i=0;
	
	fgets(str,sizeof(str),stdin);
	
	while(str[i+4]!='\n')
	{
		if(str[i]=='a')
		{
			if(str[i+1]=='p')
			{
				if(str[i+2]=='p')
				{
					if(str[i+3]=='l')
					{
						if(str[i+4]=='e')
						{
							str[i]='p';
							str[i+1]='e';
							str[i+2]='a';
							str[i+3]='c';
							str[i+4]='h';
						}
					}
				}
			}
		}
		else if(str[i]=='p')
		{
			if(str[i+1]=='e')
			{
				if(str[i+2]=='a')
				{
					if(str[i+3]=='c')
					{
						if(str[i+4]=='h')
						{
							str[i]='a';
							str[i+1]='p';
							str[i+2]='p';
							str[i+3]='l';
							str[i+4]='e';
						}
					}
				}
			}
		}
		i++;
	}

	printf("%s",str);
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main{
    private static void solve(int N, int H, int[] attack, int[] throwk){
        int count = 0;
        int sum = 0;
        Arrays.sort(attack);
        int maxa = attack[N - 1];
        Arrays.sort(throwk);
        for(int i = N - 1; throwk[i] > maxa && i > 0; i --){
            sum += throwk[i];
            count ++;
            if(sum >= H){
                System.out.print(count);            
                return;                
            }
        }
        if(throwk[0] > maxa){
            sum += throwk[0];
            count ++;
        }
        if(sum >= H){
            System.out.print(count);            
            return;                
        }
        count = (int)(count + Math.ceil((double)(H - sum) /maxa));
        System.out.print(count);            
        return;    
    }
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int H = input.nextInt();
        int[] attack = new int[N];
        int[] throwk = new int[N];
        for(int i = 0; i < N; i ++){
            attack[i] = input.nextInt();
            throwk[i] = input.nextInt();
        }
        input.close();
        solve(N, H, attack, throwk);
    }
}

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

int main() {
  int H, W;
  
  cin >> H >> W;

  string m = "";
  for (int i = 0; i < H; i++) {
    string s;

    cin >> s;

    m += s;
  }

  for (int i = 0; i < H * W; i++) {
    if (m.at(i) == '#') {
      cout << '#';
    } else if (m.at(i) == '.')  {
      int count = 0;
      int x = i % W;
      int y = i / W;

      if (x - 1 >= 0 && y - 1 >= 0 && m.at(x - 1 + (y - 1) * W) == '#') {
        count++;
      }
      if (y - 1 >= 0 && m.at(x + (y - 1) * W) == '#') {
        count++;
      }
      if (x + 1 < W && y - 1 >= 0 && m.at(x + 1 + (y - 1) * W) == '#') {
        count++;
      }
      if (x - 1 >= 0 && m.at(x - 1 + y * W) == '#') {
        count++;
      }
      if (x + 1 < W && m.at(x + 1 + y * W) == '#') {
        count++;
      }
      if (x - 1 >= 0 && y + 1 < H && m.at(x - 1 + (y + 1) * W) == '#') {
        count++;
      }
      if (y + 1 < H && m.at(x + (y + 1) * W) == '#') {
        count++;
      }
      if (x + 1 < W && y + 1 < H && m.at(x + 1 + (y + 1) * W) == '#') {
        count++;
      }

      cout << count;
    }

    if ((i + 1) % W == 0) {
      cout << endl;
    }
  }
}


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

#define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define i64 long long

using namespace std;

string n;
int d;
i64 b = 1, s, ans;
vector<i64> f(2019);

int main() {_
  cin >> n;
  reverse(n.begin(), n.end());
  f[s]++;
  for(char c : n) {
  	d = c - '0';
    s = (s + d*b)%2019;
    b = 10*b % 2019;
    ans += f[s];
    ++f[s];
  }
  cout << ans << endl;                        
}

Measured memory_bytes: 3392
//AOJ Small, Large, or Equal
//20180929
//F_Naru

#include<iostream>
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a==b) cout << "a == b" << endl;
  if(a >b) cout << "a > b" << endl;
  if(a <b) cout << "a < b" << endl;
}



Measured memory_bytes: 3104
#include <iostream>
#include <queue>
#include <vector>
#define INF 1000000000000

using namespace std;
using llong = long long;
using P = pair<llong,int>;

vector<P> graph[100000];
llong dist[100000];

int main(){
  int n,m,r;

  cin >> n >> m >> r;
  for(int i=0;i<m;++i){
    int s,t,d;
    cin >> s >> t >> d;
    graph[s].emplace_back(d,t);
  }

  priority_queue<P,vector<P>,greater<P>> q;

  for(int i=0;i<n;++i) dist[i] = INF;

  q.push(P(0,r));

  while(!q.empty()){
    auto p = q.top();q.pop();
    int v = p.second;
    llong w = p.first;
    if(dist[v]!=INF) continue;
    dist[v] = w;
    for(auto &next_p:graph[v]){
      int next_v = next_p.second;
      if(dist[next_v]!=INF) continue;
      q.push(P(w+next_p.first,next_v));
    }
  }

  for(int i=0;i<n;++i){
    if(dist[i]!=INF){
      cout << dist[i] << endl;
    }else{
      cout << "INF" << endl;
    }
  }

}

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

using LL = long long;
using LD = long double;
 
LL mod = 10e9+7;

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

	if (s[2]==s[3] && s[4] == s[5]) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	

}

Measured memory_bytes: 256