akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

#define double long double
constexpr double inf = 1e+10;
constexpr double eps = 1e-10;

template<class T> struct ConvexHullTrick {
  struct Line { T a, b; };
  deque<Line> deq;
  bool monotone_query;
  bool need(const Line& l, const Line& m, const Line& r) const {
    return m.b * (r.a - l.a) > l.b * (r.a - m.a) + r.b * (m.a - l.a);
  }
  ConvexHullTrick(bool monotone_query = false) : monotone_query(monotone_query) {}
  void add(T a, T b) {
    if (deq.empty() or a - deq[0].a < eps) {
      if (!deq.empty() and a - deq[0].a > -eps) return;
      while (deq.size() >= 2 and !need({a, b}, deq[0], deq[1])) {
        deq.pop_front();
      }
      deq.emplace_front(Line{a, b});
    } else if (a - deq.back().a > -eps) {
      if (a - deq.back().a < eps) return;
      while (deq.size() >= 2 and !need(deq[deq.size() - 2], deq.back(), {a, b})) {
        deq.pop_back();
      }
      deq.emplace_back(Line{a, b});
    } else assert(false);
  }
  T max(T x) {
    if(deq.empty()) return -inf;
    if (monotone_query) {
      while (deq.size() >= 2 and deq[0].a * x + deq[0].b <= deq[1].a * x + deq[1].b) {
        deq.pop_front();
      }
      return deq[0].a * x + deq[0].b;
    }
    int ok = 0, ng = deq.size();
    while (ng - ok > 1) {
      int m = ok + ng >> 1;
      (deq[m - 1].a * x + deq[m - 1].b <= deq[m].a * x + deq[m].b ? ok : ng) = m;
    }
    return deq[ok].a * x + deq[ok].b;
  }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  double xz, vz; cin >> xz >> vz;
  V<double> x(n), v(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> v[i];
    x[i] -= xz;
    v[i] -= vz;
  }

  V<double> res(n, inf);
  auto solve = [&]() -> void {
    V<> idx(n);
    iota(begin(idx), end(idx), 0);
    sort(begin(idx), end(idx), [&](int i, int j) { 
      if (abs(v[i] - v[j]) > eps) return v[i] > v[j]; 
      return x[i] - x[j] > eps;
    });
    ConvexHullTrick<double> cht;
    auto itr = begin(idx);
    for (int i : idx) if (x[i] > 0) {
      while (itr != end(idx) and v[*itr] - v[i] > eps) {
        if (x[*itr] < 0) {
          cht.add(v[*itr], x[*itr]);
        }
        ++itr;
      }
      if (v[i] < 0) {
        res[i] = x[i] / -v[i];
      }
      if (cht.deq.empty()) {
        continue;
      }
      auto fn = [&](const auto& l) -> double {
        assert(abs(l.a - v[i]) > eps);
        return (x[i] - l.b) / (l.a - v[i]);
      };
      int ok = 0, ng = cht.deq.size();
      while (ng - ok > 1) {
        int mid = ok + ng >> 1;
        (fn(cht.deq[mid - 1]) > fn(cht.deq[mid]) ? ok : ng) = mid;
      }
      res[i] = min(res[i], fn(cht.deq[ok]));
    }
  };

  solve();
  for (auto&& e : x) e = -e;
  for (auto&& e : v) e = -e;
  solve();

  for (auto e : res) {
    if (e == inf) {
      cout << -1 << '\n';
    } else {
      cout << fixed << setprecision(15) << e << '\n';
    }
  }
}


Measured memory_bytes: 16484
def input_from_console():
    x = int(input())
    return x


def solve(x):
    years = 0
    amount = 100
    rate = 0.01
    while amount < x:
        amount += int(amount * rate)
        years += 1
    return years


def main():
    x = input_from_console()
    print(solve(x))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Measured memory_bytes: 9016
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define int long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1*1e5+5;
 
int32_t main() {
	string s;
	cin >> s;
	
	string x1 , x2;
	x1.pb(s[0]);
	x1.pb(s[1]);
	x2.pb(s[2]);
	x2.pb(s[3]);
	stringstream ss;
	ss << x1;
	int k;
	ss >> k;
	
	bool c1 = false, c2 = false;
	if(k <= 12 && k > 0) c1 = true;
	
	
	stringstream ss2;
	ss2 << x2;
	ss2 >> k;
	
	
	ss >> k;
	
	if(k <= 12 && k > 0) c2 = true;
	
	if(c1 && c2) {
		cout << "AMBIGUOUS" << endl;
		return 0;
	}
	if(c1) {
		cout << "MMYY" << endl;
		return 0;
	}
	if(c2) {
		cout << "YYMM" << endl;
		return 0;
	}
	cout << "NA" << endl;
}


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

int main() {
  int N,K,sum=0;
  cin >> N >> K;
  vector<int> vec(N);
  for(int i=0; i<N; i++) {
    cin >> vec[i];
  }
  for(int i=0; i<N; i++) {
    if(vec[i]<K-vec[i]) {
      sum+=vec[i]*2;
    }
    else {
      sum+=(K-vec[i])*2;
    }
  }
  cout << sum << endl;
}


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

using namespace std;

int dp[1501][1501];

int LCS(string x, string y){
  memset(dp, 0, sizeof(dp));
  if(x[0] == y[0])dp[0][0] = 1;
  for(int i=1;i<x.length();i++){
    dp[i][0] = dp[i-1][0];
    if(x[i] == y[0])dp[i][0] = 1;
  }
  for(int i=1;i<y.length();i++){
    dp[0][i] = dp[0][i-1];
    if(y[i] == x[0])dp[0][i] = 1;
  }
  for(int i=1;i<x.length();i++){
    for(int j=1;j<y.length();j++){
      if(x[i] == y[j])dp[i][j] = dp[i-1][j-1] + 1;
      else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    }
  }
  return dp[x.length()-1][y.length()-1];
}

int main(){
  int q;cin >> q;
  for(int i=0;i<q;i++){
    string x, y;
    cin >> x >> y;
    cout << LCS(x, y) << endl;
  }
}


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

using namespace std;

typedef long long int ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define E(a) cout << #a << ' ' << a << '\n'


const ll M=5e5+5,LG=17,inf=1e18;

int n,m;

ll a[M];

int main()
{
	cin >> n;
	ll s=0;
	For(i,0,n)
	{
		cin >> a[i];
		s+=a[i];
	}
	cout << (s%2?"NO":"YES"); 
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int x, a, b; cin >> x >> a >> b;
	if(abs(x-a) < abs(x-b)) puts("A");
	else puts("B");
}


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

int main(){
  int w,h,x,y,r;
  cin >> w >> h >> x >> y >> r;
  if (x >= r && x <= w-r && y >= r && y <= h-r) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;
using ll=long long;


int main() {
  int n;
  cin >> n;
  vector<int> as(n);
  rep(i,n){cin >> as[i];}
  sort(ALL(as));

  rep(i,n-1){
    if(as[i]==as[i+1]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

typedef long long ll;

const int N=4009;
const int md=924844033;

int n,k;
bool vis[N][N];
int ed[N],tot;
int f[N][N][2];
int g[N],fac[N];

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        for(int j=0;j<=1;j++)
            if(!vis[i][j])
            {
                int len=0;
                for(int x=i,y=j;x<=n;x+=k,y^=1)
                    vis[x][y]=1,++len;
                ed[tot+=len]=1;
            }

    f[1][0][0]=1;
    for(int i=1;i<=tot;i++)
        for(int j=0;j<=n;j++)
        {
            f[i+1][j][0]=(f[i][j][0]+f[i][j][1])%md;
            if(!ed[i])
                f[i+1][j+1][1]=f[i][j][0];
        }

    for(int i=0;i<=n;i++)
        g[i]=(f[tot][i][0]+f[tot][i][1])%md;

    fac[0]=1;
    for(int i=1;i<=n;i++)
        fac[i]=(ll)fac[i-1]*i%md;

    int ans=fac[n];
    for(int i=1,j=-1;i<=n;i++,j=-j)
        ans=((ll)ans+md+(ll)j*fac[n-i]*g[i]%md)%md;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 136704
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> p(n);
    REP(i,n) cin >> p[i];
    int x = 0;
    int y = 0;
    int z = 0;
    REP(i,n) {
        if (p[i] <= a) x++;
        else if(a < p[i] && p[i] <= b) y++;
        else if(b < p[i]) z++;
    }
    int ans = min({x, y, z});
    cout << ans << std::endl;
    
    return 0;
}

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

int main() {

    int h, w;
    cin>>h>>w;
    int a[h][w], dp[h][w];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            char c;
            cin>>c;
            if(c=='.')
                a[i][j] = 1;
            else
                a[i][j] = 0;
        }
    }

    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(i==0 && j==0)
                dp[i][j] = 1 - a[i][j];
            else if(i==0)
            {
                if(a[i][j] == 0 && a[i][j-1] == 0)
                    dp[i][j] = dp[i][j-1];
                else if(a[i][j] == 0 && a[i][j-1] == 1)
                    dp[i][j] = 1 + dp[i][j-1];
                else if(a[i][j] == 1)
                    dp[i][j] = dp[i][j-1];
            }
            else if(j==0)
            {
                if(a[i][j] == 0 && a[i-1][j] == 0)
                    dp[i][j] = dp[i-1][j];
                else if(a[i][j] == 0 && a[i-1][j] == 1)
                    dp[i][j] = 1 + dp[i-1][j];
                else if(a[i][j] == 1)
                    dp[i][j] = dp[i-1][j];
            }
            else
            {
                if(!a[i][j])
                {
                    if(a[i-1][j] == 0 && a[i][j-1] == 0)
                        dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
                    else if(a[i-1][j] == 0 && a[i][j-1] == 1)
                        dp[i][j] = min(dp[i-1][j], 1 + dp[i][j-1]);
                    else if(a[i-1][j] == 1 && a[i][j-1] == 0)
                        dp[i][j] = min(1 + dp[i-1][j], dp[i][j-1]);
                    else
                        dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1]);
                }
                else
                {
                    dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
                }
            }
        }
    }

    cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
	long long int n, a[100010], values[100010] = { 0 }, count = 1, separate = 0;
	std::cin >> n;
	
	for (int i = 0; i < n; ++i)
	{
		std::cin >> a[i];
		if (a[i] % 4 == 0)
		{
			values[count] = a[i];
			count += 2;
		}
	}
	
	if (count >= n)
	{
		std::cout << "Yes";
		return 0;
	}
	
	for (int i = 0; i < n; ++i)
	{
		if (a[i] % 2 == 0 && a[i] % 4 != 0)
		{
			values[count] = a[i];
			++count;
			++separate;
		}
	}
	
	if (count >= n + 1 && separate > 1)
	{
		std::cout << "Yes";
		return 0;
	}
	else
	{
		std::cout << "No";
		return 0;
	}
	
	
}

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

cnt = s.count("R") * s.count("G") * s.count("B")

for i in range(n - 1):
    tmp = s[i]
    for j in range(i + 1, (n + i + 1) // 2):
        if s[2 * j - i] != s[j] and s[j] != tmp and s[2 * j - i] != tmp:
            cnt -= 1
print(cnt)

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    scanf("%d" , &n);
    string s , t;
    cin >> s >> t;

    for(int i = 0 ; i < n ; i ++){
            cout << s[i] << t[i];
    }

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int N;
	cin >> N;

	int T[N];
	int A[N];

	int a,b,c,d;

	bool error = false;
	for (int i = 0; i < N; ++i)
	{
		cin >> T[i];
	}
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	a = A[0];
	b = T[N-1];
	if(a!=b){
		error = true;
	}
	long long result = 1;
	for (int i = 1; i < N-1; ++i)
	{
		a = A[i];
		b = A[i+1];
		c = T[i];
		d = T[i-1];
		if(a==b && c==d){
			if (a<c)
			{
				result = (result*a)%1000000007;
			}else{
				result = (result*c)%1000000007;
			}
		}else{
			if(a>b && a>c){
				error = true;
			}
			if(c>d && c>a){
				error = true;
			}
		}
	}
	// 出力
	if(error){
		cout << 0 << endl;
	}else{
		cout << result << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] W = new int[N];
		int right = 0;
		int left = 0;
		int ans = 2_000_000;
		for (int i=0;i<N;i++) {
			W[i]=sc.nextInt();
			right+=W[i];
		}
		for (int i=0;i<N;i++) {
			ans=Math.min(ans,Math.abs(right-left));
			left+=W[i];
			right-=W[i];
		}
		System.out.println(ans);
	}
}

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

int main(){
    int N; cin >> N;
    string S, T; cin >> S >> T;
    string s = " ";
    rep(i,N){
        s += S[i];
        s += T[i];
    }
    cout << s.substr(1) << endl;
    return 0;
}

Measured memory_bytes: 256
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

ll n;

int main() {
    fast_io; cout_precision;
    cin >> n;
    cout << ((n * (n + 1)) >> 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int N, M, X, Y; cin >> N >> M >> X >> Y;
  vi x(N); rep(i,N) cin >> x.at(i);
  vi y(M); rep(i,M) cin >> y.at(i);
  
  sort(all(x));
  sort(all(y));
  
  int x_max = x.at(N-1);
  int y_min = y.at(0);
  
  bool war = true;
  repi(Z,x_max+1,y_min) {
    if (X<Z && Z<Y) war = false;
  }
  
  cout << (war ? "War" : "No War") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int x, y;
	while (true) {
		scanf("%d %d", &x, &y);
		if (x == 0 && y == 0)break;
		if (x > y) {
			printf("%d %d\n", y, x);
		}
		else {
			printf("%d %d\n", x, y);
		}
	}
	return 0;
}


Measured memory_bytes: 2604
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = getLine >>= putStrLn . solve

solve :: String -> String
solve ss = judge . length $ filter (== 'o') ss
    where
        k = length ss

        judge n
            | 15 - k + n < 8 = "NO"
            | otherwise = "YES"

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 380
import java.util.Scanner;
public class Main{
	public static void main (String[] args){
		int a,b,c;
		Scanner scan = new Scanner(System.in);
		a = Integer.parseInt(scan.next());
		b = Integer.parseInt(scan.next());
		c = Integer.parseInt(scan.next());
		if((a<=b)&&(a<=c)){
			if(b<=c){
				System.out.println(a+" "+b+" "+c);
			}else{
				System.out.println(a+" "+c+" "+b);
			}
		}else if((b<=a)&&(b<=c)){
			if(a<=c){
				System.out.println(b+" "+a+" "+c);
			}else{
				System.out.println(b+" "+c+" "+a);
			}
		}else if((c<=a)&&(c<=b)){
			if(a<=b){
				System.out.println(c+" "+a+" "+b);
			}else{
				System.out.println(c+" "+b+" "+a);
			}
		}
	}
}

Measured memory_bytes: 25864
from collections import defaultdict, Counter

def main():
  H, W, N, *A = map(int,open(0).read().split())
  D = defaultdict(int)

  while A:
    b, a = A.pop(), A.pop()
    for i in [a - 2, a - 1, a]:
      if 1 <= i <= H - 2:
        for j in [b - 2, b - 1, b]:
          if 1 <= j <= W - 2:
            D[(i, j)] += 1

  print((H - 2) * (W - 2) - len(D))

  c = Counter(D.values())
  for i in range(1, 10):
    print(c.get(i, 0))

if __name__ == '__main__':
  main()

Measured memory_bytes: 152976
#include<cstdio>
using namespace std;

int n,r;

int main()
{
	scanf("%d %d",&n,&r);
	if (n<=10)
	{
		printf("%d\n",r+100*(10-n));
	}
	else
	{
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(n + 1);
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    a[t]++;
  }
  ll ans1 = 0, ans2 = 0;
  for (int i = x; i < n; i++) {
    if (a[i] > 0) ans1++;
  }
  for (int i = x; 0 <= i; i--) {
    if (a[i] > 0) ans2++;
  }
  cout << min(ans1, ans2) << endl;
  return 0;
}

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

int main(){
  int n,W,H;

  while(cin >> n ,n){
    cin >> W >> H;

    bool field[H][W];
    memset(field,false,sizeof(field));

    int x,y;
    for(int i = 0 ; i < n ; i++){
      cin >> x >> y;
      x--; y--;
      field[y][x] = true;
    }

    int S,T;
    cin >> S >> T;

    int ans = 0;
    for(int i = 0 ; i <= H-T ; i++){
      for(int j = 0 ; j <= W-S ; j++){
	int cnt = 0;
	for(int k = i ; k < i+T ; k++){
	  for(int l = j ; l < j+S ; l++){
	    if(field[k][l]) cnt++;
	  }
	} 
	ans = max(ans,cnt);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1172
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	char s[100];
	int d[100], l[100], r[100], dmax=0;
	deque<char> sans;
	scanf("%d", &n);
	scanf("%s", s);
	for(int i=n-1; i>=0; i--){
		sans.push_front(s[i]);
		if(i==n-1 && s[i]=='('){
			l[0]=1, r[0]=0;
			d[n-1-i]=l[n-1-i]-r[n-1-i];
			if(dmax<d[n-1-i]){
				dmax=d[n-1-i];
			}
		}else if(i==n-1 && s[i]==')'){
			l[0]=0, r[0]=1;
			d[n-1-i]=l[n-1-i]-r[n-1-i];
			if(dmax<d[n-1-i]){
				dmax=d[n-1-i];
			}
		}else if(s[i]=='('){
			l[n-1-i]=l[n-2-i]+1;
			r[n-1-i]=r[n-2-i];
			d[n-1-i]=l[n-1-i]-r[n-1-i];
			if(dmax<d[n-1-i]){
				dmax=d[n-1-i];
			}
		}else{
			l[n-1-i]=l[n-2-i];
			r[n-1-i]=r[n-2-i]+1;
			d[n-1-i]=l[n-1-i]-r[n-1-i];
			if(dmax<d[n-1-i]){
				dmax=d[n-1-i];
			}
		}
	}

	if(dmax>0){
		for(int i=0; i<dmax ;i++){
			sans.push_back(')');
		}
	}
	for(int i=0; i<dmax-d[n-1]; i++){
		sans.push_front('(');
	}
	for(auto itr=sans.begin(); itr!=sans.end(); itr++){
		printf("%c", *itr);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string ab = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string as = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------
//提出するときC++に帰る
//--------------------------

int main() {

  ll X;
  cin >> X;

  for(ll i=-1000; i<=1000; ++i) {
    for(ll j=-1000; j<=1000; ++j) {
      ll A = i*i*i*i*i;
      ll B = j*j*j*j*j;
      if(A-B==X) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3584
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        while(true) {
        	String s = sc.next();
            if(s.equals("-"))
                break;
        	int m = sc.nextInt();
            int h = 0;
            for(int i = 0; i < m; i++)
        	h += sc.nextInt();
            for(int i = 0; i < s.length(); i++)
                System.out.print(s.charAt((h+i) % s.length()));
                System.out.println();
            h = 0;
        }
    }
}


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

int main() {
	int n; cin >> n; string s; cin >> s;
	int a = 0;
	char b = s.at(0);
	for (char i : s) { if (b != i) a++; b = i; }
	cout << a + 1 << endl;
}

Measured memory_bytes: 512
use std::cmp::*;
use std::collections::*;
use std::io::*;

use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut a: Vec<i64> = (0..n).map(|_| read()).collect();
    let mut bc: Vec<(i64, i64)> = Vec::new();
    for i in 0..m {
        let b: i64 = read();
        let c: i64 = read();
        let t = (c, b);
        bc.push(t);
    }
    bc.sort();
    bc.reverse();
    let mut d: Vec<i64> = vec![0; n];
    let mut _id = 0;
    for _i in 0..bc.len() {
        if _id >= n {
            break;
        } else {
            for _j in 0..bc[_i].1 {
                if _id >= n {
                    break;
                }
                d[_id] = bc[_i].0;
                _id += 1;
            }
        }
    }
    a.sort();
    for _i in 0..n {
        if d[_i] < a[_i] {
            break;
        } else {
            a[_i] = d[_i];
        }
    }
    let mut ans = 0;
    for _i in a {
        ans += _i;
    }
    println!("{}", ans);
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
typedef long long ll;

string xorsum(ll a){
	string asum;
	if(a==-1){
		rep(i,50){
			asum.push_back('0');
		}
	}
	else{
		if (a%4 == 0 || a%4 == 3){asum.push_back('0');}
		else{asum.push_back('1');}

		reps(i,1,50){
			if(a%(ll)pow(2,i+1) < (ll)pow(2,i) || (a%(ll)pow(2,i+1))%2==1){
				asum.push_back('0');
			}
			else{asum.push_back('1');}
		}
	}
	return asum;
}

int main(){
	ll a,b;
	cin >> a >> b;
	string asum,bsum;
	asum = xorsum(a-1);
	bsum = xorsum(b);
	ll ans = 0;
	rep(i,50){
		ans += ((ll(asum[i]-'0')+ll(bsum[i]-'0'))%2)*pow(2,i);
	}
	cout << ans;
}

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

int main(){
  int a[3],i,j,k,n,m,b,c;
  string s;
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  cout << a[2]*10+a[1]+a[0] << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int h,w,k,cnt;
char s[10][10];
bool row[10],col[10];
void dfs(int d)
{
	if(d==h+w)
	{
		int bla=0;
		for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
		bla+=(s[i][j]=='#'&&!row[i]&&!col[j]);
		if(bla==k)cnt++;
		return;
	}
	if(d<h)row[d]=1;
	else col[d-h]=1;
	dfs(d+1);
	if(d<h)row[d]=0;
	else col[d-h]=0;
	dfs(d+1);
}
int main()
{
	scanf("%d%d%d",&h,&w,&k);
	for(int i=0;i<h;i++)scanf("%s",s[i]);
	dfs(0);
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll MOD2=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    int A,B,C,K; cin>>A>>B>>C>>K;

    if(A>=K){
        cout<<K<<endl;
    }else if(A+B>=K){
        cout<<A<<endl;
    }else{
        cout<<A-(K-A-B)<<endl;
    }

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <climits>
using namespace std;
int main(void){
    int A = 0;
    int B = 0;
    int M = 0;
    cin >> A >> B >> M;
    
    int x,y,c;
    int ai[100000];
    int bi[100000];
    int a_low = INT_MAX;
    int b_low = INT_MAX;
    
    int ans = 0;
    
    for(int i = 0;i < A;i++){
        cin >> ai[i];
        if(ai[i] < a_low){
            a_low = ai[i];
        }
    }
    for(int i = 0;i < B;i++){
        cin >> bi[i];
        if(bi[i] < b_low){
            b_low = bi[i];
        }
    }
    
    ans = a_low + b_low;
    int dd = INT_MAX;
    for(int i = 0;i < M;i++){
        cin >> x >> y >> c;
        dd = ai[x - 1] + bi[y - 1] - c;
        if(ans > dd){
            ans = dd;
        }
    }
    
    cout << ans;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, S("ATCG");
    cin >> s;
    int n = s.size();
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (S.find(s[i]) != string::npos) {
            if (i == 0 || S.find(s[i-1]) == string::npos) {
                int j = i;
                while (S.find(s[j]) != string::npos) ++j;
                ans = max(ans, j-i);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2100000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

ll n;
vl a(405);
vl b(405);
vl c(405);
ll dp[405][405];

ll rec(ll l, ll r){
	if(l==r) return dp[l][r] = 0;
	if(dp[l][r] != linf) return dp[l][r];
	//dp[l][r] = min(rec(l+1,r) + b[l] + a[l+1], rec(l,r-1) + a[r-1] + c[r]);
	REP(mid,l,r){
		ll left = l>=1 ? b[l-1] : 0;
		ll right = r<n-1 ? c[r+1] : 0;
		chmin(dp[l][r],rec(l,mid)+rec(mid+1,r)+b[mid]-left+c[mid+1]-right);
	}
	return dp[l][r];
}

int main(){
	cin >> n;
	rep(i,n) cin >> a[i];
	b = a;
	c = a;
	rep(i,n-1) b[i+1] += b[i];
	for(ll i=n-1; i>0; i--) c[i-1] += c[i];
	rep(i,n) rep(j,n) dp[i][j] = linf;
	cout << rec(0,n-1) << endl;
}

Measured memory_bytes: 1536
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int):
    ret = []
    while 0 < abs(N):
        if N % -2  == 0:
            N //= -2
            ret.append('0')
        else:
            N = (N - 1) // -2
            ret.append('1')
    if ret == []:
        ret = ['0']
    return ''.join(reversed(ret))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    result = solve(N)
    print(result)

if __name__ == '__main__':
    main()


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, ans = INF, mn = INF, mx = 0;
  cin >> n;
  vector<ll> x(n);
  rep(i, n) cin >> x[i], mn = min(x[i], mn), mx = max(x[i], mx);

  for (int i = mn; i <= mx; ++i) {
    ll t = 0;
    for (int j = 0; j < n; ++j) {
      t += (x[j] - i) * (x[j] - i);
    }
    ans = min(ans, t);
  }

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


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int n, k;
  while(cin>>n>>k,n||k) {
    int A[k]; FOR(i,0,k) scanf("%d",A+i);
    sort(A, A + k);
    int ans = 0;
    // ?????????????????¨???
    if(A[0] != 0) {
      int cnt = 1;
      FOR(i,0,k-1) {
        if(A[i] == A[i+1] - 1) cnt++;
        else {
          ans = max(ans, cnt);
          cnt = 1;
        }
      }
      ans = max(ans, cnt);
    } else {
      int cnt = 1;
      int st = 1, j = 1;
      bool used = false;
      while(j < k - 1) {
        if(A[j] == A[j+1] - 1) cnt++;
        else if(!used) {
          used = true;
          st = j;
          cnt++;
          if(A[j] == A[j+1] - 2) {
            cnt++;
          }
        } else {
          ans = max(ans, cnt);
          j = st;
          used = false;
          cnt = 1;
        }
        j++;
      }
      ans = max(ans, cnt);
    }
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 3404
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
ll fac[200007],finv[200007],inv[200007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<200007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans+=m*m*(n-i+1)*(n-i)/2;
        ans%=mod;
    }
    for(ll j=1;j<=m;j++){
        ans+=n*n*(m-j+1)*(m-j)/2;
        ans%=mod;
    }
    cout << (ans*com(n*m-2,k-2))%mod<<endl;
    return 0;
}


Measured memory_bytes: 4992
'use strict'

function Main(input) {
  const N = Number(input.split('\n')[0]);
  let list = input.split('\n')[1].split(' ').map(x => Number(x));
  let count = 0;

  for(let i=0; i<N; i++) {
    while(list[i] % 2 === 0) {
      list[i] = list[i] / 2;
      count++;
    }
  }

  console.log(count);

}

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

Measured memory_bytes: 7756
N = int(input())

A = [0] * (N+1)
B = [0] * (N+1)
C = [0] * (N+1)

for i in range(1, N+1):
  a, b, c = map(int, input().split())
  A[i] = max(B[i-1], C[i-1]) + a
  B[i] = max(A[i-1], C[i-1]) + b
  C[i] = max(A[i-1], B[i-1]) + c

print(max(A[N], B[N], C[N]))

Measured memory_bytes: 14836
N = int(input())
if N <= 111:
    print(111)
elif N <= 222:
    print(222)
elif N <= 333:
    print(333)
elif N <= 444:
    print(444)
elif N <= 555:
    print(555)
elif N <= 666:
    print(666)
elif N <= 777:
    print(777)
elif N <= 888:
    print(888)
else:
    print(999)

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

using namespace std;

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)

class UnionFind {
	vector<int> parent;
  void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
public:
	UnionFind() {}
	UnionFind(int n) : parent(n, -1) {}
	void init(int n);
	int root(int a);
	bool unite(int a, int b);
	int size(int a);
	int count();
	bool operator() (int a, int b);
	int operator[] (int i);
};

int n, m;

int main()
{
	cin >> n >> m;
	UnionFind uf(n);

	REP(_i, m)
	{
		int x, y, z;
		cin >> x >> y >> z;
		--x; --y;
		uf.unite(x, y);
	}

	cout << uf.count() << endl;
}

inline void UnionFind::init(int n) { parent.assign(n, -1); }
inline int UnionFind::size(int a) { return -parent[root(a)]; }
inline int UnionFind::count() { int ret = 0; for (int x : parent) if ((1 << 31) & x) ++ret; return ret; }
inline bool UnionFind::operator() (int a, int b) { return unite(a, b); }
inline int UnionFind::operator[](int i) { return root(i); }
inline int UnionFind::root(int a) { return (parent[a] < 0) ? a : parent[a] = root(parent[a]); }
inline bool UnionFind::unite(int a, int b)
{
	int root_a = root(a), root_b = root(b);
	if (root_a == root_b) return false;

	int size_a = -parent[root_a], size_b = -parent[root_b];
	if (size_a < size_b) swap(a, b), swap(size_a, size_b), swap(root_a, root_b);

	parent[root_a] += -size_b;
	parent[root_b] = root_a;
	return true;
}


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

int main(){
    int n,ans=0;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for(int j = 0; j < n-2; j++){
        if ((p[j] < p[j+1] && p[j+1] < p[j+2]) || (p[j] > p[j+1] && p[j+1] > p[j+2]))
            ans++;
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
import copy

params = list(map(int, input().split()))
count = len(params)

minTime = 500

for i in range(count):
  pattern = copy.copy(params)
  total = 0
  pattern.pop(i)
  for j in range(len(pattern)):
      total = params[i]+pattern[j]
      if total <= minTime:
          minTime = total

print(minTime)

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

int main()
{
    long long A, B, K;
    cin >> A >> B >> K;

    long long diff;
    diff = min(K, A);
    A -= diff;
    K -= diff;

    diff = min(K, B);
    B -= diff;
    cout << A << " " << B << endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[]
for i in range(M):
  BC.append(list(map(int,input().split())))
A.sort(reverse=True)
BC.sort(key=lambda x:x[1],reverse=True)
ans=sum(A)
for i in range(M):
  for _ in range(BC[i][0]):
    if A==[]:
      print(ans)
      exit()
    if A[-1]>BC[i][1]:
      print(ans)
      exit()
    else:
      p=A.pop()
      ans-=p
      ans+=BC[i][1]
      
print(ans)

Measured memory_bytes: 32972
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <map>
#include <numeric>
#include <cassert>
#include <iomanip>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr int INF = 1145141919810893;

//
struct Edge {
	int next;
	int w = 1;
};
template<class T>
struct Vertex {
	std::vector<Edge>edges;
	T val = {};
};
template<class T>
struct Graph {
	std::vector<Vertex<T>> vertex;
public:
	Graph(size_t n = 0) :vertex(n) {
	}
	void setArray(int u, int v, int w = 1) {
		vertex[u].edges.push_back(Edge{ v ,w });
	}
	void setConnect(int u, int v, int w = 1) {
		setArray(u, v, w);
		setArray(v, u, w);
	}
	T& val(int u) {
		return vertex[u].val;
	}
	void dfsImpl(int pos, int prev, std::function<void(int now, int next, int w)> func) {
		for (auto& e : vertex[pos].edges) {
			if (e.next == prev) continue;
			func(pos, e.next, e.w);
			dfsImpl(e.next, pos, func);
		}
	}
	void dfs(int pos, std::function<void(int now, int next, int w)> func) {
		dfsImpl(pos, -1, func);
	}
	//graph.dfs(0, [](Vertex<int>& now, Vertex<int>& next, int w) {});
	int radius() {
		if (vertex.size() <= 1)return 0;
		int farestID = -1;
		int far = -1;
		val(0) = 0;
		dfs(0, [&](int now, int next, int w) {
			val(next) = 1 + val(now);
			if (val(next) > far) {
				far = val(next);
				farestID = next;
			}
			});
		far = -1;
		val(farestID) = 0;
		dfs(farestID, [&](int now, int next, int w) {
			val(next) = 1 + val(now);
			if (val(next) > far) {
				far = val(next);
				farestID = next;
			}
			});
		return far;
	}
};




#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOADVEC3(type,name0,name1,name2,N) std::vector<type>name0(N),name1(N),name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn];cin >> name2[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;


void proc();

signed main() {
	ios::sync_with_stdio(false);
	proc();
	return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/


void proc() {
	LOAD(int, N);
	Graph<int> graph(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		graph.setConnect(a - 1, b - 1);
	}
	if (graph.radius() % 3 == 1) {
		cout << "Second" << endl;
	}
	else {
		cout << "First" << endl;
	}
}


#endif



Measured memory_bytes: 39808
n = int(input())
s_li = list(input())
all_li = [[0,0]]
for s in s_li:
    if s == 'W':
        all_li.append([all_li[-1][0]+1,all_li[-1][1]])
    else:
        all_li.append([all_li[-1][0],all_li[-1][1]+1])
#print(all_li)
ans = float('inf')
for i,a in enumerate(all_li):
    if i == 0:
        continue
    tmp_count = 0
    if i-1>0:
        tmp_count += all_li[i-1][0]
    tmp_count += (all_li[-1][1]-a[1])
    if tmp_count < ans:
        ans = tmp_count
    #print(i,a,tmp_count)
print(ans)

Measured memory_bytes: 92604
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, K;
  cin >> N >> K;
  vector<long> data(N);
  for(int i = 0; i < N; i++)cin >> data.at(i);
  sort(data.begin(), data.end());
  long sum = 0;
  for(int i = 0; i < K; i++)sum += data.at(i);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define ll long long
#define M 1000000007
#define all(a) a.begin(), a.end()

int n;
int a[100100];

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) scanf("%d", a + i);
	sort(a, a + n);
	reverse(a, a + n);
	int x = 0, y = 0, cnt = 1;
	for(int i = 1; i <= n; ++i){
		if(i == n || a[i] != a[i - 1]){
			if(cnt >= 4){
				if(!x) x = y = a[i - 1];
				else y = a[i - 1];
				break;
			}else if(cnt >= 2){
				if(!x) x = a[i - 1];
				else { y = a[i - 1]; break; }
			}
			cnt = 1;
		}else{
			cnt++;
		}
	}
	printf("%lld\n", (ll)x * y);
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	for (int i=0;i<4;i++){
		cout<<s[i];
	}
	cout<<" ";
	for (int i=4;i<(int)s.size();i++){
		cout<<s[i];
	}
	cout<<endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int a,b,i,j,m,l,q,r;
	char ch[150][150];
	while(scanf("%d%d",&a,&b)!=EOF)
	{
		getchar();
		for(i=1;i<=a;i++)
		{
		for(j=1;j<=b;j++)
		scanf("%c",&ch[i][j]);
		getchar();
	    }
		for(m=1;m<=b+2;m++)
		printf("#");
		printf("\n");
		for(l=1;l<=a;l++)
		{
			printf("#");
			for(q=1;q<=b;q++)
			printf("%c",ch[l][q]);
			printf("#");
			printf("\n");
		}
		for(r=1;r<=b+2;r++)
		printf("#");
		printf("\n");
}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll f(ll x,ll c,ll d){
    ll res =x;
    res -=x/c;
    res -=x/d;
    res+= x/lcm(c,d);
    return res;
}

int main(){
   ll n;
   cin>>n;
   vector<ll>v(n);
   rep(i,n){
       cin>>v[i];
   }
   sort(v.rbegin(),v.rend());
   ll sum=0;
   ll a=0;
   ll tmp=0;
   rep(i,n-1){
       sum+=v[a];
       if(a==0)a++;
       else{
           tmp++;
       }
       if(tmp==2){
           a++;
           tmp=0;
       }
   }
   cout<<sum<<endl;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> pii;

const int INF = 0x3f3f3f3f;

ll dp[105][100005], w[105], v[105], n, s;


int main() {
    cin >> n >> s;
    for(int i = 1; i <= n; i++)
        cin >> w[i] >> v[i];

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

    for(int i = 1; i <= n; i++) {
        for(int j = s; j >= 0; j--) {
            dp[i][j] = dp[i-1][j];
            if(w[i] <= j) dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]]+v[i]);
        }
    }

    cout << dp[n][s] << endl;
}


Measured memory_bytes: 79360
//aoj0115
public class Main{
  static double eps = 0.0000001;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    double ux, uy, uz, ex, ey, ez;
    double[] x, y, z, s, t;
    double[][] a, ainv;
    int i, j;
    x = new double[3]; y = new double[3]; z = new double[3];
    a = new double[3][3]; ainv = new double[3][3];
    s = new double[3]; t = new double[3];

    ux = sc.nextDouble(); uy = sc.nextDouble(); uz = sc.nextDouble();
    ex = sc.nextDouble(); ey = sc.nextDouble(); ez = sc.nextDouble();
    t[0] = ex - ux; t[1] = ey - uy; t[2] = ez - uz;
    for(i = 0;i < 3;i++){
      x[i] = sc.nextDouble(); y[i] = sc.nextDouble(); z[i] = sc.nextDouble();
      a[0][i] = x[i] - ux; a[1][i] = y[i] - uy; a[2][i] = z[i] - uz;
    }
    getinv(a, ainv, 3);
    for(i = 0;i < 3;i++)for(j = 0;j < 3;j++)s[i] += ainv[i][j] * t[j];
    if(solve(s))out.println("HIT");
    else out.println("MISS");

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
  private static void getinv(double[][] a, double[][] ainv, int n){
    int i, j;
    double[][] x;
    x = new double[n][n * 2];
    for(i = 0;i < n;i++){
      for(j = 0;j < n;j++)x[i][j] = a[i][j];
      x[i][n + i] = 1;
    }
    for(i = 0;i < n;i++){
      for(j = i;j < n;j++)if(x[j][i] != 0)break;
      hswap(x, n, i, j);
      hdiv(x, n, i, x[i][i]);
      for(j = 0;j < n;j++)if(i != j)hdel(x, n, i, j);
    }
    for(i = 0;i < n;i++)for(j = 0;j < n;j++)ainv[i][j] = x[i][j + n];

    return;
  }
  private static void hswap(double[][] x, int n, int i, int j){
    int q;
    double tmp;
    for(q = 0;q < 2 * n;q++){
      tmp = x[i][q]; x[i][q] = x[j][q]; x[j][q] = tmp;
    }
    return;
  }
  private static void hdiv(double[][] x, int n, int i, double a){
    int q;
    for(q = i;q < n * 2;q++)x[i][q] /= a;
    return;
  }
  private static void hdel(double[][] x, int n, int i, int j){
    int q;
    double t = x[j][i];
    for(q = i;q < 2 * n;q++)x[j][q] -= x[i][q] * t;
    return;
  }
  private static boolean solve(double[] s){
    int i;
    for(i = 0;i < 3;i++)if(s[i] + eps < 0)return true;
    if(s[0] + s[1] + s[2] + eps <= 1.0)return true;
    return false;
  }
}

Measured memory_bytes: 28136
import sys
s = input()
t = input()
num0, num1 = len(s), len(t)

if num0 < num1:
    print('UNRESTORABLE')
elif num0 == num1:
    for i, j in zip(s, t):
        if i != j and i != '?':
            print('UNRESTORABLE')
            sys.exit()
    print(t)
else:
    for i in range(num0-num1, 0, -1):
        for j in range(num1):
            if s[i+j] != t[j] and s[i+j] != '?':
                break
            elif j == num1-1:
                ans = s[:i]+t+s[i+num1:]
                ans = ans.replace('?', 'a')
                print(ans)
                sys.exit()
    print('UNRESTORABLE')
        
            


Measured memory_bytes: 9084
N,M,Q = map(int,input().split())
a = []
b = []
c = []
d = []
for i in range(Q):
    ai,bi,ci,di = map(int,input().split())
    a.append(ai-1)
    b.append(bi-1)
    c.append(ci)
    d.append(di)

def score(A):
    tmp = 0
    for j in range(Q):
        if A[b[j]] - A[a[j]] == c[j]:
            tmp += d[j]
    return tmp
    
def dfs(A):
    if len(A) == N:
        return score(A)
    Alast = A[-1] if len(A) > 0 else 1
    res = 0
    for k in range(Alast,M+1):  
        A.append(k)
        res = max(res,dfs(A))
        A.pop()
    return res

print(dfs([]))

Measured memory_bytes: 9276