akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/
struct XY {
  int x, y;
  XY&operator+=(const XY&d) { x += d.x; y += d.y; return *this; }
  XY operator+(const XY&d)const { return XY(*this) += d; }
  bool operator==(const XY&d)const { return x == d.x && y == d.y; }
  bool check(int w, int h)const { return 0 <= x && x < w && 0 <= y && y < h; }
};
const XY d4[] = { { -1,0 }, { 1,0 }, { 0,-1 }, { 0,1 }, };
template<class T> auto get(T& a, XY d)->decltype(a[d.y][d.x]) { return a[d.y][d.x]; }
ostream& operator<<(ostream& os, XY d) { return os << '(' << d.x << ',' << d.y << ')'; }




void Calc() {

  int n, m;
  in, n, m;
  vector<XY> d(n);
  for (auto& i : d) {
    in, i.x, i.y;
  }

  vector<XY> p(m);
  for (auto& i : p) {
    in, i.x, i.y;
  }
  const int INF = 1e9 - 1;

  for (auto& i : d) {
    int mini = INF;
    int ans = 0;
    rep(j, m) {
      auto a = p[j];
      int tmp = abs(a.x - i.x) + abs(a.y - i.y);
      if (mini > tmp) {
        mini = tmp;
        ans = j;
      }
    }
    cout << (ans + 1) << endl;
  }


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 100000000;
using namespace std;

string s[100];
int h, w;

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

void dfs(char c, int y, int x){
    if(y < 0 || x < 0 || y >= h || x >= w) return;
    if(s[y][x] != c) return;
    s[y][x] = '.';

    rep(i,4){
        dfs(c,y + dy[i], x + dx[i]);
    }
}

int main(){
    while(cin >> h >> w, h||w){
        rep(i,h) cin >> s[i];

        int cnt = 0;
        rep(i,h){
            rep(j,w){
                if(s[i][j] != '.'){
                    dfs(s[i][j], i, j);
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3804
cnt = 0


def insertion_sort(a, n, g):
    global cnt
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j = j - g
            cnt += 1
            a[j+g] = v


def shell_sort(a, n):
    g = [1]
    while True:
        tmp = g[-1] * 3 + 1
        if tmp > n:
            break
        else:
            g.append(tmp)
    g.reverse()
    m = len(g)
    print(m)
    print(' '.join(map(lambda x: str(x), g)))
    for i in range(m):
        insertion_sort(a, n, g[i])


def main():
    global cnt
    a = [int(input()) for _ in range(int(input()))]
    shell_sort(a, len(a))
    print(cnt)
    print('\n'.join(map(lambda x: str(x), a)))


if __name__ == '__main__':
    main()



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

int main() {
	string S, T; cin >> S >> T;
	int N = S.size();
	bool flag = false;
	for (int i = 0; i < N; i++) {

		S = S.back() + S.substr(0, N - 1);
		if (S == T) {
			flag = true;
				break;
		}
	}

	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		String result = "APPROVED";
		for(int i = 0; i < n; i++){
		    int a = sc.nextInt();
		    if(a%2 == 0 && (a%3 != 0 && a%5 != 0)) result = "DENIED";
		}
		
		// 計算
		//String result = "Yes";
		
		// 出力
		System.out.println(result);
	}
}


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

int main() {
	string t, p;
	cin >> t >> p;
	regex r("(?=" + p + ").");
	for (auto i = sregex_iterator(t.begin(), t.end(), r), e = sregex_iterator(); i != e; ++i)
		cout << (*i).position() << endl;
}



Measured memory_bytes: 3360
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int memo[100005];

bool check(const string& S, int K){
  rep(i,100005) memo[i] = 0;

  string ret;
  int base = 0;
  rep(i,S.size()){
    int c = (S[i] == '1')?1:0;
    base += memo[i];
    c += base;
    if(c%2==1){
      if(i<S.size()-K+1){
        memo[i] += 1;
        memo[i+K] -= 1;
        base++;
        ret += "0";
      }else{
        ret += "1";
      }
    }else{
      ret += "0";
    }
  }

  int cnt = 0;
  rep(i,S.size()){
    if(ret[i] == '1') break;
    cnt++;
    if(cnt >= K) break;
  }
  return cnt >= K;
}

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

  int lb = 0, ub = S.size()+1;
  while(ub-lb>1){
    int m = (lb+ub)/2;
    if(check(S, m)) lb = m;
    else ub = m;
  }
  cout << lb << endl;
  
  return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 a, b, c; cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <queue>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
using namespace std;

const int MOD = 1000000007;

//abc134_e E - Sequence Decomposing 
//a[i]とa[j] が同じ色なら、a[i] < a[j] を満たす
//用いる色の数を最小にする
// 2 1 4 5 3 -> 145  23 の 2色
// 245 13でもよい
// 後ろから見て、現在の最小の値を保存したほうがよい?


int main(){
    int N;
    cin >> N;
    vector <ll> a(N);
    REP(i,N)
    {
        cin >> a[i];
    }
    vector <int> v;

    v.push_back(a[0]);
    for(int i = 1; i < N; ++i)
    {

        if(v[0] >= a[i])
        {
            auto it = v.begin();
            it = v.insert(it, a[i]);
        }
        else
        {
            //挿入位置を二分探索で見つける
            int p = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
            v[p-1] = a[i];
            

        }

    }
    //for(auto t: v)
    //{
    //    cout << t << endl;
    //}
        
    int res;
    res = v.size();
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 1660
object Main extends App {
  val n = scala.io.StdIn.readLine.toInt
  val w = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  var ans = 999999
  (1 until w.length).foreach { i =>
    val a = w.splitAt(i)

    ans = List(Math.abs(a._1.sum - a._2.sum), ans).min
  }
  println(ans)
}


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

using namespace std;
using ll = long long;
using ld = long double;

ll dp[1500][1500];
ll mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<string> v(n);
    for (string &e : v) {
        cin >> e;
    }
    dp[0][0] = 1;
    for (int i = 1; i < n; i++) {
        dp[i][0] = dp[i - 1][0] * (v[i][0] == '.');
    }
    for (int i = 1; i < m; i++) {
        dp[0][i] = dp[0][i - 1] * (v[0][i] == '.');
    }
    for (int i = 1; i < n; i++) {
        for (int j = 1; j < m; j++) {
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
            dp[i][j] *= (v[i][j] == '.');
        }
    }
    cout << dp[n - 1][m - 1];
}


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

using namespace std;

int main() {
	int cards[4][14];
	int x,n;
	string a;

	for (int l = 0; l < 4; l++) {
		for (int m = 0; m < 14; m++) {
			cards[l][m] = 0;
		}
	}

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a >> x;
		if (a == "S") {
			cards[0][x-1] = 1;
		}
		else if (a == "H") {
			cards[1][x-1] = 1;
		}
		else if (a == "C") {
			cards[2][x-1] = 1;
		}
		else if (a == "D") {
			cards[3][x-1] = 1;
		}
	}

	for (int j = 0; j < 13; j++) {
		if (cards[0][j] == 0) {
			cout << "S" << " " << j+1 << endl;
		}
	}
	for (int o = 0; o < 13; o++) {
		if (cards[1][o] == 0) {
			cout << "H" << " " << o+1 << endl;
		}
	}
	for (int p = 0; p < 13; p++) {
		if (cards[2][p] == 0) {
			cout << "C" << " " << p+1 << endl;
		}
	}
	for (int q = 0; q < 13; q++) {
		if (cards[3][q] == 0) {
			cout << "D" << " " << q+1 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int m;
  cin >> m;
  vl d(m),c(m);
  rep(i,m) cin >> d.at(i) >> c.at(i);
  long num[10] = {-1,10,5,4,3,2,2,2,2,2};
  long to[10] = {-1,1,1,3,3,1,3,5,7,9};
  long ans = 0;
  vl s;
  rep(i,m){
    long x = d.at(i);
    long y = c.at(i);
    if(x == 0){
      ans += y;
    }else{
      while(y){
        long r = y % num[x];
        ans += r-1;
        s.push_back(r*x);
        ans += (y / num[x])*num[x];
        y /= num[x];
        x = to[x];
      }
    }
  }
  long now = s.at(0);
  for(int i=1;i<s.size();i++){
    now += s.at(i);
    ans++;
    if(now >= 10){
      now = now/10 + now%10;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 38372
import java.util.*;

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

      int N=sc.nextInt();
      int A=sc.nextInt();
      int B=sc.nextInt();

      int ans;

      if(N*A>=B){
        ans = B;
      }
      else{
        ans = N*A;
      }

      System.out.println(ans);

    }
}


Measured memory_bytes: 23764
#include <stdio.h>
#define N 100
#define A 0
#define B 1
#define C 2
#define INF 1000000

int G[N][N];
int n;

int prim(int v){

  int sum = 0,mincost,i,j;
  int color[N],cost[N];

  for(i = 0 ; i < n ; i++){
    cost[i] = INF;
    color[i] = A;
  }

  cost[0] = 0;
  color[0] = B;

  while(1){
    int ver = -1;
    mincost = INF;

    for(i = 0 ; i < n ; i++){
      if(color[i] == B && cost[i] < mincost){
        mincost = cost[i];
        ver = i;
      }
    }

    if(ver == -1) break;

    color[ver] = C;

    for(i = 0 ; i < n ; i++){
      if(color[i] != C && G[ver][i] < INF){
        color[i] = B;
        if(cost[i] > G[ver][i]) cost[i] = G[ver][i];
      }
    }

  }

  for(i = 0 ; i < n ; i++){
    sum += cost[i];
  }

  return sum;

}

int main(){
  int i,j,x;
  scanf("%d",&n);

  for(i = 0; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      int cost;
      scanf("%d",&cost);
      if(cost == -1) G[i][j] = INF;
      else G[i][j] = cost;
    }
  }

  x = prim(0);

  printf("%d\n",x);

  return 0;
}



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

int main()
{
    string W,T;
    int count=0;
    cin >> W;
    regex re(W,regex_constants::icase);
    while(1){
        cin >> T;
        if(T == "END_OF_TEXT") break;
        if(regex_match(T,re)) count++;
    }
    
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast_cin() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define int ll

const int MAX = 2e5+5;
const int INF = LLONG_MAX;

int n, c, h[MAX], dp[MAX];
struct Line {
	mutable ll k, m, p;
	bool operator<(const Line& o) const { return k < o.k; }
	bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line, less<>> {
	// (for doubles, use inf = 1/.0, div(a,b) = a/b)
	const ll inf = LLONG_MAX;
	ll div(ll a, ll b) { // floored division
		return a / b - ((a ^ b) < 0 && a % b); }
	bool isect(iterator x, iterator y) {
		if (y == end()) { x->p = inf; return false; }
		if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
		else x->p = div(y->m - x->m, x->k - y->k);
		return x->p >= y->p;
	}
	void add(ll k, ll m) {
        k*= -1, m*=-1;
		auto z = insert({k, m, 0}), y = z++, x = y;
		while (isect(y, z)) z = erase(z);
		if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
		while ((y = x) != begin() && (--x)->p >= y->p)
			isect(x, erase(y));
	}
	ll query(ll x) {
		assert(!empty());
		auto l = *lower_bound(x);
		return -l.k * x - l.m;
	}
};

LineContainer t;
signed main(){
    fast_cin();
    cin>>n>>c;
    for(int i=1;i<=n;i++) cin>>h[i];
    t.add(-2*h[1], h[1]*h[1]);
    for(int i=2;i<=n;i++){
        dp[i] = t.query(h[i]) + h[i]*h[i] + c;
        t.add(-2*h[i], dp[i] + h[i]*h[i]);
    }
    cout<<dp[n]<<"\n";
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
int v[1000];
int main() {
    FILE * fi, * fout;
    int i,n;
    //fi = fopen("A.in" ,"r");
    //fout = fopen("A.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%d" ,&n);
    for(i=1;i<=n;i++)
      fscanf(fi,"%d" ,&v[i]);
    std::sort(v+1,v+n+1);
    fprintf(fout,"%d\n" ,v[n]-v[1]);
    //fclose(fi);
    //fclose(fout);
}


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

int main() {
  int n;
  cin>>n;
  deque<int>b;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(i%2==0)b.push_back(a);
    else b.push_front(a);
  }
  if(n%2==1)reverse(b.begin(),b.end());
  for(int i=0;i<n;i++){
    if(i!=n-1)cout<<b[i]<<" ";
    else cout<<b[i]<<endl;
  }
  return 0;
}


  


Measured memory_bytes: 2944
#include <cstdio>

int main() {
  int N;
  scanf("%d", &N);

  int res=0;
  for (int i=0; i<N; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    res += r - l;
  }

  printf("%d\n", res + N);
  return 0;
}


Measured memory_bytes: 128
/*------------
Name: Mohamed Anas
Program Description: Dp implementation of frog jumping
-----*/
#include<stdio.h>
#define LARGE 1000000000;
int* h;
int* dp;
int N;
int K;
int min(int a,int b){
	if(a<b)return a;
	else return b;
}
int absolute(int a){
	if(a<0)return -a;
	else return a;
}
int min_cost(int n){
	
		for (int i = 1; i<=N; ++i)
		{ for (int j = 1; j<=K; ++j)
		{
			if(i-j>0)dp[i]=min(dp[i],dp[i-j]+absolute(h[i]-h[i-j]));
			//if(j<=N)dp[j]= min(dp[j],dp[i]+absolute(h[i]-h[j]));
		}
		//printf("dp[%d] = %d\n",n,dp[n] );
		}
		return dp[n];
	
}

int main(){
	scanf("%d",&N);
	scanf("%d",&K);
	h = (int*)malloc(sizeof(int)*(N+2));
	dp = (int*)malloc(sizeof(int)*(N+2));
	for (int i = 0; i < N+2; ++i)
	{	dp[i]=LARGE;
		/* code */
	}
	dp[1]=0;
	for (int i = 1; i < N+1;++i)
	{
		scanf("%d",&h[i]);

	}
	h[0]=0;
	//printtall();
	printf("%d",min_cost(N));
}

Measured memory_bytes: 896
/**
 * File              : A.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 10.01.2020
 * Last Modified Date: 10.01.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

#include <bits/stdc++.h>
using namespace std;

int main() {
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
'''
着想：大きいaほど左右の端に移動したい、小さいaを先に端にやるより必ず大きくなるから
問題：単純に貪欲に大きいaから左端(x-1)と右端(N-x)の大きい方に移動すると、
      残りのaの組み合わせ的に最適でない場合がある
      アイテムの左右端の単純な割り振りはO(2^N)
解決策の着想：大きい順のk個を(k=L+R)となる
    　　左L個右R個にどのように割り振っても(k+1)個目の最適な割り振り方は変わらない
解決策：アイテムk個左右に割り振る状態をdp[L][R]で保存O(N^2)
'''

def solve():
  N = int(input())
  A = [[a, i] for a,i in zip(map(int, input().split()), range(N))]
  A.sort(key=lambda a: a[0], reverse=True)

  dp = [[0]*(N+1) for _ in range(N+1)] # 左からxマス右からyマス埋める
  for i in range(0,N):
    a, l = A[i]
    for x in range(0,i+1):
      y = i - x # 合計x+y=iマス既に埋まっている、次にi+1マス目を考える
      dp[x+1][y] = max(dp[x+1][y], dp[x][y] + a * abs(l - x))
      dp[x][y+1] = max(dp[x][y+1], dp[x][y] + a * abs(l - (N-y-1)))

  print(max(dp[N-i][i] for i in range(N+1)))
  
solve()

Measured memory_bytes: 136024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

string S, T;
int main(int argc, char **argv) {
    cin >> S >> T;
    int res = 0;
    for(int i = 0; i < 3; ++i)
        if(S[i] == T[i])
            res++;

    cout << res << endl;
}

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

int main(){
    int A, B;
    int M=-1001001001;
    cin >> A >> B;
    M = max(M, (A+B));
    M = max(M, (A-B));
    M = max(M, (A*B));
    cout << M << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N;
    map<ll, ll> check;

    cin >> N;
    rep(i, N) {
        ll A;
        cin >> A;
        if (check.count(A) == 0) {
            check[A] = 1;
        }
        else {
            check[A]++;
        }
    }

    ll ans = 0;
    for (auto itr = check.begin(); itr != check.end(); itr++) {
        if (itr->second % 2 == 1) {
            ans++;
        }
    }

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

Measured memory_bytes: 6528
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
SS = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
cnt= [7, 6, 5, 4, 3, 2, 1]
c = -1
for n in SS:
  c += 1
  if S == n:
    print(cnt[c])
    exit()
    

Measured memory_bytes: 5200
S = gets.chomp

def WA
  puts 'WA'
  exit
end

s = S.gsub(/A|C/, '')
isAC = S[0] == 'A' && S[2..S.length-2].count('C') == 1 && s == s.downcase()

WA() if !isAC
puts 'AC'

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int n,a,b;
int pa(int x)
{
    int k = 0;
    while(x>0)
    {
        k+=x%10;
        x/=10;
    }
    if(k>=a&&k<=b)return 1;
    else return 0;
}
int main()
{
    cin>>n>>a>>b;
    int sum = 0;
    for(int i=1;i<=n;i++)
    {
        if(pa(i))sum+=i;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main()
{
    long long n,k,a;
    vector<long long>v;
    cin >> n >> k;
    while (n--)
    {
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(),v.end(),greater<long long>());
    long long ans=0;
    for (long long i=0; i<=v.size(); i++)
    {
        if (k==0)
            {
                for (long long j=i;j<v.size();j++)
                {ans+= v[j];}{cout << ans; return 0;}
            }
        else
            k--;
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

#define ALL(V) (V).begin(),(V).end()

using namespace std;

typedef pair<int,int> ii_t;

#define MAX 100010
#define RMAX 1000
char is_prime[MAX];
#define PMAX 100000
int prime[PMAX];

int state[16];
int pure;
int answer=0;
void check(int n,const vector<vector<ii_t> > &vec){
    for (int i=0;i<n;i++) {
        if (!state[i]) continue;

        int a = vec[i].size();
        for (int j=0;j<a;j++) {
            if (state[vec[i][j].first-1] != vec[i][j].second) {
                return;
            }
        }
    }
    answer = max(answer,pure);
}

void dfs(int index, int n, const vector<vector<ii_t> > &vec){
    if (index == n) {
        check(n, vec);
        return;
    }

    state[index] = 1;
    pure++;
    dfs(index+1, n, vec);
    pure--;
    state[index] = 0;
    dfs(index+1, n, vec);
}

int main() {
    int n, a;
    int x, y;
    cin >> n;
    vector<vector<ii_t> > vec(n);
    for (int i=0;i<n;i++){
        cin >> a;
        for (int j=0;j<a;j++){
            cin >> x >> y;
            vec[i].push_back(ii_t(x,y));
        }
    }

    dfs(0, n, vec);

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        long syou = N/(A+B);
        long amari = N%(A+B);
        if(amari<=A){
            System.out.println(A*syou + amari);
        }else{
            System.out.println(A*syou + A);
        }
     }
}




Measured memory_bytes: 35684
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,t,x,y;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t>>x>>y;
		if(x+y>t)
		{
			cout<<"No"<<"\n";
			return 0;
		}
		if((x+y)%2==1 && t%2==0)
		{
			cout<<"No"<<"\n";
			return 0;
		}
		if((x+y)%2==0 && t%2==1)
		{
			cout<<"No"<<"\n";
			return 0;
		}
	}
	cout<<"Yes"<<"\n";
	return 0;
}

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

using namespace std;

const int MAXN = 2 * (200 + 10);

int n, H;
vector<int> adj[MAXN], rev[MAXN], vec;
int in[MAXN], out[MAXN];
bool mark[MAXN];

void dfs(int v)
{
	vec.push_back(v);
	mark[v] = true;
	for (auto i : adj[v])
		if (!mark[i])
			dfs(i);
	return;
}


int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> H;
	for (int i = 0; i < n; i++)
	{
		int a, b, c, d, v = 0, u = 0;
		cin >> a >> b >> c >> d;
		if (c)
			v += H + 1 + c;
		else
			v += a;
		if (d)
			u += d;
		else
			u += b + H + 1;
		adj[v].push_back(u);
		adj[u].push_back(v);
		in[u]++;
		out[v]++;
	}
	for (int i = 0; i < H + 1; i++)
		if (out[i] < in[i])
			return cout << "NO" << endl, 0;
	for (int i = H + 1; i < ((H + 1) << 1); i++)
		if (in[i] < out[i])
			return cout << "NO" << endl, 0;
	for (int i = 0; i < MAXN; i++)
	{
		if (!mark[i] && (in[i] + out[i]))
		{
			dfs(i);
			bool can = false;
			for (auto me : vec)
				if (in[me] != out[me])
					can = true;
			if (!can)
				return cout << "NO" << endl, 0;
			vec.clear();
		}
	}
	cout << "YES" << endl;
	return 0;
}

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

int main()
{
	int N;
	cin >> N;
	for(int n=0; n<N; n++){
		int A;
		cin >> A;
		if(A % 2 ==0 && (A % 3 != 0&&A % 5 != 0)){
			cout << "DENIED";
			return 0;
		}
	}
	cout << "APPROVED";
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n)cin >> h.at(i);
    vector<int> dp(n,INF);
    dp.at(0)=0;
    rep(i,n){
        int cost;
        if(i>0){
            cost = abs(h.at(i)-h.at(i-1));
            dp.at(i)=min(dp.at(i),dp.at(i-1)+cost);
        }
        if(i>1){
            cost = abs(h.at(i)-h.at(i-2));
            dp.at(i)=min(dp.at(i),dp.at(i-2)+cost);
        }    
    }
    cout << dp.at(n-1) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>
#include <queue>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;


// a,bの最小公倍数
ll lcm(ll a, ll b){ll lcm = a * b; ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return lcm /= b;}
// a,bの最大公約数
ll gcd(ll a, ll b){ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return b;}
// MOD
ll modadd(ll a, ll b){return (a%MOD+b%MOD+MOD)%MOD;}
ll modmul(ll a, ll b){return a%MOD*b%MOD%MOD;}
ll modexp(ll a, ll n){if(n==0)return 1; if(n%2==0){ll e=modexp(a,n/2); return modmul(e,e);} return modexp(a,n-1)*a%MOD;}
ll modinv(ll n){return modexp(n%MOD,MOD-2);}
ll modfact(ll n){ll res=1; for (int i=1; i <= n; ++i){res *= i; res %= MOD;} return res;}
ll modncr(ll n, ll r){ll numer=1;ll denom=1;for(int i=1;i<=r;++i){numer=modmul(numer,n-r+i);denom=modmul(denom,i);}return modmul(numer, modinv(denom));}


int main(){

    ll n;
    cin >> n;
    
    int tmp = n;

    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }

    if (tmp % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;




}



//              g++ -std=c++1z


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

const int64_t MOD = 1e9 + 7;
int main()
{
    int N;
    cin >> N;
    int64_t power = 1;
    for (int i = 0; i < N; i++)
    {
        power = (power * ((i + 1) % MOD)) % MOD;
    }
    cout << power % MOD << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(i, e) cerr << #i << ' ' << i << e
void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
#else
#define DE(...) 0
void debug(...) {}
#endif
const int maxn = 300010;
int n, a[maxn], ca[maxn], b[maxn], cb[maxn];
int c[maxn];
int cnt[maxn];
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int i = 0;i < n;++i)
		cin >> a[i], ++ca[a[i]];
	for (int i = 0;i < n;++i)
		cin >> b[i], ++cb[b[i]], c[i] = b[i];
	for (int i = 1;i <= n;++i) if (ca[i] + cb[i] > n)
		return puts("No"), 0;
	cout << "Yes\n";
	vector<int> p, lft;
	for (int i = 0;i < n;++i)
		if (a[i] == b[i])
			p.pb(i), ++cnt[a[i]];
	int mx = *max_element(cnt, cnt+1+n);
	for (int i = 0;i < p.size();++i) {
		int tar = p[ (i+mx) % p.size() ];
		if (a[ p[i] ] == a[ tar ])
			lft.pb(p[i]);
		else 
			c[ p[i] ] = a[ tar ];
	}
	for (int i = 1;i < lft.size();++i)
		assert(a[ lft[i] ] == a[ lft[i-1] ]);
	int num = lft.size()?a[lft[0]] : -1;
	for (int i = 0;i < n;++i) if (c[i] != a[i] && c[i] != num && a[i] != num) {
		if (lft.size()) {
			int p = lft.back();
			lft.pop_back();
			swap(c[p], c[i]);
		}
	}
	assert(lft.empty());
	for (int i = 0;i < n;++i)
		cout << c[i] << " \n"[i+1==n];



	
}



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

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

  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }

  return 0;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
  	cin>>a>>b;
  	vector<int>vec(3);
  	vec[0]=a+b;
  	vec[1]=a-b;
  	vec[2]=a*b;
  	sort(vec.begin(),vec.end());
  	cout<<vec[2]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int n; cin >>n;
  vector<li> s(2,0),c(2,0);
  rep(i,n){
    li a; cin >>a;
    rep(j,2){
      s[j]+=a;
      if((i+j)%2){
        if(s[j]>=0){
          c[j]+=s[j]+1;
          s[j]=-1;
        }
      }else{
        if(s[j]<=0){
          c[j]+=-s[j]+1;
          s[j]=1;
        }
      }
    }
  }
  print(min(c[0],c[1]));
}


Measured memory_bytes: 3632
import math
n,m = map(int, input().split())
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans = 0
if n >= 2:
    ans += comb(n,2)
if m >= 2:
    ans += comb(m,2)
print(ans)

Measured memory_bytes: 3060
n = gets.chomp!.to_i
edges = {}
(n-1).times do
    a, b, c = gets.chomp!.split(" ").map(&:to_i)
    edges[a] ||= {}
    edges[a][b] = c
    edges[b] ||= {}
    edges[b][a] = c
end
q, k = gets.chomp!.split(" ").map(&:to_i)
queries = []
q.times do
    queries << gets.chomp!.split(" ").map(&:to_i)
end

root = k
scores = {}

routes = [[root, 0]]
while routes.empty?.!
    x, w = routes.shift
    scores[x] = w

    edges[x].each do |k, v|
        next if scores[k]

        routes.unshift([k, w + v])
    end
end

queries.each do |from, to|
    puts scores[from] + scores[to]
end


Measured memory_bytes: 66428
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();

int main(){
 int a,b,res=0; cin>>a>>b;
 if(b%a==0)res=a+b;
 else res=b-a;
 
 cout<<res<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Point{
	double x, y;
	public Point(double _x, double _y){
		x = _x;
		y = _y;
	}
	// add , sub
	public Point add(Point p) {
		return new Point(x + p.x, y + p.y);
	}
	public Point sub(Point p) {
		return new Point(x - p.x, y - p.y);
	}
	public double innerdot(Point p) {
		return p.x * x + p.y * y;
	}
	// rotate d degree
	public Point rotate(double d) {
		double theta = d / 180.0 * Math.PI;
		return new Point(Math.cos(theta) * x  - Math.sin(theta) * y, Math.sin(theta) * x + Math.cos(theta) * y);
	}
}
class Line{
	Point p1, p2;
	public Line(Point _p1, Point _p2){
		p1 = _p1;
		p2 = _p2;
	}
	public Line(double x1, double y1, double x2, double y2) {
		p1 = new Point(x1, y1);
		p2 = new Point(x2, y2);
	}
	public Point Projection(Point p){
		Point Between_p1p2 = p2.sub(p1); //x2, y2
		Point Between_p1p = p1.sub(p); //x1, y1
		double k = Between_p1p.innerdot(Between_p1p2) / Between_p1p2.innerdot(Between_p1p2);
		return new Point(p1.x - k * Between_p1p2.x, p1.y - k * Between_p1p2.y);
	}
	public Point Reflection(Point p) {
		Point t = this.Projection(p);
		Point PX = t.sub(p);
		return p.add(new Point(PX.x * 2.0, PX.y * 2.0));
	}
}


public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		Point p1 = new Point(sc.nextDouble(), sc.nextDouble());
		Point p2 = new Point(sc.nextDouble(), sc.nextDouble());
		Point p3 = new Point(- p2.sub(p1).y + p2.x, p2.sub(p1).x + p2.y);
		Point p4 = p3.add(p1.sub(p2));
		System.out.println((int)p3.x+" "+(int)p3.y+" "+(int)p4.x+" "+(int)p4.y);
	}
}


Measured memory_bytes: 23124
module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = words
printer = unlines . (:[]) . show

solver [ns,ss] = leader_cost ss (int ns)
leader_cost ss n 
  | n == 1 = 0
  | n >= 2 = result
  where
    ln = div n 2
    rn = n - ln
    (ls,rs) = splitAt ln ss
    result = min (count 'W' ls + leader_cost rs rn)
                 (count 'E' rs + leader_cost ls ln)
    
count c = length . filter (==c)


Measured memory_bytes: 27004
(let* ((n (read))
       (l (make-array `(,(1+ n))))
       (ans 0))
  (loop :for i :from 1 :to n
        :do (setf (aref l i) (read)))
  (loop :for i :from 1 :to (- n 2)
        :for x := (aref l i)
        :do (loop :for j :from (1+ i) :to (- n 1)
                  :for y := (aref l j)
                  :do (loop :for  k :from (1+ j) :to n
                            :for z := (aref l k)
                            :if (and (/= x y z)
                                     (< (abs (- x y)) z (+ x y)))
                            :do (incf ans))))
  (format t "~A~%" ans))


Measured memory_bytes: 24644
# Your code here!
n=gets.to_i
s=gets.chomp()
ss=s.unpack("C*")
x=0
y=0

for i in 0..n-1

    if ss[i]>70
        #puts("a")
        x=x+1
    else
        #puts("b")
        x=x-1
    end
    
    if y<x
        #puts("c")
        y=x
    end
    
end

puts(y)


Measured memory_bytes: 1916
N,A,B = map(int,input().split())

"""
各桁の和を足し合わせる方法
"""

m = []

for i in range(1,N+1):
    j = str(i)
    l = list(map(int,j))
    total = sum(l)

    if A <= total and total <=B:
        m.append(i)

print(sum(m))


Measured memory_bytes: 3424
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	a := getStdinInt()
	fmt.Printf("%d\n", a+a*a+a*a*a)
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 1812
#include<bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;

int main() {
    int N; cin >> N;
    vector<pint> res;
    int dame = N;
    if(N % 2 == 1) --dame;

    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            if(j <= i || j == dame) continue;
            res.push_back(pint(i, j));
        }
        --dame;
    }

    cout << res.size() << endl;
    for (auto p : res)
    {
        cout << p.first << " " << p.second << endl;
    }

}

Measured memory_bytes: 384
wordlist = raw_input().split()
maxlength = 0
lengthindex = -1
for i in range(0, len(wordlist)):
	length = len(wordlist[i])
	if maxlength < length:
		maxlength = length
		lengthindex = i
longest = wordlist[lengthindex]
wordlist.sort()
max = 0
cnt = 0
tmp = ''
modeword = ''
for i in range(0, len(wordlist)):
	if wordlist[i] != tmp:
		tmp = wordlist[i]
		cnt = 1
	else:
		cnt += 1
		if max < cnt:
			max = cnt
			modeword = tmp
print modeword+' '+longest


Measured memory_bytes: 4656
//AtCoder DP B

//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back

using namespace std;

const ll sz=1e5+5;
const ll szz=1e6+6;
const ll mod=1e9+7;

ll h[sz],dp[sz],n,k;

ll minCost(ll idx)
{
	if(idx==n-1)
		return 0;

	if(dp[idx]!=-1)
		return dp[idx];

	ll mini=1e16;
	for(ll i=1;i<=k;i++)
	{
		if(idx+i<n)
		{
			mini=min(mini, abs(h[idx]-h[idx+i])+minCost(idx+i));
		}
	}

	return dp[idx]=mini;
}

int main()
{
	Ryuga;

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

	clock_t startTime=clock();

	cin>>n>>k;
	memset(dp,-1,sizeof dp);
	rep(i,0,n)
	{
		cin>>h[i];
	}

	cout<<minCost(0);

	cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...

Measured memory_bytes: 11592
n=int(input())
s=input()

dp_w=[0]
dp_e=[0]

for i in range(n):
    if i!=0:
        dp_w.append(dp_w[-1])
        dp_e.append(dp_e[-1])
    if s[i]=="W":
        dp_w[-1]+=1
    else:
        dp_e[-1]+=1

def migi(i):
    if i==n-1:
        return 0
    return dp_e[n-1]-dp_e[i]
def hidari(i):
    if i==0:
        return 0
    return dp_w[i-1]
ans=1000000000000000
for i in range(n):
    right=migi(i)
    left=hidari(i)
    ans=min(right+left,ans)
print(ans)

Measured memory_bytes: 23492
#include <bits/stdc++.h>
#define F(i,n) for (int i=1; i<=(int)n; i++)
#define FF(i,n) for (int i=0; i<(int)n; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pi pair < int , int >
#define re(x) (int)x.size()
#define y1 u228
using namespace std;
typedef long long ll;
const int N = 1010;
const int big = 2e9;
const int md = 1e9 + 7;
int n,w[N],s[N],v[N],p[N],ww[N],ss[N],vv[N],mx;
ll f[N][N*10];
bool cmp(int x,int y){
    //return min(s[x]-w[y],s[y])>min(s[y]-w[x],s[x]);
    return (s[x]+w[x])>(s[y]+w[y]);
}
void up(ll &x,ll y){x=max(x,y);}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    //freopen("input.txt","r",stdin);
    cin>>n;
    F(i,n) cin>>w[i]>>s[i]>>v[i];
    F(i,n) p[i]=i;
    sort(p+1,p+n+1,cmp);
    F(i,n) {ww[i]=w[p[i]];ss[i]=s[p[i]];vv[i]=v[p[i]];}
    F(i,n) {w[i]=ww[i]; s[i]=ss[i]; v[i]=vv[i];}
    F(i,n) mx=max(mx,s[i]);
    up(f[1][s[1]],0ll+v[1]);
    F(i,n-1){
        FF(j,mx+1){
            if (w[i+1]<=j) up(f[i+1][min(j-w[i+1],s[i+1])],f[i][j]+0ll+v[i+1]);
            up(f[i+1][j],f[i][j]);
        }
        up(f[i+1][s[i+1]],0ll+v[i+1]);
    }
    ll ans=0;
    FF(j,mx+1) ans=max(ans,f[n][j]);
    cout<<ans<<endl;
    return 0;
}







Measured memory_bytes: 79104
let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.to_list @@ Array.init n @@ fun _ ->
    Scanf.scanf "%d " @@ fun a -> a in
  let x = List.length (List.filter (fun a -> a mod 2 = 1) as_) in
  let y = List.length (List.filter (fun a -> a mod 4 = 0) as_) in
  print_endline @@
    if x <= y + if n mod 2 = 1 && y = n / 2 then 1 else 0 then "Yes" else "No"


Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  string a,b,c;
    cin >> a >> b >> c;
  cout << a[0] << b[1] << c[2] << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <stack>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
   int n,a[110],sum=0;
   scanf("%d",&n);
   for(int i=0;i<n;i++)
   {
       scanf("%d",&a[i]);
       sum+=a[i];
   }
   int sum1=0,sum2=0;
   sum1=(int)(1.0*sum/n+0.5);
   for(int i=0;i<n;i++)
      sum2+=(a[i]-sum1)*(a[i]-sum1);
   printf("%d",sum2);
    return 0;
}

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

int main()
{
  // 入力
  int n;
  cin >> n;
  
  // 出力
  cout << (180 * (n - 2)) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

  double W;
  double H;
  
  double x;
  double y;
  
  cin >> W >> H >> x >> y;
  
  if(W / x == 2 && H / y == 2){
    cout << W * H / 2 << " " << 1 << endl;
  }
  else{
    cout << W * H / 2 << " " << 0 << endl;
  }
  
}


Measured memory_bytes: 256
x,y=map(int,input().split())
if y==0:
  print(x)
  exit()
p=list(map(int,input().split()))
for i in range(200):
  if not x-i in p:
    print(x-i)
    exit()
  if not x+i in p:
    print(x+i)
    exit()

Measured memory_bytes: 9064
#include<stdio.h> 

int main(void)
{
  int n,m;
  scanf("%d %d",&n,&m);
  if (n > m) {
    for (int i=0; i < n; i++) {
      printf("%d",m);
    }
  } else {
    for (int i=0; i < m; i++) {
      printf("%d",n);
    }
  }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;
void solve()
{
	ll l,r,d;
	cin>>l>>r>>d;
	ll ans=r/d-(l-1)/d;
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1;
	//cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
ll N;
ll a[300000];
int main(){
  cin>>N;
  for(ll i=1;i<=N*N;i++)
    a[i]=-1;
  vector<P>A(N);
  for(ll i=0;i<N;i++){
  ll x;cin>>x;P p(x,i+1);
    A[i]=p;
   }bool judge=true;sort(A.begin(),A.end());
  ll d=1;
  for(ll i=0;i<N;i++){
  ll x=A[i].first;ll n=A[i].second;
    a[x]=n;
    ll sum=1;
    while(sum<n){
    if(a[d]==-1){a[d]=n;sum++;d++;}
      else
        d++;
    if(x<d)judge=false;
    }if(!judge)break;
  }if(!judge)
    cout<<"No"<<endl;
  else{
    ll d1=N*N;
  for(ll i=N-1;0<=i;i--){
  ll x=A[i].first;ll n=A[i].second;
    ll sum=0;
    while(sum<N-n){
    if(a[d1]==-1){a[d1]=n;sum++;d1--;}
      else
        d1--;
    if(d1<x)judge=false;
    }if(!judge)break;
  }if(!judge)
    cout<<"No"<<endl;
    else{
      cout<<"Yes"<<endl;
    for(ll i=1;i<N*N;i++)
      cout<<a[i]<<" ";
    cout<<a[N*N]<<endl;
    }
  
  }
  return 0;
}

Measured memory_bytes: 5592
import java.math.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;

public class Main {


    public static long f(long n){
        if(n==1) return 1;
        return n*f(n-1);
    }

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

        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        System.out.print(Math.max(a-2*b,0));




    }

    
}


Measured memory_bytes: 23252
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
b=[int(input()) for i in range(n)]
result=[[0]*3 for i in range(3)]
for i in range(3):
  for j in range(3):
    for k in range(n):
      if a[i][j]==b[k]:
        result[i][j]=1
for i in range(3):
  cnth=0
  cntw=0
  for j in range(3):
    cnth+=result[i][j]
    cntw+=result[j][i]
  if cnth==3 or cntw==3:
    print('Yes')
    exit()
if result[0][0]==result[1][1]==result[2][2]==1 or result[0][2]==result[1][1]==result[2][0]==1:
  print('Yes')
  exit()
print('No')


Measured memory_bytes: 3064
/* Bismillahirrahmanirrahim */
#include<bits/stdc++.h>
#define forA for(int i=0; i<a; i++)
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(((c>=a)&&(c<=b))||((c<=a)&&(c>=b))) cout << "Yes";
	else cout << "No";
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int ans = 0;
	for (int ii = 1; ii <= N; ++ii){
		int digit = 0;
		int tmp = ii;
		while (tmp > 0) {
			digit++;
			tmp /= 10;
		}
		if (digit % 2 == 1){
			ans++;
		}
	}

	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 1e5+1;
int n, cnt[N], q;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll s = 0;
  cin >> n;
  FOR(i, 0, n){
    int a;
    cin >> a;
    cnt[a]++;
    s += a;
  }
  cin >> q;
  FOR(_, 0, q){
    ll b, c;
    cin >> b >> c;
    s += (c-b)*cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << s << endl;
  }
}

Measured memory_bytes: 3980