akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

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

    unsigned int a[n];
    for(int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    
    int max = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++) 
        {
            if(i == j) continue;
            int df = abs(a[i] - a[j]);
            if(df > max) max = df;
        }
    }

    printf("%d\n", max);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	int N,i,j,k;
	cin>>N;
	if (N<3){
		cout<<0<<endl;
		return 0;
	}
	vector<LL> L(N);
	for (i=0;i<N;i++){
		cin>>L[i];
	}
	int ans=0;
	for (i=0;i<N-2;i++){
		for (j=i+1;j<N-1;j++){
			if (L[i]==L[j]){
				continue;
			}
			for (k=j+1;k<N;k++){
				if (L[i]==L[k] || L[j]==L[k]){
					continue;
				}				
				if (L[i]+L[j]>L[k] && L[i]+L[k]>L[j] && L[j]+L[k]>L[i]){
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int n;
char s[55][25];
ll c[55];

bool ispal(char *s, int l, int r) {
	while (l < r) {
		if (s[l] != s[r]) return 0;
		l ++, r --;
	}
	return 1;
}

ll mem[55][25][55][25];

ll calc(int i, int ui, int j, int uj) {
	if (~mem[i][ui][j][uj]) return mem[i][ui][j][uj];
	ll &ans = mem[i][ui][j][uj] = 1e18;
	if (ui == strlen(s[i]) && uj == strlen(s[j])) return ans = 0;
	if (ui == strlen(s[i])) {
		if (ispal(s[j], 0, strlen(s[j]) - uj - 1)) return ans = 0;
		rep(k, n) ans = min(ans, calc(k, 0, j, uj) + c[k]);
		return ans;
	}
	if (uj == strlen(s[j])) {
		if (ispal(s[i], ui, strlen(s[i]) - 1)) return ans = 0;
		rep(k, n) ans = min(ans, calc(i, ui, k, 0) + c[k]);
		return ans;
	}
	if (s[i][ui] == s[j][strlen(s[j]) - uj - 1])
		return ans = calc(i, ui + 1, j, uj + 1);
	return ans;
}

int main() {
	scanf("%d", &n);
	rep(i, n) scanf("%s %lld", s[i], &c[i]);
	ll ans = 1e18;
	rep(i, n) if (ispal(s[i], 0, strlen(s[i]) - 1)) ans = min(ans, c[i]);
	memset(mem, -1, sizeof(mem));
	rep(i, n) rep(j, n) ans = min(ans, calc(i, 0, j, 0) + c[i] + c[j]);
	if (ans >= 1e18) puts("-1");
	else printf("%lld\n", ans);
	return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ull ans=0,a=0;
  vector<ull> v; 
  cin >>n;
  rep(i,n) {
    ull u;
    cin >>u;
    v.push_back(u);
  }
  
  rep(i,v.size()-2){
    rep2(j,i+1,v.size()-1){
      rep2(k,j+1,v.size()){
        if(v[i]==v[j]||v[i]==v[k]||v[k]==v[j])continue;
        ull m,s;
        m=max(max(v[i],v[j]),v[k]);
        s=v[i]+v[j]+v[k];
        //cout <<s;
        if(s-m>m)ans++;
        a++;
      }
    }
  }
  cout <<ans;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    int cnt = 0;
    int max_cnt = 0;
    cin >> n;
    vector<int>h(n);
    vector<int>d(n-1);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    for (int i = 1; i < n; i++)
    {
        d[i-1] = h[i] - h[i-1];
    }
    for (int i = 0; i < (n-1); i++)
    {
        if(d[i] <= 0) {
            cnt++;
            if(cnt > max_cnt){
                max_cnt = cnt;
            }
        }else if (cnt > max_cnt){
            max_cnt = cnt;
            cnt = 0;
        }else {
            cnt = 0;
        }
    }
    cout << max_cnt << endl;
    
   return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,d;
    float x,m,a;
    cin>>n;
    vector<float> v;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    x=(v[0]+v[1])/2;
    m=x;
    for(int i=2;i<n;i++)
    {
       m=(m+v[i])/2;
    }
    cout<<m;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

#define DBG 0

int N=50;
int K=250;
int A[50][50];

int cnt;

int q(int y1,int x1,int y2,int x2){
    if((y2-y1)*(x2-x1)==0)return 0;

    if(DBG){
        int res=0;
        for(int y=y1;y<y2;y++)for(int x=x1;x<x2;x++)res+=A[y][x];
        return res;
    }

    else{
        cout<<"? "<<y1<<" "<<x1<<" "<<y2-1<<" "<<x2-1<<endl;
        int p;cin>>p;
        return p;
    }
}


vector<int>lis[2555];
int dfs(int y1,int x1,int y2,int x2,int p){
    if(y1==y2)return 0;
    if(x1==x2)return 0;

    if((y2-y1)*(x2-x1)==p){
        for(int y=y1;y<y2;y++)for(int x=x1;x<x2;x++)A[y][x]=1;
        return 0;
    }

    if(p==0)return 0;
    int y3=(y1+y2)/2;
    int x3=(x1+x2)/2;

    int pl=q(y1,x1,y2,x3);
    int pu=q(y1,x1,y3,x2);

    int p11,p12,p21,p22;

    int cnt=2;

    if(pl==0){
        p11=p21=0;
        p12=pu;
        p22=p-pu;
    }
    else if(pl==p){
        p12=p22=0;
        p11=pu;
        p21=p-pu;
    }
    else if(pu==0){
        p11=p12=0;
        p21=pl;
        p22=p-pl;
    }
    else if(pu==p){
        p21=p22=0;
        p11=pl;
        p12=p-pl;
    }
    else{
        p11=q(y1,x1,y3,x3);
        p12=pu-p11;
        p21=pl-p11;
        p22=p-p11-p12-p21;
        cnt++;
    }

    cnt+=dfs(y1,x1,y3,x3,p11);
    cnt+=dfs(y1,x3,y3,x2,p12);
    cnt+=dfs(y3,x1,y2,x3,p21);
    cnt+=dfs(y3,x3,y2,x2,p22);

    lis[(y2-y1)*(x2-x1)].pb(cnt);
    return cnt;
}
const int B=8;

signed main(){
    if(DBG){
        vector<pint>v;
        rep(i,N)rep(j,N)v.pb({i,j});
        srand((unsigned)time(NULL));
        random_shuffle(all(v));

        for(int i=0;i<K;i++){
            A[v[i].fi][v[i].se]=1;
        }
        int sum=0;
        for(int i=0;i<N/B;i++){
            for(int j=0;j<N/B;j++){
                int y=(i+1)*B;
                int x=(j+1)*B;
                if(i+1==N/B)y=N;
                if(j+1==N/B)x=N;
                int p=q(i*B,j*B,y,x);
                sum++;
                sum+=dfs(i*B,j*B,y,x,p);
            }
        }
        int cnt=0;
        rep(i,N)rep(j,N)cnt+=A[i][j];
        cout<<cnt<<endl;
        cout<<sum<<endl;

        cout<<dfs(0,0,N,N,K)<<endl;
    }

    else{
        int tmp;
        cin>>tmp;cin>>tmp;cin>>tmp;
        int mod;cin>>mod;

        for(int i=0;i<(N+B-1)/B;i++){
            for(int j=0;j<(N+B-1)/B;j++){
                int p=q(i*B,j*B,min(N,(i+1)*B),min(N,(j+1)*B));
                dfs(i*B,j*B,min(N,(i+1)*B),min(N,(j+1)*B),p);
            }
        }

        int p=1;
        int res=0;
        rep(i,N)rep(j,N){
            res=(res+p*A[i][j])%mod;
            p=p*2%mod;
        }

        cout<<"! "<<res<<endl;
    }
    return 0;
}


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

typedef long long int64;

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) > (b) ? (b) : (a))
#define INT_MAX 0x7fffffff


int main(void) {
    int64 n, w;
    scanf("%lld %lld", &n, &w);

    int64 *arr[2] = {
        malloc(sizeof(int64) * n),
        malloc(sizeof(int64) * n),
    };
    
    int s = 0;
    for(int64 i = 0; i < n; i++) {
        scanf("%lld %lld", &arr[0][i], &arr[1][i]);
        s += arr[1][i];
    }

    int64 *dp = malloc(sizeof(int64) * (s + 1));
    dp[0] = 0;
    for(int i = 1; i < s + 1; i++) 
        dp[i] = INT_MAX;

    for(int64 i = 0; i < n; i++) {
        int64 wi = arr[0][i];
        int64 ci = arr[1][i];

        for(int64 curr_v = s - ci; curr_v >= 0; curr_v--)
            dp[curr_v + ci] = min(dp[curr_v + ci], dp[curr_v] + wi);
    }

    int result = 0;
    for(int i = 0; i <= s; i++)
        if(dp[i] <= w)
            result = i;

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

    free(dp);
    free(arr[0]);
    free(arr[1]);
    return 0;
}



Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  string n;
  cin>>n;
  int k;
  cin>>k;
  int len = n.size();
  vector<vector<vecll>> dp(2, vector<vecll>(k+1, vecll(len+1)));
  dp[0][0][0] = 1;
  for(auto&& i:irange(0,len)) {
    int dgt = n[i] - '0';
    for(auto&& j:irange(0,k)) {
      for(auto&& a:irange(1,10)) {
        if (a < dgt) {
          dp[1][j+1][i+1] += dp[0][j][i];
        } else if (a == dgt) {
          dp[0][j+1][i+1] += dp[0][j][i];
        }
        dp[1][j+1][i+1] += dp[1][j][i];
      }
    }
    for(auto&& j:irange(0,k+1)) {
      if (dgt == 0) {
        dp[0][j][i+1] += dp[0][j][i];
      } else {
        dp[1][j][i+1] += dp[0][j][i];
      }
      dp[1][j][i+1] += dp[1][j][i];
    }
  }
  cout<<dp[0][k][len] + dp[1][k][len]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=1e9+7;
#define ll long long

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long H, N, total = 0ll; cin >> H >> N;
    vector<int> A(N);
    rep (i, 0, N) {
        cin >> A[i];
        total += A[i];
    }

    if (total >= H) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
{-#LANGUAGE FlexibleContexts#-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V

getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]

type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)

mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
ti = toInteger
fi = fromInteger
fig = fromIntegral
rf = realToFrac

(.<.) :: Integer -> Integer -> Integer
(.<.) f g -- combination
    | g < 1 || f < 1 || f < g = 1
    | True = foldr1 (*) (take (fi g) [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)

unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)

mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a

countIf f = length . filter f

enumDivisor :: Int -> [Int]
enumDivisor n = do
    let sqrted = floor $ sqrt (fromIntegral n)
        smaller = filter (\x -> mod n x == 0) [1..sqrted]
        bigger = reverse $ map (div n) smaller
    if head bigger == sqrted then smaller ++ (init bigger)
    else smaller ++ bigger

safeHead [] = Nothing
safeHead (x:_) = Just x

-- 
--
--

main = do
    op . words <$> getLine >>= putStrLn . show
    where
        op [a, "+", b] = foldr1 (+) $ map (read :: String -> Int) [a,b]
        op [a, "-", b] = foldr1 (-) $ map (read :: String -> Int) [a,b]


Measured memory_bytes: 508
#include<stdio.h>
int main(){
	int H,W;
	int i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 && W==0){
			return 0;
		}
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if(i==0 || i==H-1 || j==0 || j==W-1) {
					printf("#");
				}
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<stdio.h>
int main(){
    int n,x,c;
    while(true){
        c = 0;
        scanf("%d %d",&n,&x);
        if(n == 0 && x == 0) break;
        for(int i=1;i<n;i++){
            for(int j=i+1;j<n;j++){
                for(int k = j+1 ; k <= n; k++){
                    if(i+j+k == x) c++;
                }
            }
        }
        printf("%d\n",c);
    }    
}


Measured memory_bytes: 2732
def subset_sum(n, s, a):
	dp = [[0 for x in range(s+1)] for x in range(n+1)]
	dp[0][0]=1
	for i in range(n):
		v = a[i]
		for j in range(s+1):
			if v > j:
				dp[i+1][j] = dp[i][j]
			else:
				dp[i+1][j] = dp[i][j]+dp[i][j-v]
	return dp[n][s] > 0

n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
for i in range(q):
	if subset_sum(n, m[i], a) == True:
		print('yes')
	else:
		print('no')
 


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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int edges = (n * (n - 1) / 2) - (n - 1);
    int x = edges - k;
    if (x < 0) {
        cout << -1 << endl;
        return 0;
    }

    vector<vector<int>> ret;
    for (int j = 2; j <= n; j++)ret.push_back({1, j});
    for (int i = 2; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (x > 0) ret.push_back({i, j});
            x--;
        }
    }

    cout << ret.size() << endl;
    for (auto x:ret)cout << x[0] << " " << x[1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	double a,b,x;

	scanf("%lf %lf %lf",&a,&b,&x);

	double theta1 = atan(2*(a*a*b-x)/(a*a*a));

	if(a*tan(theta1) <= b){

		printf("%.10lf\n",theta1*(180/M_PI));
		return 0;
	}

	double theta2 = atan((a*b*b)/(2*x));

	printf("%.10lf\n",theta2*(180/M_PI));

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b;
    cin >> a >> b;
    if (a+b >=10)
    {
      cout << "error" << endl;
    }
    else
    {
      cout << a+b << endl;
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    --a[i];
  }

  vector<int> cnt(n, 0);
  rep(i, n) ++cnt[a[i]];

  ll sum_comb = 0;
  rep(i, n) {
    sum_comb += (ll)cnt[i] * (cnt[i] - 1) / 2;
  }

  vector<ll> comb_i(n);
  rep(i, n) comb_i[i] = sum_comb - cnt[a[i]] + 1;
  rep(i, n) cout << comb_i[i] << endl;
  return 0;
}

Measured memory_bytes: 6400
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int Ccnt = 0,isLarge = 0;
	char s[13];
	bool f1 = false,f2 = false,f3 = false;

	scanf("%s",s);
	if(s[0] == 'A')	f1 = true;
	for (int i = 2; i <= strlen(s) - 2; ++i)
	{
		if(s[i] == 'C')	++Ccnt;
	}
	if(Ccnt == 1)	f2 = true;
	for (int i = 0; i < strlen(s); ++i)
	{
		if(s[i] < 'a')	++isLarge;
	}
	if(isLarge <= 2)	f3 = true;
	if(f1 && f2 && f3)	puts("AC");
	else puts("WA");
	return 0;
}


Measured memory_bytes: 128
def main():
    from builtins import int,str,map,list,dict,float,print,len,sorted,max,min
    from itertools import accumulate, permutations, combinations
    from collections import deque, defaultdict, Counter
    from operator import itemgetter
    from bisect import bisect_left, bisect_right, bisect
    from heapq import heappop, heappush
    from fractions import gcd
    import sys, re, math, copy

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))
    sys.setrecursionlimit(10 ** 6)  # 再帰上限を10＊＊6に

    D = input_number()
    ans = 'Christmas'
    r = 25 - D
    for i in range(r):
        ans+=' Eve'
    print(ans)

def resolve():
    main()

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 5036
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

cnt = []
for h in H:
    a = T-(h*0.006)
    c = abs(A-a)
    cnt.append(c)
    
ans = cnt.index(min(cnt))+1
print(ans)

Measured memory_bytes: 9216
import java.util.Scanner;

public class Main {

	void main() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < a.length ; i++) {
			a[i] = sc.nextInt();
		}
		System.out.print("" +a[n-1]);
		
		for(int i = a.length - 2; i >= 0 ; i--) {
			System.out.print(" " +a[i]);
		}
        System.out.println();
	}
	public static void main(String[] args) {
		new Main().main();
	}

}


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

#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n, m, p;
  bitset<101234> problemas;
  ll erros[101234];
  mset(erros, 0);
  string s;
  cin >> n >> m;

  ll acertos, penalidades;
  acertos = penalidades = 0;

  while (m--) {
    cin >> p >> s;
    if ((s == "AC") && (!problemas[p])) {
      penalidades += erros[p];
      problemas[p] = 1;
      acertos++;
    }
    else if ((s == "WA") && (!problemas[p]))
      erros[p]++;
  }
  cout << acertos <<  ' ' << penalidades << ende;
  return 0;
}


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

using namespace std;

int main(void) {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int count = 0;
  while (A > 0 && C > 0) {
    if (count % 2 != 0) {
      A = A - D;
    } else {
      C = C - B;
    }
    count++;
  }

  if (A > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  ll a, b, x;
  cin >> a >> b >> x;
  ll anum;
  if(a == 0) anum = 0;
  else anum = (a - 1) / x + 1;
  ll bnum = b / x + 1;
  cout << bnum - anum << endl;
}

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

struct UnionFind{
  vector<int> r;
  
  UnionFind(int n){
    r=vector<int>(n,-1);
  }
  
  int root(int x){
    return (r[x]<0? x:r[x]=root(r[x]));
  }
  
  void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y) return;
    if(r[x]>r[y]) swap(x,y);
    r[x]+=r[y];
    r[y]=x;
    return;
  }
  
  int size(int x){
    return -r[root(x)];
  }
};

int main(void){
  int n,m;cin>>n>>m;
  UnionFind UF(n);
  while(m--){
    int a,b;cin>>a>>b;
    UF.unite(a-1,b-1);
  }
  
  int ans=0;
  while(n--) ans=max(ans,UF.size(n));
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4024
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e19;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
string dir[8] = { "R","L","D","U","RD","RU","LD","LU" };
bool flag[201010];
ll ans[201010];

vector<vector<ll>>to;

void dfs(ll v) {
	flag[v] = true;
	for (auto nv : to[v]) {
		if (flag[nv] == false) {
			ans[nv] += ans[v];
			dfs(nv);
		}
	}
}

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	vector<ll>a(2), b(2);
	rep(i, 2) {
		cin >> a[i];
	}
	rep(i, 2) {
		cin >> b[i];
	}
	ll ans = -1 * INF;
	rep(i, 2) {
		rep(j, 2) {
			ans = max(ans, a[i] * b[j]);
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  int x;
  cin >> x;
  int ans=1;
  
  for (int b=1;b<=x;b++){
    int power=b*b;//1の1乗が最小値
    for (int p=2;p<10;p++){
      if (power>x) break;
      ans=max(ans,power);
      power*=b;
    }
  }
  cout << ans << endl;
}
      

Measured memory_bytes: 256
#include<stdio.h>
int main(){

  int x,y,n,r;

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

  if(y>x){
    n=y;
    y=x;
    x=n; 
  }

    while(1){
      r=y;
      y=x%y;
      if(y==0)break;
      x=r;
    }

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

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

void solve(ll a,ll b){
    ll g = gcd(a,b);
    ll l = a/g*b;
    cout << g <<  " " << l << endl;
}

int main(){
    ll a,b;
    while(cin>>a>>b){
        solve(a,b);
    }
}

Measured memory_bytes: 3040
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
        sc.nextLine();
		String S= sc.nextLine();      
        if(S.length()<=K){
          System.out.println(S);
        }else {
          String Sf=S.substring(0,K);
          System.out.println(Sf+"...");  
        }
	}
  
      
}

Measured memory_bytes: 38620
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)

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

using namespace std;
using ull=unsigned long long;

const int N_MAX = 3*100000;
const int MOD = 1e9+7;

ull fact_memo[N_MAX];

ull power(ull a, ull b) {
	if (b == 0) return 1;
	ull half = power(a, b/2);
	ull ret = (half*half)%MOD;

	if(b&1) ret = (ret*a)%MOD;
	return ret;
}

ull inv(ull n) {
	return power(n, MOD-2)%MOD;
}

ull calc(ull w, ull h) {
	ull res = fact_memo[(w-1)+(h-1)];
	res = (res*inv(fact_memo[w-1]))%MOD;
	res = (res*inv(fact_memo[h-1]))%MOD;
	// cerr << w << " " << h << " " << res << endl;
	// cerr << fact_memo[(w-1)+(h-1)] << " " << fact_memo[w-1] << " " << fact_memo[h-1] << endl;
	return res;
}


int main(void){
	int H, W, A, B; cin >> H >> W >> A >> B;

	fact_memo[0] = 1;
	rep(i, 1, N_MAX) {
		fact_memo[i] = (fact_memo[i-1]*i)%MOD;
	}

	ull res = 0;
	for(int i = 0; i < H-A; i++) {
		res += calc(B, i+1)*calc(W-B, H-i);
		res %= MOD;
	}
	cout << res << endl;
        
	return 0;
}


Measured memory_bytes: 2560
#!python3

LI = lambda: list(map(int, input().split()))

# input
N, M = LI()


def main():
    s = N
    c = M
    x = min(s, c // 2)
    c -= 2 * x
    y = c // 4
    ans = x + y
    print(ans)
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
#define LL long long
#define Rg register
#define RI register int
#define RC register char
#define ed puts("") 
#define pair pair<LL,LL>
#define space putchar(' ')
using namespace std;
    
template <typename tp> inline void read(tp & x)
{	
    x=0;
    RI f=1;
    RC c=getchar();
    while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar(); }
    while(c>='0' && c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();} 
 	x*=f;
} 	
    
template <typename Tp> inline void print(Tp x)
{		
    if(x<0) x=-x,putchar('-');
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

int n;
LL ans;
LL b[100005];
struct qwq
{
	int num;
	int val;
	bool flag;
}a[100005];

inline bool cmp(qwq x,qwq y)
{
	return x.val<y.val;
}
//qwq
int main()
{
	read(n);
	for(RI i=1;i<=n;++i)
		read(a[i].val),a[i].num=i;
	stable_sort(a+1,a+n+1,cmp);
	for(RI i=1;i<=n;++i)
	{
		int k=i;
		int kk=a[i].val;
//		while(k<=n)
//		{
//			if(a[i].num==k)
//			{
//				a[i].flag=1;	
//				break;
//			}
//			k+=2;
//		}
		int h=i%2;
		int hh=a[i].num%2;
		if(h==hh) a[i].flag=1;
		if(a[i].flag) continue;
//		k=i;
//		while(k>=1)
//		{
//			if(a[i].num==k)
//			{
//				a[i].flag=1;
//				break;
//			}
//			k-=2;
//		}
	}
	for(RI i=1;i<=n;++i)
	{
		if(a[i].flag) continue;
		ans++;
	}
	if(ans==0)
	{
		print(0);
		return 0;
	}
	print(ans/2);
	return 0;
}

Measured memory_bytes: 2688
//************************
//*  Date: 2018.9.22     *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,a[100010];
int ev[100010],od[100010];

int main()
{
	cin>>n;
	int mxe=0,mxo=0;
	int mxec,mxoc;
	rep(i,n)
	{
		cin>>a[i];
		if(i%2==1)
		{
			od[a[i]]++;
			if(od[a[i]]>mxo) mxo=od[a[i]],mxoc=a[i];
		}
		else
		{
			ev[a[i]]++;
			if(ev[a[i]]>mxe) mxe=ev[a[i]],mxec=a[i];	
		}
	}
	sort(ev,ev+100005);
	reverse(ev,ev+100005);
	sort(od,od+100005);
	reverse(od,od+100005);
	//cout<<mxec<<' '<<mxoc<<endl;
	if(mxec==mxoc)
	{
		cout<<min(n-mxe-od[1],n-mxo-ev[1])<<endl;
		rt0;
	}
	cout<<n-mxe-mxo<<endl;
	rt0;
}

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

#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000000

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

    int n;

    cin >> n;

    string s, t;

    cin >> s >> t;

    for(int i = 0; i < 2*n; i++){
        if(!(i%2))
            cout << s[(i/2)];
        else
            cout << t[(i-1)/2];
    }

    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = [list(map(int, input().split())) for _ in range(n)]
    a0 = list(filter(lambda aa: aa[2] > 0, a))[0]

    for i in range(101):
        for j in range(101):
            is_ok = True
            h_ans = a0[2] + abs(a0[0] - i) + abs(a0[1] - j)
            for x, y, h in a:
                if max(h_ans - abs(x - i) - abs(y - j), 0) != h:
                    is_ok = False
                    break
            if is_ok:
                break
        if is_ok:
            break

    print(i, j, h_ans)


main()


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

using namespace std;

typedef long long ll;

ll N, K, L, R;
ll a[40];

auto enumerate(int sidx, int size) {
  vector<pair<ll, ll>> ret;
  for(int i=0; i<1<<size; i++) {
    int cnt = 0; ll sum = 0;
    for(int j=0; j<size; j++)
      if(i >> j & 1) cnt++, sum += a[sidx + j];
    if(cnt <= K) ret.emplace_back(cnt, sum);
  }
  return ret;
}

ll solve() {
  auto v0 = enumerate(0, N / 2);
  auto v1 = enumerate(N / 2, (N + 1) / 2);
  sort(v0.begin(), v0.end());
  ll ret = 0;
  for(int i=0; i<(int)v1.size(); i++)
    ret +=  upper_bound(v0.begin(), v0.end(), make_pair(K - v1[i].first, R - v1[i].second))
          - lower_bound(v0.begin(), v0.end(), make_pair(K - v1[i].first, L - v1[i].second));
  return ret;
}

int main() {
  cin >> N >> K >> L >> R;
  for(int i=0; i<N; i++) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 43736
#include <stdio.h>
#include <math.h>
  
typedef struct{
  double x;
  double y;
} Point;
  
void koch(int, Point, Point);
  
int main(int argc, char const *argv[]) {
  
  Point p1,p2; 
  int n;
  
  scanf("%d",&n);
  
  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;
  
  printf("%.8f %.8f\n",p1.x,p1.y);
  koch(n,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);
  
  return 0;
}
  
void koch(int n, Point p1, Point p2){
  
  if( n == 0 ) return;
  
  Point s,t,u;
  double th = M_PI * 60.0 / 180.0;
  
  s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
  t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
  u.x = (t.x-s.x) * cos(th) - (t.y-s.y) * sin(th) + s.x;
  u.y = (t.x-s.x) * sin(th) + (t.y-s.y) * cos(th) + s.y;
  
  koch(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,p2);
  
}

Measured memory_bytes: 2712
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<typeinfo>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

using cWeightEdges=vector<vector<pair<int,int>>>;
using cEdges=vector<vector<int>>;

int main() {
	string str;
	cin>>str;
	int K;
	cin>>K;

	if(str.size()==1){
		K%=26;
		while(K>0){
			--K;
			if(str[0]=='z')str[0]='a';
			else ++str[0];
		}
	}
	else{
		int index=0;
		for(int i=0;i<str.size()-1;++i){
			if(str[i]!='a' && 'z'-str[i]+1<=K){
				K-='z'-str[i]+1;
				str[i]='a';
			}
			if(K==0)break;
		}
		K%=26;
		while(K>0){
			--K;
			if(str.back()=='z')str.back()='a';
			else ++str.back();
		}
	}

	cout<<str<<endl;
	
	//system("pause");
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] X = new int[M];
        for(int i = 0; i < M; i++) {
            X[i] = sc.nextInt();
        }
        Arrays.sort(X);
        int[] Y = new int[M-1];
        for(int i = 0; i < M-1; i++) {
            Y[i] = X[i+1] - X[i];
        }
        Arrays.sort(Y);
        int ans = 0;
        for(int i = 0; i < (M-1)-(N-1); i++) {
            ans += Y[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50420
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.buffer.readline().rstrip()
def resolve():
    n,q=map(int,input().split())
    S,T,X=[0]*n,[0]*n,[0]*n
    D=[0]*q
    for i in range(n):
        S[i],T[i],X[i]=map(int,input().split())
    for j in range(q):
        D[j]=int(input())

    E=[]
    E+=[(s-x,1,x) for s,x in zip(S,X)]
    E+=[(t-x,2,x) for t,x in zip(T,X)]
    E+=[(d,3,i) for i,d in enumerate(D)]
    E.sort()
    from collections import defaultdict
    cnt=defaultdict(int)
    cnt[INF]=1

    from heapq import heappop,heappush
    Q=[INF]
    ans=[-1]*q
    for a,b,c in E:
        if(b==1):
            heappush(Q,c)
            cnt[c]+=1
        elif(b==2): # 本来はここでqからcを削除したいが、できないためb==3で処理する
            cnt[c]-=1
        else:
            while(cnt[Q[0]]==0): # 本来削除されるべき通行止めをここで消す
                heappop(Q)
            x=Q[0]
            if(x!=INF): ans[c]=x
    print(*ans,sep="\n")
resolve()


Measured memory_bytes: 125192
#include <stdio.h>
#include <math.h>

int main(void)
{
    double a, b, c, C, S, L, h, rad_1d;

    rad_1d = atan(1) / 45;

    scanf("%lf %lf %lf", &a, &b, &C);

    S = a * b * sin(rad_1d * C) / 2;
    
    c = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(rad_1d * C));
    L = a + b + c;
    h = S * 2 / a;

    printf("%f\n%f\n%f\n", S, L, h);

    return 0;
}

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

#define ll long long

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if (c > a) {
        cout << "0 " << max(0ll, b-c+a);
    }
    else
        cout << a-c << " " << b;
    return 0;
}


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

using namespace std;

int main(){
  int t;
  cin>>t;
  
  while(t--){
    int up=0,dwon=0;
    int diff,n;
    cin>>n;
    int block[n];

    for(int j=0;j<n;j++){
      cin>>block[j];
    }

    for(int j=0;j<n-1;j++){
      if(block[j] < block[j+1]){
        diff=block[j+1]-block[j];
        if(up<diff)
          up=diff;
      }
      else if(block[j] > block[j+1]){
        diff=block[j]-block[j+1];
        if(dwon<diff)
          dwon=diff;
      }
    }

    cout<<up<<" "<<dwon<<endl;
  }

  return 0;
}



Measured memory_bytes: 2984
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from itertools import combinations_with_replacement as combi
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n, m, q = MII()
    query = [MII() for _ in range(q)]
    # l = [i for i in range(1,m+1)]
    # maxv = 0
    # for v in combi(l,n):
    #     sumv = 0
    #     for a,b,c,d in query:
    #         if v[b-1]-v[a-1] == c:
    #             sumv += d
    #     maxv = max(maxv, sumv)
    # print(maxv)
    def score(A):
        res = 0
        for a, b, c, d in query:
            if A[b-1]-A[a-1] == c:
                res += d
        return res

    def dfs(A):
        if len(A) == n:
            return score(A)
        res = 0
        prev_last = A[-1] if len(A) > 0 else 0
        for v in range(prev_last, m):
            A.append(v)
            res = max(res, dfs(A))
            A.pop()
        return res
    print(dfs([]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9612
n = int(input())
s = input().strip()

cumsum = [0] * n

# 西を向いている人数の累積和
for i in range(n):
    dir = s[i]
    prev = cumsum[i - 1] if i > 0 else 0
    cur = 1 if dir == 'W' else 0
    cumsum[i] = prev + cur


num_min = 1000000


for i in range(n):
    # i 番目の人がリーダーになる場合
    # リーダーより西の人で向きを変える人の数
    # = i番目より前で西を向いている人数
    w = cumsum[i - 1] if i > 0 else 0
    # リーダーより東の人で向きを変える人の数
    # = i番目より後で東を向いている人数
    e = n - (i + 1) - (cumsum[-1] - cumsum[i])

    num_min = min(num_min, w + e)

print(num_min)


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

#define REP(i,n) for(int i=0;i<(n);++i)
#define FORR(it,cont) for(auto it=rbegin(cont);it!=rend(cont);++it)
#define FOR(it,cont) for(auto it=begin(cont);it!=end(cont);++it)
#define ALL(cont) begin(cont), end(cont)
#define LB(b,e,v) lower_bound(b,e,v)
#define UB(b,e,v) upper_bound(b,e,v)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define MODDING(a,b) (a) = AS_MOD(a,b)
#define MAXIMIZE(a, b) (a) = max((a),(b))
#define MINIMIZE(a, b) (a) = min((a),(b))

using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<int, Pii> iPii;
struct SegmentTree {
  long long Storage[1<<20][2]; // 0=> normal 1 => sum
  int N;
  void init(int n) {
    N=1;
    while(N<n) N*=2;
    for(int i=0;i<N*2;++i) {
      Storage[i][0]=Storage[i][1]=0;
    }
  }
  void addRange(long long v,int a,int b,int k,int l, int r) {
    if(b<=l || a>=r) return;
    if(a<=l && b>=r) {
      Storage[k][1]+=v;
    } else {
      Storage[k][0]+=v*(min(b,r)-max(a,l));
      addRange(v,a,b,k*2+1,l,(l+r)/2);
      addRange(v,a,b,k*2+2,(l+r)/2,r);
    }
  }

  long long sumRange(int a,int b,int k,int l, int r) {
    if(b<=l || a>=r) return 0;
    if(a<=l && b>=r) {
      return Storage[k][0]+Storage[k][1] * (r-l);
    } else {
      long long tl = sumRange(a,b,k*2+1,l,(l+r)/2);
      long long tr = sumRange(a,b,k*2+2,(l+r)/2,r);
      long long ts = Storage[k][1] * (min(b,r)-max(a,l));
      return tl+tr+ts;
    }
  }
};
int N,M;
SegmentTree segmentTree;
vector<iPii> ranges;
int main() {
  cin >> N >> M;
  segmentTree.init(M+1);
  REP(i, N) {
    int l,r;
    cin >> l >> r;
    ranges.push_back(iPii(r-l, Pii(l,r)));
  }
  sort(ALL(ranges));
  int j=0;
  REP(i, M) {
    while(ranges[j].first<i && j < ranges.size()) {
      segmentTree.addRange(1,ranges[j].second.first,ranges[j].second.second+1,0,0,segmentTree.N);
      ++j;
    }
    int ans=ranges.size() - j;
    for(int k=0;k<=M;k+=i+1) {
      ans += segmentTree.sumRange(k,k+1,0,0,segmentTree.N);
    }
    cout << ans <<endl;
  }
  return 0;
}


Measured memory_bytes: 14448
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

struct UnionFind {
    //自身が親であれば，その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;

    UnionFind(int n) {
        r = vector<int>(n, -1);
    }

    int root(int x) { //木の根を調べる（どのグループに属しているか）
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) { //xとyの属する集合を併合
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) { //xが属する集合の頂点数を調べる
        return -r[root(x)];
    }

    bool same(int x, int y) { //xとyが同じ集合に属するか否か
        return root(x) == root(y);
    }
};
 
int main() {
    int n,m; cin >> n >> m;
    UnionFind UF(n);
    rep(i,m) {
        int a, b; cin >> a >> b;
        a--; b--;
        UF.unite(a,b);
    }
    int ans = 0;
    rep(i,n) {
        chmax(ans, UF.size(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 4004
#include<bits/stdc++.h>
using namespace std;
int n, m;
int d[100010];
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i)
	{
		int u, v; scanf("%d%d", &u, &v);
		++d[u]; ++d[v];
	}
	for(int i = 1; i <= n; ++i) printf("%d\n", d[i]);
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>

char week[7][10] = {
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday",
  "Sunday",
};

int main(void){
  int y, m, d;
  int h, C, Y, R;

  while(1){
    scanf("%d%d", &m, &d);
    if(m == 0 && d == 0) break;

    y = 2004;

    if(m == 1 || m == 2){
      y--;
      m += 12;
    }

    C = y / 100;
    Y = y % 100;
    R = -2 * C + C / 4;
    h = (d + 26 * (m + 1) / 10 + Y + Y / 4 + R + 7*7*7*7*7*7*7) % 7;

    printf("%s\n", week[(h + 5) % 7]);
  }

  return 0;
}

Measured memory_bytes: 584
parseint(x) = parse(Int, x)
readint() = readline() |> parseint
readintlist() = map(parseint, readline() |> split)

function main()
    n = readint()
    h = readintlist()
    ans = "Yes"
    for i = n-1:-1:1
        if h[i] > h[i+1]
            h[i] -= 1
        end
        if h[i] > h[i+1]
            ans = "No"
        end
    end
    println(ans)
end

main()

Measured memory_bytes: 133792
#include <cstdio>
#include <cstring>
#include <algorithm>
void Unused(...) {}
#ifndef DEBUG
  #define echo(...) Unused(__VA_ARGS__)
#else
  #define echo(...) fprintf(stderr, __VA_ARGS__)
#endif

const int MaxN = 10000 + 7;
const int MaxK = 13;

int n, k;
int d[MaxK];
bool allow[10];
int digits[10], lim;

int p10(int exp)
{
    int ans = 1;
    for (; exp > 0; --exp)
        ans *= 10;
    return ans;
}

int dfs(int bit, bool gr)
{
    if (bit < 0)
        return 0;
    const int now = digits[bit];
    if (bit == lim)
    {
        int rest = dfs(bit - 1, false);
        if (rest >= 0)
            return rest;
    }
    for (int next = 0; next < 10; ++next)
    {
        for (; next < 10 && !allow[next]; ++next)
            ;
        //echo("for %d try %d(%d %d)\n", bit, next, gr, next > now);
        if (next < 10 && (gr || next >= now))
        {
            int ans = p10(bit) * next;
            int rest = dfs(bit - 1, gr || next > now);
            //echo("rest %d\n", rest);
            if (rest >= 0)
                return ans + rest;
        }
    }
    return -1;
}

int main()
{
    scanf("%d %d", &n, &k);
    for (int i = 0; i < 10; ++i)
        allow[i] = true;
    for (int i = 1; i <= k; ++i)
    {
        scanf("%d", d + i);
        allow[d[i]] = false;
    }
    for (lim = 0; n; n /= 10)
        digits[lim++] = n % 10;
    printf("%d\n", dfs(lim, false));
    return 0;
}



Measured memory_bytes: 128
#coding:utf-8
import sys
import bisect
import math
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    a, b, x = LMIIS()


    if x <= a*a*b/2:
        print(math.atan(b/(2*x/a/b)) * 180 / math.pi)
    else:
        print(math.atan(2*(a*a*b-x)/a/a/a) * 180 / math.pi)







if __name__ == '__main__':
    main()


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

namespace _1
{
    class Program
    { 
        static void Main()
        {
            int[] n = Console.ReadLine().ToCharArray().Select(x => x.ToString()).Select(x => int.Parse(x)).ToArray();
            int ans = 0;

            for(int a = 0; a < 3; a++)
            {
                if (n[a] == 1)
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }
    }
}

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

int main()
{
    int N;
    cin >> N;
    vector<long double> v(N);
    for (int i = 0; i < N;i++)
        cin >> v[i];

    sort(v.begin(), v.end());
    long double ans = (v[0] + v[1]) / 2;
    for (int i = 2; i < N;i++){
        ans = (v[i] + ans) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256