akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    string s;
    cin >> s;
    deque<char> deq;
    rep(i,s.length())deq.pb(s[i]);
    int rev=0;
    int q;
    cin >> q;
    while(q--){
        int t;
        cin >> t;
        if(t==1){
            rev=1-rev;
            continue;
        }
        else{
            int f;
            char c;
            cin >> f >> c;
            if(rev+f==1 || rev+f==3)deq.push_front(c);
            else deq.pb(c);
        }
    }
    if(rev){
        rep(i,sz(deq)){
            cout << deq[sz(deq)-i-1];
        }
    }
    else{
        rep(i,sz(deq)){
            cout << deq[i];
        }
    }



    
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
h.extend([10**9]*1000)
dp = [10**9] * (N+1000)
 
dp[0] = 0
 
for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]))
 
print(dp[N-1])

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

int main(){
   int n;  
   cin >> n;
  vector<int> v(n);
  
  rep(i,n){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
    
  double ans;
  ans = v[0];
  for (int i = 1; i < (n); ++i){
    ans = (ans+v[i])/2;
  };
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
string a;
int main(){
  int n;
  cin>>n;
  cin>>a;
  int x=0;
  for(int i=0;i<n-2;++i){
    if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C'){
      x+=1;
    }
  }
  cout<<x;
  

}

Measured memory_bytes: 256
def solve(k, s)
  count = 0
  nums = (0..k).to_a.sort.reverse
  nums.each do |i|
    if i <= s
      nums.each do |j|
        count += 1 if i + j <= s && s - i - j <= k
      end
    end
  end
  count
end

k, s = gets.strip.split.map(&:to_i)
puts solve(k, s)


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const int INF = 1001001001;
const double pi = acos(-1);

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<int> vec(1000000 + 1, 0);
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++)
    {
        if (vec[a[i]] == 0)
        {
            for (int j = a[i]; j <= a.back(); j += a[i])
            {
                vec[j]++;
            }
        }
        else
        {
            vec[a[i]]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (vec[a[i]] == 1)
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7956
def main(nums)
  size = nums.size

  l, r = 0, 0
  xor, sum = nums.first, nums.first
  count = 1

  down = false
  loop do
    if down
      num = nums[l]
      xor = xor ^ num
      sum -= num
      l += 1
    else
      break if r + 1 >= size
      num = nums[r + 1]
      xor = xor ^ num
      sum += num
      r += 1
    end

    if xor == sum
      count += r - l + 1
      down = false
    else
      down = true
    end
  end

  count
end

_ = gets.to_i
nums = gets.split(' ').map(&:to_i)
puts main(nums)

Measured memory_bytes: 17420
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


vbool memo(1001);

int main() {
	
	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================
	

	int N;
	cin >> N;

	string S;
	cin >> S;

	int sizeS = S.size();

	for (int i = 000; i <= 999; i++) {
		vint n(3);
		n[0] = i / 100;
		n[1] = (i / 10) % 10;
		n[2] = i % 10;

		int check = 0;

		for (int keta = 0; keta < sizeS; keta++) {
			if (n[check] == (int)S[keta] - 48) {
				check++;
				if (check == 3) {
					memo[i] = true;
					break;
				}

			}

		}


	}

	int ans = 0;
	for (int i = 0; i < 1000; i++) {
		ans += memo[i];

	}

	cout << ans;

}




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

int main()
{
    ll a,b,n;
    cin>>a>>b>>n;

    if(n<b) {
        cout<<floor((a*n)/b);
    }
    else{

        cout<<floor((a*(b-1))/b);

    }
    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const string YES = "YES";
const string NO = "NO";

ll calc_num_a(const vector<ll>& v, ll l, ll r){
    if(l >= r || v.size() == 0){ return 0; }
    r = min((ll)v.size(), r);
    ll ret = v.at(r - 1);
    if(l > 0){
        ret -= v.at(l - 1);
    }
    return ret;
}

bool solve(ll na, ll nb, ll ma, ll mb){
    ll n3 = (na - nb) % 3;
    if(n3 < 0){ n3 += 3; }

    ll m3 = (ma - mb) % 3;
    if(m3 < 0){ m3 += 3; }

    return n3 == m3;
}

int main(){
    string s, t;
    cin >> s >> t;
    vector<ll> cs(s.size(), 0), ct(t.size(), 0);

    REP(i, s.size()){
        cs.at(i) = s.at(i) == 'A';
        if(i > 0){ cs.at(i) += cs.at(i - 1); }
    }

    REP(i, t.size()){
        ct.at(i) = t.at(i) == 'A';
        if(i > 0){ ct.at(i) += ct.at(i - 1); }
    }

    ll q;
    cin >> q;
    REP(i, q){
        ll ai, bi, ci, di;
        cin >> ai >> bi >> ci >> di;
        const ll s_na = calc_num_a(cs, ai - 1, bi);
        const ll s_nb = bi - ai + 1 - s_na;

        const ll t_na = calc_num_a(ct, ci - 1, di);
        const ll t_nb = di - ci + 1 -t_na;
        if(solve(s_na, s_nb, t_na, t_nb)){
            cout << YES << endl;
        }else{
            cout << NO << endl;
        }
    }

    return 0;
}


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

double a[3001];
double dp[3001];
int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  memset(dp,0,sizeof(dp));
  dp[0]=1.0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j>=0;j--){
      dp[j] = (j==0?0:dp[j-1]*a[i])+dp[j]*(1-a[i]);
    }
  }
  double ans = 0.0;
  for(int i=0;i<=n;i++){
    int j=n-i;
    if(i>j){
      ans+=dp[i];
    }
  }
  printf("%.10lf\n",ans );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int inf = 5e18;  
const int mod = 1e9+7;
const int mod1 = 5e18;
const int nax = 2005;
int s,dp[nax];
int calc(int req)
 {
  if(req < 3)
     return 0;
  if(req == 3)
     return 1;
  if(dp[req] == -1)
     {
      int now = 0;
      loop(i,3,req+1)
       {
        if(req - i < 3)
        {
           now++;
           now %= mod;
           break;
        }
        else
        {
           now += calc(req - i);
           now %= mod;
        }
       }
      dp[req] = now;
     }
  return dp[req];
 }
void solve()
 {
  cin>>s;
  memset(dp,-1,sizeof dp);
  int ans = calc(s);
  cout<<ans;
 } 
int32_t main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
 // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
} 

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n,x,G[200005],h[200005];

void Upd(int x,ll d) {
	while (x<=2e5) {
		G[x]=max(G[x],d);
		x+=(x & -x);
	}
}

ll Get(int x) {
	ll res=0;
	while (x>0) {
		res=max(res,G[x]);
		x-=(x & -x);
	}
	return res;
}

main () {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>h[i];
	for (int i=1; i<=n; i++) {
		cin>>x;
		Upd(h[i],x+Get(h[i]-1));	
	}
	cout<<Get(n)<<endl;
}

Measured memory_bytes: 3328
def resolve():
    n = int(input())
    d = list(map(int, input().split()))
    m = int(input())
    t = list(map(int, input().split()))
    dt, dd = dict(), dict()
    for l, dc in zip([d, t], [dd, dt]):
        for ti in l:
            if ti in dc:
                dc[ti] += 1
            else:
                dc[ti] = 1
    print("YES" if all(k in dd and dd[k] >= v for k, v in dt.items()) else "NO")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 56672
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back

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

	int h, w;
	cin >> h >> w;
	char a[h][w] = {};
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			cin >> a[i][j];
		}
	}

	vector<pair<int, int>> ci[w], ri[h];
	int r[h] = {}, c[w] = {};
	int l1, r1;
	for (int i = 0; i < h; ++i)
	{
		int j = 0, max = 0, c1 = 0, s;
		for(; j < w; ++j)
		{
			s = j;
			c1 = 0;
			while(j < w && a[i][j] == '.')
			{
				c1++;
				j++;
			}
			ri[i].pb({s, j - 1});		
		}
	}

	for (int i = 0; i < w; ++i)
	{
		int j = 0, s = 0, max = 0, c1 = 0;
		for(; j < h; ++j)
		{
			s = j;
			c1 = 0;
			while(j < h && a[j][i] == '.')
			{
				c1++;
				j++;
			}
			ci[i].pb({s, j - 1});
		}

	}

	// for (int i = 0; i < h; ++i)
	// {
	// 	cout << r[i] << " ";
	// for(auto e : ri[i])
	// 	cout << e.ff << " " << e.ss << "\n";
	// }

	// cout << "\n";
	// for (int i = 0; i < w; ++i)
	// {
	// 	cout << c[i] << " ";
	// for(auto e : ci[i])
	// 	cout << e.ff << " " << e.ss << "\n";
	// }
	// cout << "\n";
	ll max = 0, k;
	for (int i = 0; i < h; ++i)
	{
		for(auto e1 : ri[i])
		{
			for(int j = e1.ff; j <= e1.ss; ++j)
			for(auto e2 : ci[j])
			{
				if(e2.ff <= i && e2.ss >= i)
				{
					k = e2.ss - e2.ff + e1.ss - e1.ff + 1;
					if(k > max)
						max = k;
				}
			}
		}

	}
	// cout << r[2] << " " << c[1] << "\n";	
	cout << max;
	return 0;
}

Measured memory_bytes: 68352
#include<iostream>
using namespace std;
int main(){
  string s;
  bool memo[26] = {true};
  cin >> s;
  for(int i=0;i<26;i++) memo[i] = true;
  for(int i=0;i<s.size();i++){
    memo[s.at(i) - 'a'] = false;
  }
  for(int i=0;i<26;i++){
    if(memo[i]){
       cout << (char)(i+'a') << endl;
       return 0;
    }
  }
  cout << "None" << endl;
}


Measured memory_bytes: 512
n = input()
if len(n) == 1:
    print(n)
    exit()
if n == n[0] + "9" * (len(n) - 1):
    print(int(n[0]) + 9 * (len(n) - 1))
    exit()
print(int(n[0]) - 1 + 9 * (len(n) - 1))

Measured memory_bytes: 3060
N = int(input())
n = N
m = N ** 0.5
L = []
i = 3

print(str(N) + ': ', end = '')

while n%2 == 0:
    n = n/2
    L.append(2)

while i <= m:
    while n%i == 0:
        n = n/i
        L.append(i)
    i += 2

if n not in L:
    L.append(int(n))  

if 1 in L:
    L.remove(1)

if len(L) == 0:
    L.append(N)

print(' '.join(map(str, L)))



Measured memory_bytes: 5640
n = int(input())

if (n>=400 and n<=599):
    print("8 ")
elif (n>=600 and n<=799):
    print("7 ")
elif (n>=800 and n<=999):
    print("6 ")
elif (n>=1000 and n<=1199):
    print("5 ")
elif (n>=1200 and n<=1399):
    print("4 ")
elif (n>=1400 and n<=1599):
    print("3 ")
elif (n>=1600 and n<=1799):
    print("2 ")
elif (n>=1800 and n<=1999):
    print("1")


Measured memory_bytes: 9112
#include <stdio.h>

int main(void){
  int i,j,n,m,cn;
  char c,s[5]={'S','H','C','D','\0'};
  static int card[4][13];
  scanf("%d\n",&n);

  for(i=0;i<n;i++){
    scanf("%c %d\n",&c,&m);
    for(j=0;j<4;j++)
      if(s[j]==c)
        card[j][m-1]=1;
  }
  
  for(i=0;i<4;i++)
    for(j=0;j<13;j++)
      if(card[i][j]==0)
        printf("%c %d\n",s[i],j+1);

  return 0;
}
    



Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
int N;
int A[123456];
int main(){
  LL sum=0;
  cin>>N;for(int i=0;i<N;++i){cin>>A[i];sum+=A[i];}
  sort(A,A+N);
  LL ans=sum;
  for(int i=0;i<N;i+=2){
    if(i+1<N){
      A[i]=-A[i];
      A[i+1]=-A[i+1];
      sum+=A[i]*2;
      sum+=A[i+1]*2;
      ans=max(sum,ans);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
def read_input(trans=int):
    return list(map(trans, input().split()))


N, K = read_input()
A = read_input()
K = min(K, 41)

for _ in range(K):
    B = [0]*N
    for i in range(N):
        start = max(i-A[i], 0)
        end = min(i+A[i], N-1)

        B[start] += 1
        if end+1 < N:
            B[end+1] -= 1
    for i in range(1, N):
        B[i] += B[i-1]
    A = B.copy()


print(" ".join(map(str, A)))


Measured memory_bytes: 172400
s = input()
n = len(s)
l = [0]*(n+1)
r = [0]*(n+1)
for i in range(n):
    if s[i] == "<":
        l[i+1] = l[i] + 1
    if s[~i] == ">":
        r[~(i+1)] = r[~i] + 1
ans = 0
for j in range(n+1):
    ans += max(l[j],r[j])
print(ans)    

Measured memory_bytes: 27308
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int NMAX=1e5+1,INF=1e9+1;
int n,hauteurs[NMAX],dp[NMAX];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	
	for(int i=1;i<=n;i++){
		cin >> hauteurs[i];
	}
	dp[0]=INF;
	for(int i=2;i<=n;i++){
		dp[i]=min( dp[i-1]+abs(hauteurs[i-1]-hauteurs[i]), dp[i-2]+abs(hauteurs[i-2]-hauteurs[i]) );
	}
	
	cout << dp[n] << '\n';

	
	
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;
int main(){
  int n,l;
  cin >> n >> l;
  vector<int> a(n);
  int t=n*2;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(i)if(a[i-1]+a[i]>=l)t=i;
  }
  if(t>n)puts("Impossible");
  else {
    puts("Possible");
    for(int i=1;i<t;i++)cout << i << endl;
    for(int i=n-1;i>=t;i--)cout << i << endl;
  }
  return 0;
} 

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

int main()
{
    int N, K;
    cin >> N >> K;
    bool have[N];
    fill_n(have, N, false);
    for (int i = 0; i < K; i++)
    {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++)
        {
            int treat;
            cin >> treat;
            treat--;
            have[treat] = true;
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (!have[i])
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

struct Edge{
    int to,id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v,int p_color=-1,int parent=-1){
    int k=1;
    for(int i=0;i<g[v].size();i++){
        int u=g[v][i].to;
        int edge_id=g[v][i].id;
        if(u==parent) continue;
        if(k==p_color) k++;
        ans[edge_id]=k;
        k++;
        dfs(u,ans[edge_id],v);
    }
}

int main(){
    int n;
    cin >> n;
    g.resize(n);
    ans.resize(n-1);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back((Edge){b,i});
        g[b].push_back((Edge){a,i});
    }
    dfs(0);
    int m=0;
    for(int i=0;i<n;i++){
        m=max(m,int(g[i].size()));
    }
    cout << m << endl;
    for(int i=0;i<n-1;i++){
        cout << ans[i] << endl;
    }

    return 0;
}




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

//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long

const int MX = 200005;

LL n,m,k;
LL A[MX], B[MX];
LL preA[MX];
LL pre[MX];

int countBooks(LL rem) {
	int ans = 0;
	int low = 1, high = m, mid;
	while(low <= high) {
		int mid = low + (high - low)/2;
		if(pre[mid] <= rem) {
			ans = mid;
			low = mid + 1;
		} else {
			high = mid - 1;
		}
	}
	return ans;
}

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

	preA[0] = 0;
	for(int i=1;i<=n;i++) {
		cin >> A[i];
		preA[i] = preA[i-1] + A[i];
	}

	pre[0] = 0;
	for(int i=1;i<=m;i++) {
		cin >> B[i];
		pre[i] = pre[i-1] + B[i];
	}

	int ans = 0;

	for(int i=0;i<=n;i++) {
		int ret = 0;
		if(preA[i] <= k) {
			LL rem = k - preA[i];
			int books = countBooks(rem);
			ret = i + books;
		}
		ans = max(ans, ret);
	}

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


Measured memory_bytes: 9836
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,k=INTM()
    if k<=a:
        a=a-k
    elif k<=a+b:
        b=b-(k-a)
        a=0
    else:
        a,b=0,0
    print(a,b)
if __name__ == '__main__':
    do()

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

const int INF = 1 << 30;
typedef pair<int, int> P;

int main() {
    int H, W;  cin >> H >> W;
    vector<vector<char>> grid(H, vector<char>(W));
    int BLACK = 0, WHITE = 0;
    for (int i = 0; i < H; ++i) for (int j = 0; j < W; ++j) {
        cin >> grid[i][j];
        if (grid[i][j] == '.') ++WHITE;
        else ++BLACK;
    }

    vector<vector<int>> d(H, vector<int>(W));
    for (int i = 0; i < H; ++i) for (int j = 0; j < W; ++j) d[i][j] = INF;
    d[0][0] = 0;
    vector<int> dx{1, 0, -1, 0}, dy{0, 1, 0, -1};
    queue<P> que;
    que.push(P(0, 0));
    bool ok = false;

    while (!que.empty()) {
        P p = que.front();  que.pop();
        int x = p.first, y = p.second;
        if (x == H - 1 && y == W - 1) {
            ok = true;
            break;
        }
        for (int i = 0; i < 4; ++i) {
            int nx = x + dx[i], ny = y + dy[i];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && grid[nx][ny] == '.' && d[nx][ny] == INF) {
                que.push(P(nx, ny));
                d[nx][ny] = d[x][y] + 1;
            }
        }
    }

    if (ok) {
        cout << WHITE - d[H - 1][W - 1] - 1 << endl;
    } else {
        cout << -1 << endl;
    }
}


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    ll n, k, ans=0, now=0;
    string s;
    cin >> n >> k >> s;
    
    vector<ll> num;
    if(s[0] == '0') num.push_back(0);
    ll tmp = 1;
    frep(i, 1, n-1) {
        if(s[i-1] == s[i]) {
            tmp++;
        }
        else {
            num.push_back(tmp);
            tmp = 1;
        }
    }
    num.push_back(tmp);
    if(s[n-1] == '0') num.push_back(0);

    if((num.size()-1)/2 <= k) ans = n;
    else {
        rep(i, 2*k+1) {
            now += num[i];
        }
        ans = now;
        rep(i, (num.size()-1)/2-k) {
            now -= (num[2*i]+num[2*i+1]);
            now += (num[2*(k+i)+1]+num[2*(k+i)+2]);
            if(ans < now) ans = now;
        }
    }

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

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        ret %= MOD;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count))%MOD;
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}



Measured memory_bytes: 1528
import sys
from collections import defaultdict

sys.setrecursionlimit(1000000)

N, M = map(int, sys.stdin.readline().split())
E = defaultdict(list)

for _ in range(M):
    l, r, d = map(int, sys.stdin.readline().split())
    l -= 1
    r -= 1
    E[l].append((r, d))
    E[r].append((l, -d))

xs = [None] * N

def dfs(i, x):
    xs[i] = x
    mi, ma = x, x
    for j, d in E[i]:
        if xs[j] is None:
            res = dfs(j, x + d)
            if res is None:
                return None
            else:
                mi2, ma2 = res
                mi = min(mi2, mi)
                ma = max(ma2, ma)
        else:
            if xs[j] - x != d:
                return None
    return mi, ma

for i in range(N):
    if xs[i] is None:
        res = dfs(i, 0)
        if res is None:
            break
        else:
            mi, ma = res
            if ma - mi > 1e9:
                break
else:
    print('Yes')
    sys.exit()
print('No')


Measured memory_bytes: 136060
def A(S):
    answer = 0

    if S[1] == 'R':
        answer += 1
        if S[0] == 'R':
            answer += 1
        if S[2] == 'R':
            answer += 1
    elif S[0] == 'R' or S[2] == 'R':
        answer = 1

    return answer

  
S = input()
print(A(S))

Measured memory_bytes: 8980
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int[] a = in.nextIntArray(n);
			int sum = Arrays.stream(a).sum();

			BigInteger now = BigInteger.ONE;
			now = now.or(BigInteger.ONE.shiftLeft(a[0]));
			for (int i = 1; i < n; i++) {
				now = now.or(now.shiftLeft(a[i]));
			}

			for (int i = (sum+1)/2; i <= sum; i++) {
				if (now.testBit(i)) {
					out.println(i);
					return;
				}
			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 228144
#include <stdio.h>
#include <stdlib.h>

int compar(const int *val1, const int *val2) {
    if ( *val1 < *val2 ) {
        return -1;
    } else if ( *val1 == * val2 ) {
        return 0;
    } else {
        return 1;
    }
}

int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  int x[m];
  for(int i = 0; i < m; ++i) scanf("%d",&x[i]);
  qsort(x, m, sizeof(int),(int (*)(const void *, const void *))compar);
  int answer = 0;
  if(m == 1 || n >= m){
    answer = 0;
  }else{
    int deltax[m-1];
    int num = m - n;
    for(int i = 0; i < m - 1; ++i) deltax[i] = x[i+1] - x[i];
    qsort(deltax, m-1, sizeof(int),(int (*)(const void *, const void *))compar);
    for(int i = 0; i < num; ++i) answer += deltax[i];
  }
  printf("%d\n",answer);
  return 0;
}

Measured memory_bytes: 1396
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,p,i,flag=0;
	scanf("%d%d",&a,&b);
	for(i=0;i<=2000;i++)
		if(i*8/100==a&&i*10/100==b)
		{
			flag=1;
			break;
		}
	if(flag==0)
		printf("-1");
	else
		printf("%d",i);
}

Measured memory_bytes: 256
<?php

// 標準入力を一行ずつ配列に代入します
$line = fgets(STDIN); // 標準入力からの入力値を変数に代入
$N = $line;

$x = 0;

//指定数までチェック
for ($i=1 ; $i<$N+1 ; $i=$i+2){
    
    //echo $i."\n";
    
    // 約数チェック
    $yakusu = 0;
    for ($j=1;$j<$i+1;$j++){
        if($i%$j==0){
            $yakusu++;
        }
        if($yakusu==8){
            //echo "約数は８個です\n";
            $x++;
        }
    }
    
}
echo $x;



?>

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k;
	cin>>a>>b>>k;
	if(b-a+1<=2*k){
		for(int i=a;i<=b;i++){
			cout<<i<<endl;
		}
	}else{
		for(int i=0;i<k;i++){
			cout<<a+i<<endl;
		}
		for(int i=k-1;i>=0;i--){
			cout<<b-i<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
/*  Seventeen and we got a dream to have a family           */
/*  A house and everything in between                       */
/*  And then, oh, suddenly we turned twenty-three           */
/*  Now we got pressure for taking our life more seriously  */
/*  We got our dead-end jobs and got bills to pay           */
/*  Have old friends and know our enemies                   */
/*  Now I, I'm thinking back to when I was young            */
/*  Back to the day when I was falling in love              */
/*  He used to meet me on the Eastside                      */
/*  In the city where the sun don't set                     */

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
ll mod=1000000007;

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

ll t=1;
//cin>>t;
while(t--)
{


ll n,m,i,j,k;
cin>>n>>m>>k;
vector<ll>a,b;

a.push_back(0);
for(i=0;i<n;i++){
ll te;
cin>>te;
a.push_back(te);
}

for(i=0;i<m;i++){
ll te;
cin>>te;
b.push_back(te);
}


for(i=1;i<b.size();i++)
b[i]+=b[i-1];

vector<ll>ans;
ll sum=0;
ans.push_back(0);

for(i=0;i<a.size();i++)
{
   ll pu=i;
  sum+=a[i];
 ll ser=k-sum;

 if(b[0]<=ser)
  {
    ll ind=lower_bound(b.begin(),b.end(),ser+1)-b.begin();
     ind--;
   pu+=ind+1;

  }
  if(ser>=0)
   ans.push_back(pu);

}
/*
for(i=0;i<b.size();i++)
cout<<b[i]<<" ";
cout<<endl;

for(i=0;i<ans.size();i++)
cout<<ans[i]<<" ";
cout<<endl;
*/

ll fans=*max_element(ans.begin(),ans.end());

cout<<fans<<endl;

}
return 0;
}








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

// claudio van
int main() {
  int n; scanf("%d", &n);
  int cnt = 0;
  int mx = -1;
  for (int i = 0; i < n; ++i) {
    int h; scanf("%d", &h);
    mx = max(mx, h);
    if (mx == h) {
      cnt++;
    }
  }
  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <assert.h>

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define trace(x) cerr << #x << " = " << x << endl;



/////////////////////////////////////////////
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

///////////////////////////////////////////////////////////////////////
#define int long long

void solve(){

	int n;
	cin>>n;
	int a[n];
	for(int i = 0 ; i < n ; ++i)
		cin>>a[i];
	int ans = 0;
	for(int i = 0 ; i < n ; ++i){

		for(int j = i+1 ; j < n ; ++j){

			for(int k = j+1 ; k < n ; ++k){

				if(a[i]==a[j] || a[j]==a[k] || a[k]==a[i])
					continue;
				if(a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i])
					++ans;
			}
		}
	}

	cout<<ans<<endl;
}
signed main(){
 
    fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t ; ++i)
        solve();
}


Measured memory_bytes: 3652
//??°????????????????±???????????????°??????
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		
		//??°????????????????????????????????°
		boolean flg = true;
		
		//????????????
		int[] score = new int[3];						//????????°???????´?????????????score
		String grade = "";
		
		while(flg) {
			String[] str = br.readLine().split(" ");	//???????????????????????§??????str???????´?
			
			score[0] = Integer.parseInt(str[0]);
			score[1] = Integer.parseInt(str[1]);
			score[2] = Integer.parseInt(str[2]);
			
			if(score[0]==-1 && score[1]==-1 && score[2]==-1) {
				break;
			}
			
			if(score[0] == -1 || score[1] == -1) {
				grade = grade + "F" + "\n";
			}
			else if(80 <= score[0]+score[1]) {
				grade = grade + "A" + "\n";
			}
			else if(score[0]+score[1] < 80 && 65 <=score[0]+score[1]) {
				grade = grade + "B" + "\n";
			}
			else if(score[0]+score[1] < 65 && 50 <=score[0]+score[1]) {
				grade = grade + "C" + "\n";
			}
			else if(score[0]+score[1] < 50 && 30 <=score[0]+score[1]) {
				if(50 <= score[2]) {
					grade = grade + "C" + "\n";
				}
				else
					grade = grade + "D" + "\n";
			}
			else {
				grade = grade + "F" + "\n";
			}
			
		}
		System.out.print(grade);
	}

}

Measured memory_bytes: 24236
import java.util.Scanner;

/**
 * Created by lyc on 2017/10/12.
 */
class Main {
    public static void main(String[] strings) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int total = 0;
        while (N-- != 0) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            total += (r - l) + 1;
        }
        System.out.print(total);
    }
}

Measured memory_bytes: 25704
import sys
import numpy as np

m = 10**9+7

def syuke(n,r):
    ue=1
    sit=1
    r =min(r,n-r)
    for i in range(r):
        ue = (ue*(n-i))%m
        sit = (sit*(i+1))%m
    return(ue*pow(sit,(m-2),m))

n,a,b = map(int,input().split())

syu = 0
if n<3:
    print(0)
    sys.exit()
syu = pow(2,n,m)-1
syu -= syuke(n,a)%m
syu -= syuke(n,b)%m
print(syu%m)

Measured memory_bytes: 12504
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	vector<ll> v;
	v.pb(a);
	v.pb(b);
	v.pb(c);
	sort(all(v));
	cout << v[0]+v[1] << endl;
	return 0;
}

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

int sumofdigits(int x){
  int sum=0;
  while(x>0){
    sum+=x%10;
    x/=10;
  }

  return sum;
}//各桁の和を計算する関数
 
int main() {
  
  int N;

  cin >> N;

  int f = sumofdigits(N);

  if(N%f==0){
 
  cout << "Yes" << endl;

  }

  else{
 
  cout << "No" << endl;

  }
 
  return 0;
}

Measured memory_bytes: 256
#ifdef lolipop
#define _GLIBCXX_DEBUG
#endif

/*
    This ain't a milly rock
    This a money dance
    And my D' ain't hard
    That's a '30 in my pants
*/

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <ctime>
#include <map>
#include <random>
#include <iomanip>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <bitset>
#include <deque>
#include <utility>

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ld long double

using namespace std;

// mt19937 rnd(time(nullptr));

inline void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}


void solve() {
    int n;
    cin >> n;
    set <string> s;
    for(int i = 0; i < n; ++i) {
        string t;
        cin >> t;
        s.insert(t);
    }
    cout << s.size() << '\n';
}

signed main() {
#ifdef lolipop
    freopen("input.txt", "r", stdin);
#else
    fastio();
#endif

    int T = 1;
//    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

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

#define MAX 100005
#define INF INT_MAX

vector< vector<int> > adj;
vector<int> d;

int main(int, char**)
{
    int n;
    cin >> n;

    adj.assign(n, vector<int>());
    d.assign(n,-1);
    int u, k, v;
    rep(i,n) {
        cin >> u >> k; u--;
        rep(j,k) {
            cin >> v; v--;
            adj[u].push_back(v);
        }
    }
    queue<int> q;
    q.push(0);
    d[0] = 0;
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (auto e : adj[v]) {
            if (d[e] != -1) continue;
            d[e] = d[v] + 1;
            q.push(e);
        }
    }
    rep(i,n) {
        cout << i+1 << " " << d[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  vector<long double> x(N);
  vector<long double> y(N);
  vector<int> indices(N);
  for (int i = 0; i < N; ++i) {
    cin >> x[i];
    cin >> y[i];
    indices[i] = i;
  }

  long double total = 0;
  do {
    long double tmp = 0;
    for (int i = 0; i < N - 1; ++i) {
      int index1 = indices[i];
      int index2 = indices[i + 1];
      tmp += sqrt(pow(x[index1] - x[index2], 2) + pow(y[index1] - y[index2], 2));
    }
    total += tmp;
  } while (next_permutation(indices.begin(), indices.end()));

  int c = 1;
  for (int i = 0; i < N; ++i) {
    c *= i + 1;
  }

  cout << fixed << setprecision(15) << total / c << endl;

  return 0;
}

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

namespace ProblemC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var ss = new string[N];
            var isStartB = new bool[N];
            var isEndA = new bool[N];
            var onlyBothTrue = true;
            var insideABCount = 0;
            for (int i = 0; i < N; i++)
            {
                ss[i] = Console.ReadLine();
                for (int j = 0; j < ss[i].Count() - 1; j++)
                {
                    if (ss[i].Substring(j, 2) == "AB")
                        insideABCount++;
                }
                isStartB[i] = ss[i].First() == 'B';
                isEndA[i] = ss[i].Last() == 'A';
                if (isStartB[i] != isEndA[i])
                    onlyBothTrue = false;
            }
            var startBCount = isStartB.Count(x => x);
            var endACount = isEndA.Count(x => x);
            var minStartBEndA = Math.Min(startBCount, endACount);
            if (minStartBEndA == 0)
                Console.WriteLine(insideABCount);
            else if (onlyBothTrue)
                Console.WriteLine(insideABCount + minStartBEndA - 1);
            else
                Console.WriteLine(insideABCount + minStartBEndA);
        }
    }
}


Measured memory_bytes: 19680
#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;
    string s;
    cin>>n>>s;
    int r=0,w=0;
    bool ok=false;
    rep(i,n){
        if(s[i]=='R')r++;
        else w++;
    }
    int cnt1=0,cnt2=0,ans=0;
    rep(i,n){
        if(i<r){
            if(s[i]=='W')cnt1++;
        }
    }
    reverse(s.begin(),s.end());
    rep(i,n){
        if(i<w){
            if(s[i]=='R')cnt2++;
        }
    }
    cout<<min(cnt1,cnt2)<<endl;
}

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

vector<int> KMP(const string& S) {
	int N = S.size();
	vector<int> A(N + 1);
	A[0] = -1;
	for (int i = 0, j = -1; i < N; i++) {
		while (j >= 0 && S[i] != S[j]) {
			j = A[j];
		}
		j++;
		A[i + 1] = j;
	}
	return A;
}

vector<int> StringSearch(const string& S, const string& T) {
	auto A = KMP(T);
	int N = T.size();
	vector<int> res;
	for (int i = 0, j = 0; i < (int)S.size(); i++) {
		while (j >= 0 && S[i] != T[j]) {
			j = A[j];
		}
		j++;
		if (j == N) {
			res.push_back(i - N + 1);
			j = A[j];
		}
	}
	return res;
}

int main()
{
	cin.sync_with_stdio(false);
	string T, P;
	cin >> T >> P;
	for (auto ans : StringSearch(T, P)) {
		printf("%d\n", ans);
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

ll MOD = 1e9+7;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    bool operator==(const mint& m){
        return n == m.n;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if((t & 1) == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

ll N,K;
ll A[300000];

bool isPos(){
    ll c = 0;
    for(int i=0;i<N;i++){
        if(A[i] < 0) c++;
    }
    if(N > c){
        if(N==K) return c%2 == 0;
        return true;
    }
    return K%2 == 0;
}

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> A[i];
    if(isPos()){
        vector<ll> P;
        vector<ll> M;
        for(int i=0;i<N;i++){
            if(A[i]>=0) P.push_back(A[i]);
            else M.push_back(abs(A[i]));
        }
        sort(P.rbegin(),P.rend());
        sort(M.rbegin(),M.rend());
        mint ans(1);
        int s = 0;
        if(K % 2 == 1){
            ans *= mint(P[0]);
            s++;
        }
        vector<ll> t;
        for(int i=0;i+1<M.size();i+=2) t.push_back(M[i]*M[i+1]);
        for(int i=s;i+1<P.size();i+=2) t.push_back(P[i]*P[i+1]);
        sort(t.rbegin(),t.rend());
        for(int i=0;i<(K-s)/2;i++) ans *= t[i];
        cout << ans << endl;
    }else{
        vector<ll> v;
        for(int i=0;i<N;i++) v.push_back(abs(A[i]));
        sort(v.begin(),v.end());
        mint ans(1);
        for(int i=0;i<K;i++) ans *= mint(v[i]);
        cout << mint(0) - ans << endl;
    }
    return 0;
}

Measured memory_bytes: 7976
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;
 vector<vector<int>> v;
 int ans=0;
 int n;
 
 void dfs(int i,int j,int sum){
     if(i==1&&j==n-1){
         ans=max(ans,sum+v[i][j]);
         return;
     }
     if(i>=2)return;
     if(j>=n)return;
     
     dfs(i+1,j,sum+v[i][j]);
     dfs(i,j+1,sum+v[i][j]);
     return;
 }
int main(){
    cin>>n;
   v.resize(2,vector<int>(n));
   rep(i,0,2){
       rep(j,0,n)cin>>v[i][j];
   }
   dfs(0,0,0);
   cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

		int n = readInt(r);
		String[] numArrayStr = r.readLine().split(" ");

		int[] numArrayInt = convertToInt(numArrayStr);

		bubbleSort(numArrayInt);
	}

	public static void bubbleSort(int[] numArrayInt){
		int temp = 0;
		int count = 0;
		boolean flag = true;
		while(flag){
			flag = false;
			for(int i = numArrayInt.length - 1; i > 0; i--){
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			}
		}
		printBlank(numArrayInt);
		System.out.println(count);
	}

	public static int readInt(BufferedReader r) throws Exception{
        return Integer.parseInt(r.readLine());
    }

	public static int[] convertToInt(String[] numArrayStr){
		int[] numArrayInt = new int[numArrayStr.length];
		for(int i = 0; i < numArrayStr.length; i++){
			numArrayInt[i] = Integer.parseInt(numArrayStr[i]);
		}
		return numArrayInt;
	}

	public static void printBlank(int[] numArrayInt){
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i < numArrayInt.length; i++){
			builder.append(numArrayInt[i]);
			builder.append(" ");
		}

		System.out.println(builder.toString().trim());
	}

}

Measured memory_bytes: 24452
#include<iostream>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
const int M = (1e6);
bool p[M];
void isPrime(){
  rep(i,M)p[i] = true;
  p[0] = p[1] = false;
  loop(i,2,M){
    if(p[i])
      for(int j = i + i ; j < M ; j += i)
	p[j] = false;
  }
}
int main(void){
  isPrime();
  int n;
  while(cin>>n){
    int res = 0;
    rep(i,n+1)res += p[i];
    cout<<res<<endl;
  }
}

Measured memory_bytes: 2136
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 3;

int n, A[CMax][CMax], ats;

int main() {
    n = CMax;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            scanf("%d", &A[i][j]);
        }
    }

    for (int i = 0; i < n-1; i++) {
        if (
            A[i][0] - A[i+1][0] != A[i][1] - A[i+1][1] ||
            A[i][1] - A[i+1][1] != A[i][2] - A[i+1][2] ||
            A[0][i] - A[0][i+1] != A[1][i] - A[1][i+1] ||
            A[1][i] - A[1][i+1] != A[2][i] - A[2][i+1]
        ) {
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    sort(h.begin(), h.end());
    ll sum = 0;
    for (int i = n - k - 1; i >= 0; i--) sum += h[i];
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1792