akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
using namespace std;

signed main()
{
	int N, A, B;
	cin >> N >> A >> B;

	if (A > B)
	{
		cout << "0" << endl;
		return 0;
	}

	if (N <= 1)
	{
		if (A == B)
		{
			cout << "1" << endl;
			return 0;
		}
		else
		{
			cout << "0" << endl;
			return 0;
		}
	}

	int min = A + B + A * (N - 2);
	int max = A + B + B * (N - 2);

	cout << (max - min + 1) << endl;

}

Measured memory_bytes: 256
/*
 Abu Jafor Mohammad Saleh
 ios_base :: sync_with_stdio(false);
 cin.tie(NULL);
 */

#include<cstdio>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<limits>
#include <algorithm>
#include <unordered_map>
#define f first
#define s second
#define MOD 1000000007
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//#include<bits/stdc++.h>
using namespace std;

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


int main()
{
    fast;
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    for(int i=0;i<n;i++)
    {
        cout<<s[i]<<t[i];
    }
    cout<<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;

template<class T, class U> inline int divCount(T &num, U divisor) {
    int count = 0;
    while (num % divisor == 0) {
        num /= divisor;
        count++;
    }
    return count;
}

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

    int n;
    cin >> n;

    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    int count = 0;
    REP(i, n) if (a[i] % 2) count++;
    if (count == n) cout << '0' << '\n';
    else {
        ll countEven = 0;
        REP(i, n) {
            if (a[i] % 2 == 0) {
                countEven += divCount(a[i], 2);
            }
        }
        cout << countEven << '\n';
    }
    return 0;
}


Measured memory_bytes: 384
def main():
    _ = input()
    a = list(map(int, input().split()))
    max_height = 0
    ans = 0
    for height in a:
        if max_height <= height:
            max_height = height
        else:
            ans += max_height - height
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 32228
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1.0)

#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld\n",a)

#define stll(a) stoll(a,nullptr,10)
#define PII pair<ll,ll>
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define EL printf("\n")
#define ff first
#define ss second


#define mem(ar,val) memset(ar,val,sizeof(ar))
#define ssort(ar) sort(ar.begin(),ar.end())
#define csort(ar,comp) sort(ar.begin(),ar.end(),comp)

#define bug1(a) cout<<"test "<<a<<endl;
#define bug2(a,b) cout<<"test "<<a<<" "<<b<<endl;
#define bug3(a,b,c) cout<<"test "<<a<<" "<<b<<" "<<c<<endl;
#define bug4(a,b,c,d) cout<<"test "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

#define fout freopen("output.txt","w",stdout)
#define fin  freopen("input.txt","r",stdin)

/// unordered_map<int,int>mp;
/// mp.reserve(1024);
/// mp.max_load_factor(0.25);

/// pbds
/// *find_by_order(k) - return k th largest element.. 0 based
/// order_of_key(k) - number of items strictly smaller than k

/*
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
*/

typedef long long ll;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


int main()
{
    ll n,k;
    ll ar[10000];
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>ar[i];
    sort(ar+1,ar+n+1);
    ll ans=0;
    for(int i=1;i<=k;i++)
        ans+=ar[i];
    cout<<ans<<endl;

}




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

int main() {
    int y,m,d;
    char c1,c2;
    cin >> y >> c1 >> m >> c2 >> d;
    cout << (m <= 4 ? "Heisei" : "TBD") << endl;    
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int a[4];
int main()
{
int f=0;
for(int i=0;i<4;i++)
{
scanf("%1d",&a[i]);
if(i>0)
{
if(a[i]==a[i-1])
{
f=1;
}


}
}
if(f==1)
printf("Bad\n");
else
printf("Good\n");

}


Measured memory_bytes: 256
use proconio::input;

fn main() {
  input! {
    N: usize,
    M: usize,
    X: usize
  }
  
  let mut books: Vec<Vec<usize>> = Vec::with_capacity(M);
  for i in 0..N {
    input! {
      C: [usize;M+1],
    }
    books.push(C.into_iter().collect());
  }
  
  let mut min = usize::max_value();
  for i in 0..(1 << N) {
    let mut result = vec![0;M+1];
    let mut total = 0;
  	for j in 0..N {
      if (i >> j) & 1 == 0 { continue }
      total += books[j][0];
      for k in 1..M+1 {
        result[k] += books[j][k];
      }
    }
	
    let mut flag = true;
    for j in 1..M+1 {
      if result[j] < X {
        flag = false;
        break;
      }
    }
    
    if flag {
      min = std::cmp::min(min, total);
    }
  }
  
  if min == usize::max_value() {
  	println!("-1");
  } else {
  	println!("{}", min);
  }
}

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

int main() {
    int n, a[100],cnt=0;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    for(int i=0; i<n; i+=2){
        if(a[i]%2==1) cnt++;
    }
    cout << cnt;
}

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

using namespace std;

typedef long long int lli;

int main() {
    int r, d, x;

    cin >> r >> d >> x;
    int ans = x;
    for (int i=0; i<10; i++) {
        ans = r * ans - d;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1000000000000;

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main() {
  ll N; cin >> N;
  ll co = INF;
  ll n = (ll)sqrt(N);
  for(int i = 1; i <= n; i++) {
    if(N % i == 0) {
      co = min(co, ((i - 1) + (N / i) - 1));
    }
  }
  cout << co << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
/*{{{*/
#include <bits/stdc++.h>
#ifdef LOCAL
int c_ = 0;
#define cout (c_?cerr:cout)
#define debug(...) \
{if(!c_++)cerr<<"\033[96;1m"; \
__VA_ARGS__; \
if(!--c_)cerr<<"\033[0m";}
#else
#define debug(...) {}
#endif
#define assrt(...) debug(\
if (not (__VA_ARGS__)) \
    exit((cerr << __LINE__ << ": " << #__VA_ARGS__ << '\n', 0));\
)
#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
using namespace std; using ll = long long;
template < typename t > using V = vector< t >;
template < typename t, size_t s > using A = array< t, s >;
void print() {cout << '\n';}
template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":""); print(b...);}
template< typename t > void print_range(t a, const t& b)
{ while (a != b) cout << (*a++) << ' '; cout << '\n';}
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
#define dump_range(...) debug(cerr<<#__VA_ARGS__ << ": "; print_range(__VA_ARGS__))
/*}}}*/

constexpr int nax = 20;

int val[nax];

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> val[i];
    for (int i = 0; i < n; ++i)
    {
        int c; cin >> c; val[i] -= c;
    }
    int res = 0;
    for (int i = 0; i < n; ++i)
        if (val[i] > 0) res += val[i];
    print(res);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#define INF 0x3f3f3f3f
int read()
{
    int x=0,f=1;	char c=getchar();
    while(c<'0'||c>'9')	{if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9')	{x=x*10+c-'0';c=getchar();}
    return x*f;
}
priority_queue<int,vector<int>,greater<int> >q1;
priority_queue<int,vector<int>,less<int> >q2;
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
/** keep hungry and keep calm! **/
/**编译错误：数组越界 除以0**/ 

/**
每天行走的距离是可以自己决定的
所以每天行走距离可以相同
那么只要字符串中出现NWSE代表四个方向的字符且数量相等即可 
**/
/**string s;
int a,b,c,d,sum;
int x[5];
int main()
{
	cin >> s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i] == 'N')
		{
			x[1] = 1;	a++;
		}
		if(s[i] == 'W')
		{
			x[2] = 1;	b++;
		}
		if(s[i] == 'S')
		{
			x[3] = 1;	c++;
		}
		if(s[i] == 'E')
		{
			x[4] = 1;	d++;
		}
	}
	for(int i=1;i<=5;i++)
		sum += x[i];//把出现了几个数字加和 
	if(sum == 1 || sum == 3)//出现1个或者3个方向，一定回不来 
	{
		printf("No\n");
		return 0;
	}
	else
	{
		if(sum == 2)
		{
			if(x[1] == 1 && x[3] == 1)
			{
				if(a % c == 0)	printf("Yes\n");
			}
			else if(x[2] == 1 && x[4] == 1)
			{
				if(b % d == 0)	printf("Yes\n");
			}
			else	printf("No\n");
		}
		if(sum == 4)
		{
			if(a == b && a == c && a == d)
				printf("Yes\n");
		}
	}
	return 0;
}**/

int main()
{
    string s;
    int w=0,e=0,ss=0,n=0;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='W')w=1;
        else if(s[i]=='E')e=1;
        else if(s[i]=='S')ss=1;
        else if(s[i]=='N')n=1;
    }
    if(w==e&&n==ss)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, x, t;
void solve()
{
    cin >> n >> x >> t;
    int sum = 0;
    int time = 0;
    while (sum < n)
    {
        sum += x;
        time += t;
    }
    cout << time << "\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3640
def RLE(S):
    res = []
    N = len(S)
    i = 0
    while i < N:
        cnt = 1
        while i < N - 1 and S[i] == S[i + 1]:
            cnt += 1
            i += 1
        res.append((S[i], cnt))
        i += 1
    return res


if __name__ == "__main__":
    S = list(input())
    term = "ATCG"
    X = ""
    for s in S:
        if s in term:
            X += "1"
        else:
            X += "0"
    rle = RLE(X)
    ans = 0
    for k, v in rle:
        if k == "1":
            ans = max(ans, v)
    print(ans)

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int c[n];
	for (auto &i : c) i = ri();
	int a[n][26];
	for (auto &i : a) for (auto &j : i) j = ri();
	
	auto score = [&] (std::vector<int> start) {
		int last[26];
		for (auto &i : last) i = -1;
		int res = 0;
		for (int i = 0; i < n; i++) {
			int cur = start[i % 26];
			last[cur] = i;
			for (int j = 0; j < 26; j++) res -= c[j] * (i - last[j]);
			res += a[i][cur];
		}
		return res;
	};
	int max = -1000000000;
	std::vector<int> res;
	std::vector<int> cur(26);
	std::iota(cur.begin(), cur.end(), 0);
	
	std::random_device rnd_dev;
	std::mt19937 rnd(rnd_dev() ^ time(NULL));
	
	clock_t r0 = clock();
	while (clock() - r0 <= 1.95 * CLOCKS_PER_SEC) {
		std::shuffle(cur.begin(), cur.end(), rnd);
		int cur_score = score(cur);
		if (max < cur_score) max = cur_score, res = cur;
	}
	
	for (int i = 0; i < n; i++) {
		printf("%d\n", res[i % 26] + 1);
	}
	
	return 0;
}


Measured memory_bytes: 3900
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    map<ll, ll> mp;
    ll ans = 0;
    rep(i, n){
        if(mp[a[i]] != 0){
            mp[a[i]] = 2;
            continue;
        }
        for(int j = a[i]; j <= 1000000; j += a[i]){
            mp[j]++;
        }
    }
    rep(i, n){
        if(mp[a[i]] == 1) ans++;
    }
    print(ans);

}

Measured memory_bytes: 67348
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int ans = a + a*a + a*a*a;
        lp(ans);
    }
    public static void lp(Object o){
        System.out.println(o);
    }
}


Measured memory_bytes: 35628
#include <stdio.h>

int main(void){
    int n, i;
    double a, s, b=0;

    scanf("%d\n", &n);

    for(i=0;i<n;i++){
        scanf("%lf", &a);
        b = b + 1 / a;

    }
    s = 1 / b;
    printf("%lf\n", s);

    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
/*切り上げの計算！*/
int maxtime(int x) {
	return(x + 9) / 10 * 10;

}
int main() {
	long long int N, M;
	cin >> N >> M;
	pair<int, int> d;
	d.first = 0;
	d.second = 0;
	vector<pair<long int, long int>> S;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		pair<long int, long int> key;
		key.first = a;
		key.second = b;
		S.push_back(key);
	}
	sort(S.begin(), S.end());
	long long int sum = 0;
	for (int i = 0; i < N; i++) {
		if (M > S[i].second) {
			M = M - S[i].second;
			long long int k = S[i].first * S[i].second;
			sum = sum + S[i].first * S[i].second;
		}
		else {
			sum = sum + S[i].first * M;
			cout << sum;
			return 0;
		}
	}
}

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

#define ff first
#define ss second
#define endl '\n'

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

	ll n;
	cin >> n;

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

	n /= 2;
	ll pow5 = 5, ans = 0;
	for ( ; pow5 <= n; pow5 *= 5) {
		ans += (n / pow5);
	}

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#define INF 1545141919
using namespace std;
int a[1010];
void In(int x){
	string s;cin>>s;
	if(s=="x")a[x]=INF;
	else{
		bool flag=false;if(s[0]=='-')flag=true;
		int cnt=0;
		for(int i=flag;i<s.size();i++)cnt*=10,cnt+=s[i]-'0';
		a[x]=cnt;
		if(flag)a[x]=-a[x];
	}
}
int main(){
	int n;
	while(cin>>n&&n){
	for(int i=0;i<n;i++)In(i);
	bool ok=true;int left=-INF,right=INF;
	for(int i=0;i<n-1;i++){
		if(a[i]==INF&&a[i+1]==INF)ok=false;
		if(a[i]!=INF&&a[i+1]!=INF){
			if(i%2==0)if(a[i]>=a[i+1])ok=false;
			if(i%2==1)if(a[i]<=a[i+1])ok=false;
		}
		if(a[i]==INF&&a[i+1]!=INF){
			if(i%2==0)right=min(right,a[i+1]-1);
			if(i%2==1)left=max(left,a[i+1]+1);
		}
		if(a[i]!=INF&&a[i+1]==INF){
			if(i%2==0)left=max(left,a[i]+1);
			if(i%2==1)right=min(right,a[i]-1);
		}
	}
	if(!ok||right<left)cout<<"none"<<endl;
	else if(right==left)cout<<right<<endl;
	else cout<<"ambiguous"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include<stdio.h>
 
int main(){
 
int a,b,max=-2000000000,min;
 
scanf("%d",&a);
 
int r[200000];
 
int i;

for(i=0;i<a;i++)scanf("%d",&r[i]);
 
min=r[0];
 

 
for(i=1;i<a;i++){
 
if(r[i]-min>max)max=r[i]-min;
if(min>r[i])min=r[i];
}
 
printf("%d\n",max);
 
return 0;
}

Measured memory_bytes: 1376
import java.util.*;

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

        Integer N = sc.nextInt();
        Integer M = sc.nextInt();

        if (N == M) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        

    }

}

Measured memory_bytes: 23764
import fractions

N = int(input())
 
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  # divisors.sort()
  return divisors
 
divisors = make_divisors(N)
sum = 0
#print(len(divisors))
sort_divisors = sorted(divisors)

if len(divisors) % 2 == 0:
  min1 = sort_divisors[int(len(divisors)/2)-1]
  min2 = sort_divisors[int(len(divisors)/2)]
else:
  min1 = sort_divisors[int((len(divisors)-1)/2)]
  min2 = min1

print(min1+min2-2)

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  string s;
  cin >> s;
  int y = stoi(s.substr(0, 2)), m = stoi(s.substr(2, 2));

  bool f1 = false, f2 = false;
  if (in(y, 1, 13)) f1 = true;
  if (in(m, 1, 13)) f2 = true;
  if (f1 && f2) {
    cout << "AMBIGUOUS" << endl;
  }
  else if (f1) {
    cout << "MMYY" << endl;
  }
  else if (f2) {
    cout << "YYMM" << endl;
  }
  else {
    cout << "NA" << endl;
  }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=[]
    inf=10**6
    for _ in range(N):
        a=LI()+[inf]
        for j in range(N-1):
            a[j]-=1
        A.append(a)
        
        
    cur=[0]*N#i番目の人が何試合消化したか
    
    st=[]# stackに，みるべき人を入れていいく，変化があった人だけ見れば良い
    nxt=[]
    
    #初日は全員みる，N>=3より初日で終わることはない
    for i in range(N):
        for j in range(i+1,N):
            if A[i][0]==j and A[j][0]==i:
                cur[i]=1
                cur[j]=1
                st.append(i)
                st.append(j)
    day=1
    
    while st:
        used=[0]*N
        day+=1
        
        while st:
            i=st.pop()#みる人
            j=A[i][cur[i]]#相手候補
            
            if used[i]==0 and used[j]==0:
                if A[j][cur[j]]==i:#マッチング
                    cur[i]+=1
                    cur[j]+=1
                    nxt.append(i)
                    nxt.append(j)
                    used[i]=1
                    used[j]=1
               
        while nxt:
            a=nxt.pop()
            if cur[a]!=N-1:
                st.append(a)
        
    if sum(cur)==N*(N-1):
        print(day)
    else:
        print(-1)
        
            
        
        
    

main()


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

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

    string s;
    cin >> s;

    int x = 0, max_x = 0;
    for (char c : s)
        if (c == 'I')
            max_x = max(max_x, ++x);
        else
            x--;
    
    cout << max_x << endl;
}

Measured memory_bytes: 3600
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

struct UF{
	vector<int> par, sz;
	vector<LL> xs;
	VV(int) attr;
	explicit UF(const vector<LL> &xs_){
		int n = xs_.size();
		par.resize(n);
		sz.assign(n, 1);
		attr.resize(n);
		xs = xs_;
		iota(ALL(par), 0);
	}
	int find(int x){
		while(x != par[x]){ x = par[x]; }
		return x;
	}
	bool unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y){ return false; }
		if(sz[x] < sz[y]){ swap(x, y); }
		sz[x] += sz[y];
		par[y] = x;
		xs[x] += xs[y];

		if(attr[x].size() < attr[y].size()){
			attr[x].swap(attr[y]);
		}
		attr[x].insert(attr[x].end(), ALL(attr[y]));
		vector<int>().swap(attr[y]);
		return true;
	}
};

void mainmain(){
	int n, m;
	scanf("%d%d", &n, &m);
	vector<LL> xs(n);
	for(int i = 0; i < n; ++i){
		scanf("%lld", &xs[i]);
	}

	vector<tuple<LL,int,int>> es(m);
	for(int i = 0; i < m; ++i){
		int a, b;
		LL y;
		scanf("%d%d%lld", &a, &b, &y);
		es[i] = make_tuple(y, a - 1, b - 1);
	}
	sort(ALL(es));

	UF uf(xs);
	vector<int> ng(m, 1);
	for(int i = 0; i < m; ++i){
		int a, b;
		LL y;
		tie(y, a, b) = es[i];

		uf.unite(a, b);
		int r = uf.find(a);
		if(uf.xs[r] >= y){
			ng[i] = 0;
			for(int z : uf.attr[r]){
				ng[z] = 0;
			}
			vector<int>().swap(uf.attr[r]);
		}
		else{
			uf.attr[r].push_back(i);
		}
	}
	
	int ans = count(ALL(ng), 1);
	printf("%d\n", ans);
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 9576
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  ll h,tmp=1,sum=0;

  cin>>h;

  while(h>1){
    h=h/2;
    sum+=tmp;
    tmp*=2;
  }

  sum+=tmp;

  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
  int n,a,t,mi=0,h,i;
  double m=1e9;
  scanf("%d %d %d",&n,&t,&a);
  for(i=0;i<n;i++){
    scanf("%d",&h);
    if(fabs(t-h*0.006-a)<m){
      mi=i;
      m=fabs(t-h*0.006-a);
    }
  }
  printf("%d\n",mi+1);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    int Y;
    int M;
    Y = N /100;
    M = N % 100;
    if( 0 < Y && Y <= 12 )
    {
        if(0 < M && M<=12)
        {
            cout << "AMBIGUOUS" << endl;
        }
        else
        {
            cout << "MMYY" << endl;
        }
    }
    else
    {
        if(0<M&& M<=12)
        {
            cout << "YYMM" << endl;
        }
        else
        {
            cout << "NA" << endl;
        }
    }
    
}

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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) cin >> h[i];
    vector<int> dp(1000000, 1001001001);
    dp[0] = 0;
    for (int j = 0; j < n; ++j) {
        dp[j + 1] = min(dp[j + 1], dp[j] + abs(h[j + 1] - h[j]));
        dp[j + 2] = min(dp[j + 2], dp[j] + abs(h[j + 2] - h[j]));
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

    if(A%2 or B%2 or C%2){
        cout<<0<<endl;
        return 0;
    }
    if(A==B and B==C) cout<<-1<<endl;
    else{
        int ans=0;
        while(A%2==0 and B%2==0 and C%2==0){
            int a=A,b=B,c=C;
            A=(b+c)/2; B=(a+c)/2; C=(a+b)/2;
            ans++;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N = int(raw_input())
L = map(int, raw_input().split())
L.sort()
ans = 0
for i in xrange(N - 1, -1, -1):
    ans += min(L[2*i], L[2*i + 1])
print ans


Measured memory_bytes: 5004
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    d = {}
    res = 0
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n-1, -1, -1):
        if i+a[i] in d:
            res += d[i+a[i]]
        if i-a[i] not in d:
            d[i-a[i]] = 1
        else:
            d[i-a[i]] += 1
    print(res)

if __name__ == '__main__':
    main()

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll H,W,A,B;

ll mo=1000000007;
ll combi(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>A>>B;
	
	ll ret=0;
	for(y=0;y<H-A;y++) ret += combi(B-1+y,y)*combi(H-y-1+W-B-1,W-B-1)%mo;
	cout<<ret%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 9600
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<utility>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
//#include<ext/rope>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
const double PI=acos(-1.0);
const double eps=1e-6;
int cnt[1005];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
template<typename T> void debug(T x)
{
    cout<<"value="<<x<<endl;
    return;
}
signed main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
	int n=read();
	for(int i=1;i<=n;i++){
        int x=read();
        cnt[x]++;
	}
	vector<pair<int,int> > a;
	for(int i=1;i<=1000;i++){
        if(cnt[i]>0){
            pair<int,int> tmp=make_pair(i,cnt[i]);
            a.push_back(tmp);
        }
	}
	ll ans=0;
	int len=a.size();
	for(int i=0;i<=len-3;i++) for(int j=i+1;j<=len-2;j++) for(int k=j+1;k<=len-1;k++){
        if(a[i].first+a[j].first>a[k].first && a[i].first+a[k].first>a[j].first && a[j].first+a[k].first>a[i].first){
            ans+=(a[i].second*a[j].second*a[k].second);
        }

	}
	for(int i=0;i<=len-1;i++){
        if(a[i].second>=3){
            ll xx=(ll)a[i].second;
            ans+=(xx)*(xx-1)*(xx-2)/6;
        }
	}
	for(int i=0;i<=len-1;i++){
        for(int j=0;j<=len-1;j++){
            if(j==i) continue;
            if(2*a[i].first>a[j].first && a[i].second>=2) ans+=(a[i].second)*(a[i].second-1)*(a[j].second)/2;
        }
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
	int n,k; cin>>n>>k;
	if(n%k!=0) cout << 1 << endl;
	else cout << 0 << endl;
}

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

lgt = n
if n==k: print(1)
else:
    lgt-=k
    ans=1
    while 1:
        lgt-=k-1
        ans+=1
        if lgt<=0:
            break
    print(ans)

Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],t[3];
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	sort(a+1,a+n+1);
	for(int i=n;i>=1;--i)
	{
		if(a[i]==a[i+1])
		{
			t[++t[0]]=a[i];i--;
			if(t[0]==2)break;
		}
	}
	if(t[0]!=2){cout<<0;return 0;}
	else
	{
		long long tot=(long long)t[1]*t[2];
		cout<<tot;
	}
}


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

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0;i < n;i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    ll c = 1;
    for (ll i = 1; i < n; i++){
        if (a[i-1] == a[i]){
            c++;
        }
        else{
            if (c%2 == 1){
                ans++;
            }
            c = 1;
        }
    }
    if (c%2 == 1){
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3988
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<assert.h>
#include<vector>
#include<string.h>
using namespace std;
using ll = long long;

const int max_n = 1e5 + 1;;
const int INF = 987654321;

int n,m;
int a[max_n];
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;

	priority_queue<int>pq;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		pq.push(a[i]);
	}
	for (int i = 0; i < m; i++)
	{
		int cur = pq.top();
		pq.pop();
		
		pq.push(cur / 2);
	}
	ll ans = 0;
	while (!pq.empty())
	{
		ans += pq.top();
		pq.pop();
	}
	cout << ans;
}

Measured memory_bytes: 1148
def check(num):
    if num > 1:
        for i in range(2, num):
            if (num % i) == 0:
                return False
                break
        else:
            return True
    else:
        return False


a = int(input())

for i in range(a, 100500):
    if check(i):
        print(i)
        break
        

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i, q;
		Dice d = new Dice();
		try (Scanner sc = new Scanner(System.in)) {
			for(i = 0; i < 6; i++) {
				d.dice_make(i, sc.nextInt()); //diceの作成
			}
			q = sc.nextInt();
			for(i = 0; i < q; i++) {
				d.same(sc.nextInt(), sc.nextInt());
				System.out.println(d.getDice(2));
			}
		}
	}
}
class Dice{
	private int[] dice = new int[6];
	public void dice_make(int i, int dice_spot){
		dice[i] = dice_spot;
	}
	public void rotation(String direction) {
		switch(direction) {
		case "E": dice = new int[] {dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]};break;
		case "N": dice = new int[] {dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]};break;
		case "S": dice = new int[] {dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]};break;
		case "W": dice = new int[] {dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]};break;
		case "T": dice = new int[] {dice[0],dice[3],dice[1],dice[4],dice[2],dice[5]};break;
		default : dice = new int[] {};break;
		}
	}
	public boolean same(int a, int b) {
		int i = 0;
		for(i = 0; i < 6; i++) {
			if(i % 2 == 0) {
				rotation("E");
			}else {
				rotation("N");
			}
			if(dice[0] == a) {
				for(i = 0; i < 4; i++) {
					rotation("T");
					if(dice[1] == b) {
						return true;
					}
				}
			}
		}
		return false;
	}
	public boolean compare(int[] diceA, int[] diceB) {
		int i, counter = 0;
		dice = diceA;
		if(same(diceB[0], diceB[1])) {
			for(i = 0; i < 6; i++) {
				if(dice[i] == diceB[i]) {
					counter++;
				}
			}
			if(counter == 6) {
				return true;
			}
		}
		return false;
	}
	public int getDice(int i) {
		return dice[i];
	}
	public int[] getDice_array() {
		return dice;
	}
}


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

typedef long long ll;
typedef pair<int,int> ii;

bool ok(string &s) {
	int n=s.size();
	string t=s.substr(0,n/2);
	return s==t+t;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	while(!s.empty()) {
		s.pop_back();
		s.pop_back();
		if(ok(s)) { cout << s.size() << endl; return 0; }
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll x,y;
  cin>>x>>y;
  if(x==2||y==2) {
cout<<"No"<<endl;
  return 0;
  }
  
  set<ll> S;
  S.insert(4);
   S.insert(6);
   S.insert(9);
   S.insert(11);
  
  if(S.count(x)&&!S.count(y)) {
cout<<"No"<<endl;
  }
  else if(!S.count(x)&&S.count(y)) {
cout<<"No"<<endl;
  }
  else {
cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 3576
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;

int main(){
	int n;
	cin >> n;
	int a;
	map<int,int> votes;
	for (int i=0;i<n;i++) {	
	cin >> a;
	++votes[a];
	}

	int cnt=0;
	for (auto &item: votes) {
	if (item.second < item.first) {
	cnt += item.second;
	}
	else if (item.first < item.second) {
	cnt += item.second - item.first;
	}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 4736
#coding:utf-8

if __name__ == "__main__":
    #conf_step_odd = ["R", "U", "D"]
    #conf_step_even = ["L", "U", "D"]

    S = input()
    steps_odd = S[0::2]
    steps_even = S[1::2]

    for stp in steps_odd:
        if stp == "L":
            print("No")
            exit()
    for stp in steps_even:
        if stp == "R":
            print("No")
            exit()

    print("Yes")

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

int n,cnt=0,ans=0;
char a[200005];

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>a[i];
	for (int i=1;i<=n;i++)
	{
		if (a[i]=='W')  cnt++;
	}
	for (int i=n-cnt+1;i<=n;i++)
	{
		if (a[i]!='W')  ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3812
N, Q = map(int, input().split())
s = input()

A = [0] * N

prev = s[0]
for i, v in enumerate(s):
    if prev == 'A' and v == 'C':
        A[i] = A[i-1] + 1
    else:
        A[i] = A[i-1]
    prev = v

for i in range(Q):
    l, r = map(int, input().split())
    l, r = l-1, r-1
    print(A[r]-A[l])

Measured memory_bytes: 6084
using System;
using System.Collections;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        string S = Console.ReadLine();
        int b = 0, w = 0;
        for (int i = 0; i < S.Length; i++)
        {
            if (i % 2 == 0)
            {
                if (S[i] == '0')
                    b++;
            }
            else
            {
                if (S[i] == '1')
                    b++;
            }
        }
        for (int i = 0; i < S.Length; i++)
        {
            if (i % 2 == 0)
            {
                if (S[i] == '1')
                    w++;
            }
            else
            {
                if (S[i] == '0')
                    w++;
            }
        }
        Console.WriteLine(Math.Min(b, w));
    }
}

Measured memory_bytes: 11232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int n1 = Integer.parseInt(bf.readLine());
        String[] sp1 = bf.readLine().split(" ");
        int n2 = Integer.parseInt(bf.readLine());
        String[] sp2 = bf.readLine().split(" ");
        int sum = 0;
        for (int j = 0; j < n2; j++) {
            if (binarySearch(sp1, sp2[j], 0, n1-1)) {
                sum++;
            }
        }
        System.out.println(sum);
    }

    private static boolean binarySearch(String sp2[], String key, int left, int right) {
        int mid = (left + right) / 2;
        if (left > right) {
            return false;
        }
        if (key.equals(sp2[mid])) {
            return true;
        } else if (Integer.parseInt(key) > Integer.parseInt(sp2[mid])) {
           return binarySearch(sp2, key, mid+1, right);
        } else {
            return binarySearch(sp2, key, left, mid-1);
        }

    }

}



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

#define INF 1 << 30

//ある数Nについて約数の数を求めるためには、
//for i N%i でやればO(N)
//N!の約数を求めるためには
//for i N%i でやればO(N)
//普通にやるとO(N^2)になっちゃう
//約数の数を求める方法を変える
//素因数分解して、Πai^piになったら、
// Π(pi+1)が約数の数
//N!を素因数分解することを考える
//iを素因数分解してそれぞれの指数を足せばN!の素因数分解になる
//N!は大きいが、N自体は小さいのでNの素因数分解は簡単にできてしまう
//その指数を足していくとN!の素因数分解になる

int N;
vector<int> p;
int ret(int n);

int main(){
  cin >> N;
  p = vector<int>(N+1,0);
  int tmp;
  for (int i=2;i<N+1;i++){
    //i(i=1は指数0なので計算しない）を素因数分解する
    tmp = i;
    for (int j=2;j<i+1;j++){
      while (tmp % j == 0){
        p[j]++;
        tmp = tmp / j;
      }
    }
  }
  //ここまででN!が素因数分解できた
  //N!=Πi^p[i] の形になっているので、iの指数がp[i]になっている
  //これの約数は0<=k[i]<=p[i]なるk[i]を用いて
  //Πi^k[i]と表現でき、この数の約数の個数は、
  //Π(k[i]+1)になっている
  //これが75=3x5x5になっているので、
  //k[i]+1から(75),(25,3),(15,5),(3,5,5)を取り出す場合の数が必要
  //(75)となる組み合わせはi(k[i]+1=75)通り
  //(25,3)となる組み合わせはi*(j-1)(k[i]+1=25&k[j]+1=3)通り
  //(15,5)となる組み合わせはi*(j-1)(k[i]+1=15&k[j]+1=3)通り
  //(3,5,5)となる組み合わせはi*(j-1)*(p-2)(k[i]+1=5&k[j]+1=5&k[p]+1=3)/2通り
  cout << ret(75) + ret(25)*(ret(3)-1) + ret(15)*(ret(5)-1) + ret(5)*(ret(5)-1)*(ret(3)-2)/2 << endl;;
}

//k[i]+1がn以上となるiの数を求める関数
int ret(int n){
  int cnt = 0;
  for (int i=0;i<N+1;i++){
    if (p[i] >= n-1){
      cnt++;
    }
  }
  return cnt;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int a,b,c;cin>>a>>b>>c;

    cout<<(a*b)/2<<endl;

}


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

const int INF = 1<<25;

int main(){
    int n, m, s, g1, g2, a, b, c;
    while(cin >> n >> m >> s >> g1 >> g2, n+m+s+g1+g2){
        vector<vector<int>> v(n, vector<int>(n, INF));
        for(int i = 0; i < n; i++)  v[i][i] = 0;
        s--, g1--, g2--;
        while(m-- > 0){
            cin >> a >> b >> c;
            v[--a][--b] = c;
        }
        for(int k = 0; k < n; k++){
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    if(v[i][k]==INF || v[k][j]==INF)    continue;
                    v[i][j] = min(v[i][j], v[i][k]+v[k][j]);
                }
            }
        }
        int ans = 1<<30;
        for(int i = 0; i < n; i++){
            ans = min(ans, v[s][i]+v[i][g1]+v[i][g2]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;

  for (int j = 0; j <= n / 4; j++) {
    for (int k = 0; k <= n / 7; k++) {
      if (4 * j + 7 * k == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> vec(n);
  for (int i = 0; i< n;i++){
    cin >> vec.at(i);
  }
  
  int sum = 1,len=0;
  
  for (int i = 0; i < n;i++){
    len += vec.at(i);
    if (len<=x){
      sum++;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
ans = 0

while max(H) > 0:
    grp = [[]]
    for i, h in enumerate(H):
        if h == 0:
            if len(grp[-1]) > 0:
                grp.append([])
        else:
            grp[-1].append((i, h))
    for g in grp:
        if len(g) == 0:
            continue
        mi = min([h for _, h in g])
        ans += mi
        for i, _ in g:
            H[i] -= mi

print(ans)


Measured memory_bytes: 3064
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};


int main(void){
  ll N;
  ll S;
  cin >> N;
  vector<ll> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
    S += A[i];
  }
  ll ans = 0;
  for(int i = 1; i < N; i++){
    if(A[i] > A[i-1]){
        ans += A[i] - A[i-1];
    }else{
        ans += A[i];
    }
  }

  ll ans2 = 0;
  for(int i = N - 1; i >= 1; i--){
    if(A[i] > A[i-1]){
      ans2 += A[i] - A[i-1];
    }else{
      ans2 += A[i];
    }
  }
  ans = min(ans, ans2);

  if(A[0] != 0){
    ans = -1;
  }
  for(int i = 0; i < N-1; i++){
    if(A[i+1] - A[i] > 1) ans = -1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792