akhauriyash/Code-Regression huggingface dataset:
import math
N = int(input())

d = [0] * N
for i in range(1, math.floor(math.sqrt(N)) + 1):
    for j in range(i, N // i + 1):
        if i == j:
            d[i * j - 1] += 1
        else:
            d[i * j - 1] += 2

print(sum(d) - d[-1])

Measured memory_bytes: 16640
object Main {
  def main(args: Array[String]): Unit = {
    val abc = io.StdIn.readLine().split(" ").map(_.toInt)
    val a = abc(0)
    val b = abc(1)
    val c = abc(2)

    val selfDivisor = if (a <= c && c <= b) 1 else 0
    val count =
      Iterator.iterate(a)(i => i + 1)
        .takeWhile(i => i <= b && i <= c / 2)
        .count(c % _ == 0)

    println(count + selfDivisor)
  }
}

Measured memory_bytes: 44076
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
public:
};

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), ret = 0;
    for(int i = 0; i < n; ++i) ret += s[i] != t[i];
    cout << ret << endl;
}

Measured memory_bytes: 3832
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    else:
        sums = 0
        count = 0
        for i in range(1, n-1):
            for j in range(i+1, n):
                for k in range(j+1, n+1):
                    sums = i + j + k
                    if sums == x:
                        count += 1 
        print(count)

        

           



Measured memory_bytes: 5596
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let a: Vec<u64> = (0..n).map(|_| sc.read()).collect();
    let mut b: Vec<u64> = (0..n).map(|_| sc.read()).collect();

    let mut ans = 0;
    for pos in (0..32).rev() {
        ans <<= 1;
        let t = 1 << pos;
        let t2 = t << 1;
        let mask = t2 - 1;

        b.sort_by_key(|k| (k & mask));

        let mut cur = 0;
        for &a in &a {
            let a = a & mask;
            let i1 = b.binary_search_by_key(&(1 * t * 2 - 1), |&b| {
                let b = b & mask;
                (a + b) * 2
            }).err()
                .unwrap();
            let i2 = b.binary_search_by_key(&(2 * t * 2 - 1), |&b| {
                let b = b & mask;
                (a + b) * 2
            }).err()
                .unwrap();
            let i3 = b.binary_search_by_key(&(3 * t * 2 - 1), |&b| {
                let b = b & mask;
                (a + b) * 2
            }).err()
                .unwrap();
            let count = n - i3 + i2 - i1;
            cur ^= count & 1;
        }
        ans += cur;
    }

    println!("{}", ans);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 11640
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll binarySearch(function<bool(ll)> check, ll ok, ll ng) {
  while ((ok - ng > 1) || (ng - ok > 1)) {
    ll mid = (ok + ng) / 2;
    if (check(mid)) ok = mid;
    else ng = mid;
  }
  return ok;
}

ll N,M;
ll a[100010];
ll sum[100010];
bool Check(ll n){
    ll cnt=0;
    for(ll i=0;i<N;i++){
        cnt+=N-(lower_bound(a,a+N,n-a[i])-a);
    }
    return cnt>=M;
}
int main(){
    cin>>N>>M;
    for(ll i=0;i<N;i++){
        cin>>a[i];
    }
    sort(a,a+N);
    sum[0]=a[0];
    for(ll i=1;i<N;i++){
        sum[i]=sum[i-1]+a[i];
    }
    ll lower=binarySearch(Check,0,INF);
    ll ans=0;
    ll cnt=0;
    for(ll i=0;i<N;i++){
        ll n=upper_bound(a,a+N,lower-a[i])-a;
        if(n-1>=0){
            ans+=sum[N-1]-sum[n-1];
        }else{
            ans+=sum[N-1];
        }
        ans+=(N-n)*a[i];
        cnt+=N-n;
    }
    ans+=(M-cnt)*lower;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
int n;
  cin >>n;
cout << n/3;
return(0);
}


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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define forn(i,n) for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))
#define pb push_back

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

ll max_self(ll &a, ll b){
	a = max(a,b);
}

void solve(){
	int n, w;
	cin >> n >> w;
	// vi val(n), wt(n);
	vll dp(w+1);
	//dp[i] - max val with i weight
	for(int i=0; i<n; i++){
		int weight, value;
		cin >> weight >> value;
		for(int j=w-weight; j>=0; j--){
			max_self(dp[j+weight], dp[j]+value);
		}
	}
	ll ans = 0;
	for(int i=0; i<=w; i++){
		max_self(ans, dp[i]);
	}
	cout << ans << en;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 1024
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
}

const int MX=1e5+10;
int N,K,W; 
int t[MX];
int memo[3000][3000];
int p[3000][3000];
int w[MX],v[MX];

str s,ss; 


int solve(int i, int j){
	if(i==sz(s) || j==sz(ss)) return 0;
	/*if(i==N && r==0) return 0;
	if(i==N) return INF;
	if(memo[i][r]!=-1)return memo[i][r];
	int ans=solve(i+1,r);
	if(r>=v[i]) ans=min(ans,solve(i+1,r-v[i])+w[i]);
	return memo[i][r]=ans;*/

	if(memo[i][j]!=-1) return memo[i][j];
	int ans;
	p[i][j]=0; ans=solve(i+1,j);
	if(solve(i,j+1)>ans) ans=solve(i,j+1),p[i][j]=1;
	if(s[i]==ss[j] && solve(i+1,j+1)+1>ans) ans=solve(i+1,j+1)+1,p[i][j]=2;

	return memo[i][j]=ans;
}

int32_t main(){
   boost;
   IO();

   for(int i=0; i<3000; i++) for(int j=0; j<3000; j++) memo[i][j]=-1;
   /*cin>>N>>W;
   for(int i=0; i<N;i++) cin>>w[i]>>v[i];

   for(int i=100000; i>=0; i--) if(solve(0,i)<=W){cout << i << endl; return 0;}*/

   cin>>s>>ss;
   int x=solve(0,0);
   //cout << x << endl;
	str res;
	int i=0,j=0;
	while(i<sz(s) && j<sz(ss)){
		if(p[i][j]==0) i++;
		else if(p[i][j]==1) j++;
		else{res+=s[i]; i++; j++;}
	}
	cout << res << endl;


   return 0;
}



Measured memory_bytes: 144612
n=int(input())
L=[list(map(int,input().split())) for i in range(n)]
LS=sorted(L,key=lambda x:(-x[1],-x[0]))

d=LS[0][1]
i=0
while d>=0 and i<n:
	d=min(d,LS[i][1])
	d-=LS[i][0]
	i+=1

print('Yes' if d>=0 else 'No')

Measured memory_bytes: 80352
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

a,b = i2()
s = s()
ls = [str(i) for i in range(10)]

for i in range(len(s)):
	if i < a or a < i:
		if s[i] not in ls:
			print("No")
			exit()
	else:
		if s[i] != "-":
			print("No")
			exit()
print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

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

const int mod = 1000000007;

vector<P> mojiv[26];

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

  string s;
  cin >> s;

  rep(i, s.size()) {
    char c = s[i];
    int j = i;
    while(j < s.size() && s[j] == c) {
      j++;
    }
    mojiv[c-'a'].push_back({i, j});
    i = j-1;
  }

  long left = -1;
  long right = -1;
  rep(i, 26) {
    rep(j, mojiv[i].size()) {
      if (mojiv[i][j].second - mojiv[i][j].first > 1) {
        left = mojiv[i][j].first+1;
        right = mojiv[i][j].second;
      }
    }
    rep(j, (int)(mojiv[i].size() - 1)) {
      long mjcnt = mojiv[i][j].second - mojiv[i][j].first + mojiv[i][j+1].second - mojiv[i][j+1].first;
      long allcnt = mojiv[i][j+1].second - mojiv[i][j].first;
      if (mjcnt * 2 > allcnt) {
        left = mojiv[i][j].first + 1;
        right = mojiv[i][j+1].second;
      }
    }
  }

  cout << left << " " << right << endl;
}


Measured memory_bytes: 2872
#include <iostream>

using namespace std;

int main() {
  int n;
  int sum = 0;
  cin >> n;
  int d[n];
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += d[i] * d[j];
    }
  }
  
  cout << sum << endl;
  return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
    int X, N;
    cin >> X >> N;
    vector<int> parr(N);
    for (int i = 0; i < N; i++) cin >> parr[i];
    vector<int> narr(200, 0);
    for (int j = 0; j < N; j++) {
        narr[parr[j]] = 1;
    }

    map<int, set<int>> m;
    for (int j = 0; j < narr.size(); j++) {
        if (narr[j] == 0) {
            m[abs(X - j)].insert(j);
        }
    }

    cout << *m.begin()->second.begin() << endl;
    return 0;
}


Measured memory_bytes: 3660
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

vector<vector<char>> arr;
vector<vector<int>> pa;
int n, m;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
void dfs(int a, int b, int p) {
	if(!a || !b || a>n || b>m || arr[a][b]=='#' || ~pa[a][b])
		return;
	pa[a][b] = p;
	for(int i = 0; i < 4; i++)
		dfs(a + dx[i], b + dy[i], p);
}

signed main() {
	EmiliaMyWife

	pair<int,int> s, t;
	cin >> n >> m;
	cin >> s.first >> s.second >> t.first >> t.second;
	arr.resize(n + 1, vector<char>(m + 1));
	pa.resize(n + 1, vector<int>(m + 1, -1));
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> arr[i][j];
	int it = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++)
			if(arr[i][j] == '.' && pa[i][j] < 0)
				dfs(i, j, it++);
	}
	//cerr << "ere ";
	vector<vector<int>> edge(it);
	vector<int> dis(it, INF);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			if(arr[i][j] == '.')
				for(int k = max(1, i-2); k <= min(i+2, n); k++)
					for(int w = max(1, j-2); w <= min(m, j+2); w++)
						if(arr[k][w]=='.')
							edge[pa[i][j]].push_back(pa[k][w]);
	//cerr << "here";
	dis[pa[s.first][s.second]] = 0;
	queue<int> bfs;
	bfs.push(pa[s.first][s.second]);
	while(!bfs.empty()) {
		int a = bfs.front();
		bfs.pop();
		for(int v : edge[a]) {
			if(dis[v] > dis[a] + 1)
				dis[v] = dis[a] + 1, bfs.push(v);
		}
	}
	int ww = pa[t.first][t.second];
	if(dis[ww] == INF)
		cout << "-1\n";
	else
		cout << dis[ww] << '\n';

	return 0;
}


Measured memory_bytes: 46720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod=1000000007;
constexpr ll INF=(1ll<<60);
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int main(){
    string s,t;cin>>s>>t;
    cout<<t<<s<<endl;
    return 0;
}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
//library end
int a,b;
string x="",y="";
signed main(){
    cin>>a>>b;
    if(a==b)puts("Yes");
    else puts("No");
    return 0;
}



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


int main(){
	ios;
	int n,ai;
	cin>>n;
	map<int,int> m;
	
	for(int i=0; i<n; i++){
		cin>>ai;
		m[ai]=i+1;
	}
	for(int i=1; i<=n; i++){
		cout<<m[i]<<" ";
	}
	cout<<'\n';
	return 0;
}



Measured memory_bytes: 5504
(let ((str (read-line)))
  (defun f (n)
    (char= (aref str (1- n)) (aref str (1+ n))))
  (if (and (f (position #\Space str :test #'char=)) (f (position #\Space str :test #'char= :from-end t)))
      (princ "YES")
      (princ "NO")))

Measured memory_bytes: 4448
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
int ans1=0;
int a[50],b[50],c[50],d[50];
int fun1(vector<int>v,int n,int m,int q){
    int ans=0;
    for(int i=0;i<q;i++){
        if(v[b[i]]-v[a[i]]==c[i])ans+=d[i];
    }
    //cout<<ans<<" ";
    return ans;
}
int fun(vector<int>v,int i,int j,int n,int m,int q){
    if(i==n){
        return fun1(v,n,m,q);
    }
    int ans=0;
    for(int k=j;k<=m;k++){
        v.push_back(k);
        ans=max(ans,fun(v,i+1,k,n,m,q));
        v.pop_back();
    }
    
    return ans;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,q;
    cin>>n>>m>>q;
    for(int i=0;i<q;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;b[i]--;
    }
    vector<int>v;
    cout<<fun(v,0,1,n,m,q);
    return 0;
}

Measured memory_bytes: 3620
inputted = list(map(int, input().split()))
AB = BA = inputted[0]
BC = CB = inputted[1]
AC = CA = inputted[2]

answer = min([
    AB + BC,
    AC + CB,
    BA + AC,
    BC + CA,
    CA + AB,
    CB + BA,
])

print(answer)


Measured memory_bytes: 2940
#include <stdio.h>
long long p = 998244353;
long long a, b, c, d;
long long x[3001][3001];
int main() {
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	x[a][b] = 1;
	for (long long i = a + 1; i <= c; i++) {
		x[i][b] = x[i - 1][b] * b % p;
	}
	for (long long i = b + 1; i <= d; i++) {
		x[a][i] = x[a][i - 1] * a % p;
	}
	for (long long i = a + 1; i <= c; i++) {
		for (long long j = b + 1; j <= d; j++) {
			x[i][j] = (x[i - 1][j] * j + x[i][j - 1] * i) % p;
			x[i][j] -= x[i - 1][j - 1] * (i - 1) * (j - 1) % p;
			x[i][j] += p;
			x[i][j] %= p;
		}
	}
	printf("%lld\n", x[c][d]);
}

Measured memory_bytes: 72028
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,k;cin>>n>>k;
    string s;cin>>s;
    vin zero,one;
    int res=0;char tmp=s[0];
    rep(i,n){
        if(s[i]!=tmp){
            if(tmp=='0')zero.push_back(res);
            else one.push_back(res);
            tmp=s[i];
            res=0;
        }
        res++;
    }
    if(s[n-1]=='0')zero.push_back(res);
    else one.push_back(res);
    if(zero.size()<=k){
        cout<<n<<endl;
        return 0;
    }
    int zs=zero.size();
    int os=one.size();
    vin upright(zs+1),handstand(os+1);
    upright[0]=0;handstand[0]=0;
    if(zs==os&&s[0]=='0'){
        reverse(all(s));
        reverse(all(zero));
        reverse(all(one));
    }
    rep(i,zs)upright[i+1]=upright[i]+zero[i];
    rep(i,os)handstand[i+1]=handstand[i]+one[i];
    int ans=0;
    if(zs==os){
        rep(i,os-k)ans=max(ans,upright[i+k]-upright[i]+handstand[i+k+1]-handstand[i]);
        ans=max(ans,upright[zs]-upright[zs-k]+handstand[os]-handstand[os-k]);
    }
    else{
        if(s[0]=='0'){
            ans=upright[k]+handstand[k];
            rep(i,os-k)ans=max(ans,upright[i+k+1]-upright[i+1]+handstand[i+k+1]-handstand[i]);
            ans=max(ans,upright[zs]-upright[zs-k]+handstand[os]-handstand[os-k]);
        }
        else rep(i,os-k)ans=max(ans,upright[i+k]-upright[i]+handstand[i+k+1]-handstand[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) ((x)&(-x))
#define X first
#define Y second
#define lc o<<1
#define rc o<<1|1
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 100000+10;
const int maxm = 2000+10;
const int mod = 1e9+7;
const double eps = 1e-8;
int a[maxn];
int main() {
#ifdef local
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n; cin>>n;
    int ans=0,res=0;
    cin>>a[1];
    for (int i=2;i<=n;i++) {
        cin>>a[i];
        if (a[i]<=a[i-1]) res++; else {
            ans=max(ans,res);
            res=0;
        }
    }
    ans=max(ans,res);
    cout<<ans<<"\n";
    return 0;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;

typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int n;

int calc(int x){
    if(x%3 == 0 or x%5 == 0)return 0;
    else return x;
}

int main(){
    cin >> n;
    vector<int>v(n);
    ll ans = 0;
    for(int i = 0; i < n+1;i++){
        ans += calc(i);
    }
    cout << ans << endl;

}


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


#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
//#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
/*
ll a[110000];
ll fac[110000], finv[110000], inv[110000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 110000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll asum[110000];
main(){
  ll n,k,ans=0;
  cin>>n>>k;
  rep(i,0,n)cin>>a[i];
  sort(a,a+n);
  rep(i,1,n)asum[i]=asum[i-1]+a[i];
  rep(i,k-1,n)ans+=COM(i,k-1);
  
}*/

int main() {
    int n,m;
    cin>>n>>m;
    vector<int> p(m);
    vector<string> s(m);
    for(int i=0; i<m; i++) cin>>p[i]>>s[i];
    map<pair<int,string>,int> mp;
    int ac=0,wa=0;
    for(int i=0; i<m; i++){
        if(s[i]=="AC"&&mp[make_pair(p[i],"AC")]==0){
            ac++;
            wa+=mp[make_pair(p[i],"WA")];
            mp[make_pair(p[i],"AC")]++;
        }
        else mp[make_pair(p[i],s[i])]++;
    }
    cout<<ac<<" "<<wa<<endl;
}

Measured memory_bytes: 28032
#include <iostream>
#include <cmath>
#define ll unsigned long long
using namespace std;


int main() {
    int x, n, p[110], arr[55];

    cin >> x >> n;

    for (int i = 0; i < 55; ++i) {
        arr[i] = 0;
    }

    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        arr[abs(x - p[i])] |= (p[i] - x >= 0) * 2 + (p[i] - x <= 0);
    }

    int i;
    for (i = 0; arr[i] == 3; ++i) 
        ;

    int res = x - i;
    if (arr[i] & 1) {
        res = x + i;
    }

    cout << res << endl;
}


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

vector <int> p(0);

void Prime(int n){

  bool flg[50000];
  int indx=2;

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

  while(indx<n){
    flg[indx]=1;
    p.push_back(indx);
    for(int i=2; i*indx<n; i++){
      flg[indx*i]=1;
    }

    while(flg[indx]==1 && indx<n)indx++;

  }
}

int main(){

  int n;
  int sum;

  Prime(50000);

  while(cin >> n,n){

    sum = 0;

    

      for(int i=0; i<(int)p.size(); i++){
	if(p[i]>=n)break;
	
	if( binary_search(p.begin()+i , p.end() , n-p[i])==true)sum++;

      }

    cout << sum << endl;
	  

    }


  return 0;
}

Measured memory_bytes: 1316
n=int(input())
arr=list(map(int,input().split()))
cnt=[0]*(10**5+1)
ans=0
for i in range(n):
  if arr[i]<=10**5:
    cnt[arr[i]]+=1
  else:
    ans+=1
for i in range(1,10**5+1):
  if cnt[i]==0:
    continue
  elif cnt[i]==i:
    continue
  elif cnt[i]>i:
    ans+=cnt[i]-i
  else:
    ans+=cnt[i]
print(ans)

Measured memory_bytes: 14692
#include <iostream>
#include <cctype>
#include <vector>
#include <algorithm>
using namespace std;
int expr(string s,int& i);
int number(string& s,int& i);

int main(void)
{
  int n;
  cin >> n;
  
  for(int i=0;i<n;i++){
    string str;
    cin >> str;
    int j=0;
    cout << expr(str,j) << endl;

  }
}

int expr(string s,int& i)
{
  i++;
  vector<int> v;
  if(isdigit(s[i])){
    int k=number(s,i);
    i++;
    return k/2+1;
  }
  else{
    while(s[i]=='['){
      v.push_back(expr(s,i));
    }

    i++;
  
  
    sort(v.begin(),v.end());
    int suuji=0;
    for(int i=0;i<=(v.size()/2);i++){
      suuji += v[i];
    }
  
    return suuji;
  }

}

int number(string& s,int& i){
  int n = s[i++] - '0';
  while(isdigit(s[i]))n=n*10+s[i++]-'0';
  return n;
}

Measured memory_bytes: 1324
# まず55555以下の素数っていくつあるん？->5637個あった
# 「どの異なる5個を選んでも」がむずい これがなければNの偶奇で2をとるかどうかがわかりそうだけど（？）
#  (30分ほど考えるがまったく無理 1byteすら書けない)
# （解説配信みる）（残り5分ほどでDを解説してるの草）
# （配信の解説を見てめちゃくちゃデカい声出た）（脱帽）（拍手）
n = int(input())
primes = []


def isprime(x):
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            return False
    return True


for i in range(2, 55555 + 1):
    if isprime(i) and str(i)[-1] == "1":
        primes.append(i)

print(" ".join(list(map(str, (primes[:n])))))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
const int maxn=3000;
typedef long long ll;
ll mod,f[maxn+5],s[maxn+5][maxn+5],c[maxn+5][maxn+5],pw[maxn+5],pw1[maxn+5];
int n;
ll Pow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
int main()
{

    scanf("%d%lld",&n,&mod);
    c[0][0]=1;
    for(int i=1;i<=n;++i)
    {
        c[i][0]=1;
        for(int j=1;j<=i;++j) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
    }
    for(int i=0;i<=n;++i) s[i][0]=1;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=i;++j) s[i][j]=(s[i-1][j-1]+(j+1)*s[i-1][j]%mod)%mod;
   pw[0]=1;
   pw1[0]=1;
   for(int i=1;i<=n;++i) pw[i]=pw[i-1]*2%mod;
   for(int i=1;i<=n;++i) pw1[i]=pw1[i-1]*2%(mod-1);
    for(int i=0;i<=n;++i)
        for(int j=0;j<=i;++j)
            f[i]=(f[i]+s[i][j]*Pow(pw[n-i],j,mod)%mod*Pow(2LL,pw1[n-i],mod)%mod)%mod;

    //for(int i=0;i<=n;++i) printf("%d : %lld\n",i,f[i]);
    ll ans=0;
    for(int i=0;i<=n;++i)
    {
        ll cnt=c[n][i]*f[i]%mod;
        if(i&1) cnt=-cnt;
        ans=(ans+cnt)%mod;
    }
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 139648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int D, G; cin >> D >> G;
    vector<int> prob(D), bonus(D);
    for (int i = 0; i < D; i++) {
        cin >> prob[i] >> bonus[i];
        bonus[i] = bonus[i] / 100;
    }
    G = G / 100;

    int tmp, cnt;
    int ans = inINF;
    int m;
    for (int i = 0; i < (1<<D); i++) {
        tmp = 0; cnt = 0;
        for (int j = 0; j < D; j++) {
            if(i & (1<<j)){
                tmp += prob[j] * (j+1);
                tmp += bonus[j];
                cnt += prob[j];
            }
            else{
                m = j; //立っていない最大のビットをmに入れる
            }
        }
        if(G <= tmp + (prob[m]-1) * (m+1)){
            if(G > tmp){
                cnt += (G - tmp - 1)/(m+1) + 1;
            }
            ans = min(ans, cnt);
        }
    }
    printf("%d\n", ans);


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

bool compare_by_greater_y(pair<int,int>a, pair<int,int>b){
    if(a.second!=b.second) return a.second>b.second;
    else return a.first>b.first;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<P> r(n), b(n);
    vector<bool> rf(n);
    rep(i, n) {
        int x, y; cin >> x >> y;
        r[i] = P(x, y);
        rf[i] = 0;
    }
    sort(ALL(r), compare_by_greater_y);
    rep(i, n) {
        int x, y; cin >> x >> y;
        b[i] = P(x, y);
    }
    sort(ALL(b));
    int ans = 0;
    rep(i, n) {
        rep(j, n) {
            if (!rf[j] && r[j].first<b[i].first && r[j].second<b[i].second) {
                ans++;
                rf[j] = 1;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	string ans;
	cin >> ans;
	int count = 0;
	int len = ans.size();
	while (n--) {
		bool flag = false;
		string s;
		cin >> s;
		for (int j = 1; j < 50; j++) {
			for (int i = 0; i < 100; i++) {
				bool match = true;
				int cnt = 0;
				for (int k = i; cnt < len; k += j) {
					if (k >= s.size()) break;
					if (s[k] != ans[cnt]) {
						match = false;
						break;
					}
					cnt++;
				}
				if (match && cnt == len) {
					flag = true;
				}
			}
		}
		if (flag) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n;
P p[100005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		ll x,l;
		scanf("%lld%lld",&x,&l);
		p[i]=P(x-l,x+l);
	}
	sort(p,p+n);
	int ans=1;
	int prev=0;
	for(int i=1;i<n;i++){
		if(p[prev].second<=p[i].first){
			ans++;
			prev=i;
		}else{
			if(p[prev].second>p[i].second){
				prev=i;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1792
N = int(input())
H = list(map(int, input().split()))
M = max(H)

ans = 0
for m in range(1, M + 1):
    i = 0
    while i < N:
        if H[i] >= m:
            ans += 1
            while H[i] >= m:
                i += 1
                if i >= N:
                    break
        else:
            i += 1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N);
    ll sum = 0;
    vec<ll> S(N+1);
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
        S[i+1] = S[i]+A[i];
    }
    ll ans = 1e18;
    for(int i=0;i+1<N;i++){
        ans = min(ans,abs(S[i+1]-(sum-S[i+1])));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 6248
s=list(input())
n=len(s)
if n==1:
    print("YES")
    exit()
if len(set(s))==2 and n==2:
    print("YES")
    exit()
if len(set(s))<3:
    print("NO")
    exit()
    
x,y,z=s.count("a"),s.count("b"),s.count('c')
if abs(x-y)>1 or abs(y-z)>1 or abs(z-x)>1:
    print("NO")
else:
    print("YES")


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

tmp = float('inf')
ans = 0
for i, x in enumerate(H):
    avg_tmp = T - x * .006
    if abs(A - tmp) > abs(A - avg_tmp):
        tmp = avg_tmp
        ans = i+1

print(ans)


Measured memory_bytes: 3060
#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

int main() {
	int N, K; cin >> N >> K;
	string S; cin >> S;
	S[K - 1] += 32;
	cout << S;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long N;
  cin >> N;
  
  vector<int> n(1,1);
  for(long i=2; i<=N/i; i++){
    if(N%i!=0) continue;
    N/=i;
    n.push_back(i);
    i--;
  }
  n.push_back(N);
  int s=n.size(), ans=11;
  for(int i=0; i<(2<<s); i++){
    int k=i;
    long a=1, b=1;    
    for(int j=0; j<s; j++){
      if(k%2==0){
        a*=n.at(j);
      }
      else{
        b*=n.at(j);
      }
      k/=2;
    }
    long x=a, y=b;
    int fx=1, fy=1;
    for(int k=0; k<fx; k++){
      x/=10;
      if(x==0) break;
      fx++;
    }
    for(int k=0; k<fy; k++){
      y/=10;
      if(y==0) break;
      fy++;
    } 
    int fz=max(fx,fy);
    ans=min(ans,fz);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue> 
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
//#define int LL
#define db double
using namespace std;
const int N   = 2e5+233;
//const int mod = ;
const int INF =numeric_limits<int >::max();
#define For(n) for (int i=1;i<=n;++i)
#define rep(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

int n,a[N],pos[N],b[N],k;

signed main()
{
	read(n);
	rep(i,1,n) read(a[i]),b[i]=a[i];
	sort(b+1,b+1+n);
	k=n/2;
	if (b[k]==b[k+1])
	{
		rep(i,1,n) printf("%d\n",b[k]);
		return 0;
	}
	rep(i,1,n) if (a[i]<=b[k]) printf("%d\n",b[k+1]);else printf("%d\n",b[k]);
	return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll H, W, A, B;
  std::cin >> H >> W >> A >> B;
  vvi ans = vv(H, W, 0, int);
  for(int i=0;i<=H;i++){
    if((i==B)||(H-i==B)){
      for(int j=0;j<i;j++){
        for(int l=0;l<W;l++) ans[j][l] = (l<A?1:0);
      }
      for(int j=i;j<H;j++){
        for(int l=0;l<W;l++) ans[j][l] = (l<A?0:1);
      }
      for(int j=0;j<H;j++){
        for(int l=0;l<W;l++) std::cout << ans[j][l];
        std::cout << '\n';
      }
      return 0;
    }
  }
  std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 5120
#include <stdio.h>
#include <stdlib.h>
int compare( const void * a, const void * b){ return *( int *)a - *( int *)b; }
int search( int *a, int length, int key ){
  int low = 0, high = length - 1;
  while( 1 ){
    if( low > high ) return 0;
    int mid = low + ( high - low ) / 2;
    if( a[ mid ] < key ){
      low = mid + 1;
      continue;
    }
    else if( a[ mid ] == key ) return 1;
    else {
      high = mid - 1;
      continue;
    }
  }
}

int main( void ){
  int n;
  scanf("%d\n", &n );
  int *s = ( int * ) malloc ( n * sizeof( int ) );
  for( int i = 0; i < n; i ++ )
    scanf("%d", s + i );

  qsort( ( void * )s, n, sizeof( int ), compare );

  int q;
  scanf("%d\n", &q );
  int count = 0;
  for( int i = 0; i < q; i ++ ){
    int t;
    scanf("%d", &t );
    count += search( s, n, t );
  }
  printf( "%d\n", count );
  return 0;
}







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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --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; }

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

const int MAX = 200005;
const ll INF = 1001001001001001001;
const int MOD = 1000000007;

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

    vector<int> A(N+1);
    for (int &i : A) cin >> i;

    if (N == 0) {
        if (A[0] != 1) {
            puts("-1");
        } else {
            puts("1");
        }
        return 0;
    }

    if (N == 1) {
        if (A[0] == 0) {
            if (A[1] == 1) {
                puts("2");
            } else if (A[1] == 2) {
                puts("3");
            } else {
                puts("-1");
            }
        } else {
            puts("-1");
        }
        return 0;
    }

    if (A[0] != 0) {
        puts("-1");
        return 0;
    }
 
    vector<ll> right(N+2);
    repr(i, N+1) right[i] = right[i+1] + A[i];

    vector<ll> left(N+1, INF);
    left[0] = 1;
    rep(i, N) {
        if (left[i] - A[i] <= 0) {
            puts("-1");
            return 0;
        }
        left[i+1] = (left[i] - A[i]) * 2;
        if (left[i+1] > INF) break;
    }
  
  if (left[N] < A[N]) {
    puts("-1");
    return 0;
  }

    ll ans = 0;
    rep(i, N+1) {
        ans += min(left[i], right[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 5048
s = input()
sl = list(s)

slen = len(sl)
ans = 1

second = int((slen - 1) / 2)
third = int((slen + 3) / 2)

for i in range(slen):
    if (sl[i] == sl[-1 - i]):
        continue
    else:
        ans = 0

if (ans == 1):
    for i in range(second):
        if (sl[i] == sl[second - i - 1]):
            continue
        else:
            ans = 0

j = -1
if (ans == 1):
    for i in range(third, slen):
        j = j + 1
        if (sl[i - 1] == sl[-1 - j]):
            continue
        else:
            ans = 0

if (ans == 1):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
lines = $stdin.read
array = lines.split("\n")

Node = Struct.new(:u, :k, :v, :visited)

class Graph

  attr :nodes, :d, :f

  def initialize(n)
    @nodes = Array.new(n){ Node.new }
    @d = Array.new(n)
    @f = Array.new(n)
  end

  def set_graph_node(u, k, v)
    @nodes[u-1].u = u
    @nodes[u-1].k = k
    @nodes[u-1].v = v
    @nodes[u-1].visited = false
  end

  def dfs(start = 0, count = 1)

    # puts "visit = #{@nodes[start].to_s}, count = #{count}"
    @nodes[start].visited = true
    @d[start] = count
    count = count + 1

    for i in @nodes[start].v
      count = dfs(i-1, count) unless @nodes[i-1].visited
    end
    # puts "visited = #{@nodes[start].to_s}, count = #{count}"

    @f[start] = count
    count = count + 1
    count
  end
end

N     = array[0].to_i
graph = Graph.new(N)

for i in 1...array.length
  seps = array[i].split(" ")
  u = seps.drop(0).first.to_i
  k = seps.drop(1).first.to_i
  v = seps.drop(2).map(&:to_i)
  graph.set_graph_node(u, k, v)
end

# puts "Trace all nodes !"
# graph.nodes.each do |node|
#   puts node.to_s
# end

# puts ""
# puts "any? ==> #{graph.nodes.any?{|n| n.visited == false }}"

start, count = 0, 1

while graph.nodes.any?{|n| n.visited == false}
  start = graph.nodes.find_index{|n| n.visited == false }
  count = graph.dfs(start, count)
end

# puts "d #{graph.d.to_s}"
# puts "f #{graph.f.to_s}"

1.upto(N).each do |n|
  puts "#{n} #{graph.d[n-1]} #{graph.f[n-1]}"
end

Measured memory_bytes: 8904
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (x, t) = (v[0], v[1]);
    println!("{}", max(0, x - t));
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

using namespace std;
#define ll long long
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int inf = 1e9 + 9;
const ll linf  = 1ll * inf * inf;
const int N = 500000 + 7;
const int M = 30;
const int multipleTest = 0;
const double pi = acos(-1);

int a[N];
int n;

vii b;

void solve() {
    cin >> n;
    rep(i, 0, n) {
        scanf("%d", a + i);
        b.push_back({a[i], i});
    }
    sort(b.begin(), b.end());

    rep(i, 0, n) {
        if (i < n / 2) a[b[i].second] = b[n / 2].first;
        else a[b[i].second] = b[n / 2 - 1].first;
    }

    rep(i, 0, n) printf("%d\n", a[i]);
}

int main() {
#ifdef _LOCAL_
    freopen("in.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
#endif
    int Test = 1;
    if (multipleTest) {
        cin >> Test;
    }
    for(int i = 0; i < Test; ++i) {
        //		printf("Case #%d: ", i + 1);
        solve();
    }
#ifdef _LOCAL_
    cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}


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

#pragma region segmenttree
template <typename T, typename F>
struct SegmentTree {
    int N;
    const int sz;
    const T ID;
    const F f;
    vector<T> cbt;
    SegmentTree(int n, T ID, F func) : sz(n), ID(ID), f(func) { init(sz); }
    SegmentTree(vector<T> V, T ID, F func)
        : sz(V.size()), ID(ID), f(func) {
        init(sz);
        for (int i = 0; i < sz; ++i)
            cbt[i + N] = V[i];
        for (int i = N - 1; i >= 1; --i)
            cbt[i] = f(cbt[i << 1 | 0], cbt[i << 1 | 1]);
    }
    void init(int n) {
        N = 1;
        while (N < n) N <<= 1;
        cbt.assign(N << 1, ID);
    }
    void update(int idx, T val) {
        idx += N;
        cbt[idx] = val;
        while (idx >>= 1) cbt[idx] = f(cbt[idx << 1 | 0], cbt[idx << 1 | 1]);
    }
    T query(int l, int r) {
        T ret_l = ID, ret_r = ID;
        l += N, r += N;
        while (l < r) {
            if (l & 1) ret_l = f(ret_l, cbt[l++]);
            if (r & 1) ret_r = f(cbt[--r], ret_r);
            l >>= 1, r >>= 1;
        }
        return f(ret_l, ret_r);
    }
    T query_rec(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = sz;
        if (r <= a || l >= b) return ID;
        if (l >= a && r <= b) return cbt[k + 1];
        T f_l = query_rec(a, b, 2 * k + 1, l, (l + r) / 2);
        T f_r = query_rec(a, b, 2 * k + 2, (l + r) / 2, r);
        return f(f_l, f_r);
    }
    T const& operator[](int idx) const { return cbt[idx + N]; }
    void print() {
        cerr << "*** DEBUG PRINT ***" << endl;
        cerr << " N : " << N << endl;
        cerr << "sz : " << sz << endl;
        int idx = 1;
        while (idx < 2 * N) {
            for (int i = idx; i < 2 * idx; ++i) cerr << cbt[i] << " \n"[i == 2 * idx - 1];
            idx <<= 1;
        }
    }
};
template <typename T, typename F>
auto make_segment_tree(int N, T ID, F func) {
    return SegmentTree<T, F>(N, ID, func);
}
template <typename T, typename F>
auto make_segment_tree(vector<T> V, T ID, F func) {
    return SegmentTree<T, F>(V, ID, func);
}
#pragma endregion

const int MX = 300300;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (auto& e : A) cin >> e;

    auto dp = make_segment_tree(vector<int>(MX, 0), 0, [](int a, int b) { return max(a, b); });

    for (auto& e : A) {
        int l  = max(0, e - K);
        int r  = min(MX - 1, e + K);
        int nw = dp.query(l, r + 1) + 1;
        if (dp[e] < nw) dp.update(e, nw);
    }

    cout << dp.query_rec(0, MX) << endl;
}


Measured memory_bytes: 10896
#include <iostream>
#include <math.h>

using namespace std;

int checkPrime(int n) {
	int dev = 2;
	while ((dev < sqrt(n) + 1) && (dev < n)) {
		if (n % dev == 0) {
			return 0;
		}
		dev++;
	}

	return 1;
}

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

	int num = 0;
	for (int i = 0; i < n; i++) {
		int v;
		cin >> v;

		num += checkPrime(v);
	}

	cout << num << endl;

	return 0;
}


Measured memory_bytes: 3108